Brain Docs

Reference

Integrations

Frameworks

Next.jsFastAPILangChainOpenAI

Protocol

Brain over MCP
Brain/Docs
✦ ASKBrain on GitHubDashboard
IntegrationsIntegrations

Integrations

Five ways to wire Brain into a stack — Next.js, FastAPI, LangChain, the OpenAI Responses API, or the first-party MCP server — and the one question that decides which.

PURPOSE

Brain has one surface — the REST API and the wire protocol — and several shapes people wrap it in. This page says which shapes exist, which of them ship as a package, and how to choose. The semantics never change: recall returns a membership verdict, corrections supersede, and the key carries the scope.

Start here

OptionTypeDefault / Env
Next.jsin-depth guide

The App Router, end to end — the runtime constraint that decides where your code can run, identity from the session, recall in a Server Component, writes in Server Actions and after(). Read it.

FastAPIin-depth guide

A Python service, end to end — choosing between the sync HTTP tier and the async wire tier, why the wrong choice blocks your event loop, and the pooled-key multi-tenancy only this tier can do. Read it.

These two are the full treatments, and they are complementary: the Next.js guide ends at the point where a serverless runtime cannot hold a connection, and the FastAPI guide picks up exactly there.

What ships, and what you write

OptionTypeDefault / Env
@brain-db/mcpfirst-party package

A published MCP server exposing 49 tools over stdio or remote Streamable HTTP. Install it; you do not write it. See Brain over MCP.

LangChainglue you write

No first-party package. Brain is the long-term half of LangChain's memory model — a store, a retriever or agent tools, never the checkpointer. Three wirings and the trade-offs.

OpenAIglue you write

No first-party package. Two function tools on the Responses API and a dispatch loop. The Assistants API it used to describe was sunset in August 2026 — the current pattern is here.

Choosing

The real question is who decides when memory is touched — the model, or your code.

MCP
SDK or framework glue
Who calls
The model decides, from the tool descriptions
You decide, at call sites you wrote
Best for
Agentic clients — Claude, Cursor, Copilot — and anything you do not control the loop of
Application code where the loop is yours
Setup
Install a package, add one client config block
Library install plus glue
Identity
Per-request key over HTTP; one key per process on stdio
Per-request key, or one pooled key with per-request act_as on the wire tier
Context cost
Tool definitions and results consume agent context
None — calls are explicit and their results are yours to trim
Failure mode
The model does not call the tool, and nobody notices
Your code did not call it, and your tests can catch that

The last row is the one worth sitting with. With MCP, a memory that never gets written looks identical to a conversation where there was nothing to write. If what you are storing matters, an explicit call site you can test is the safer shape — and nothing stops you doing both.

They are not exclusive

A common production shape is MCP for the agent's reads and explicit SDK calls for its writes: the model can ask what is known whenever it likes, and your code decides what is worth remembering. That keeps the useful autonomy and removes the failure mode above.

The tier question, once

Every guide here runs into the same fork, so it is worth stating plainly in one place. Brain has two client tiers, and which one you can use is usually decided for you by where your code runs.

HTTP tier
Wire tier
Client
BrainHttpClient — JSON to the edge
BrainClient — BRN0 over TCP
Needs
An HTTPS endpoint
A socket you can hold open
Surface
60 HTTP routes
All 72 verbs, plus transactions
Per-request identity
No — the key carries the scope
Yes — act_as on every data-plane op
Runs in
Serverless functions, edge-adjacent services, anywhere
A long-lived process you deploy
Answer spelling
Lowercase — "single" / "many" / "none"
PascalCase — "Single" / "Many" / "None"

That last row causes more confusion than it should: a verdict comparison written for one tier silently never matches on the other. It is called out again in both guides, at the point where it bites.

01
Next.js

The App Router guide — runtimes, identity, caching, streaming.

02
FastAPI

The Python guide — tiers, the event loop, pooled-key tenancy.

03
Brain over MCP

The first-party server — install, transports, the 49 tools, and the identity model.

04
LangChain

Which half of LangChain's memory model Brain belongs in, and three ways to wire it.

05
OpenAI

Function tools on the Responses API, and the identity rule that matters.

See also
Wire it in without a frameworkIdentity by keyREST API reference

Was this page helpful?

Manual rate-limit backoff

Catch a 429 / 503, honor Retry-After, and retry — taking over from the SDK's built-in auto-retry when you need to.

Next.js

Brain in a Next.js App Router app — where the client lives, why the Edge runtime cannot load it, identity from the session, recall in a Server Component, writes in Server Actions and after(), and streaming the change feed.

On this page

Start hereWhat ships, and what you writeChoosingThey are not exclusiveThe tier question, once
Suggest an editOpen in Playground