One Brain with the Vercel AI SDK.

Two ways to give an AI SDK app your team’s One Brain: its MCP server through the AI SDK’s own MCP client, or @useonebrain/ai-sdk.

Integrations · AI SDK

Two ways.

What you get1. MCP2. Package
Search, read, list, remember, write, forgetYes, as MCP toolsYes, as AI SDK tools
Approval before write and forgetNoYes, by default
Recall before each answer, without a tool callNoYes
Capture of each turn, so One Brain learns from itNoYes, by default
Dependencies@ai-sdk/mcp@useonebrain/ai-sdk

Both need a key in ONEBRAIN_API_KEY: a workspace agent key (ob_..., from Settings > Agents in the One Brain app, or onebrain admin keys create <agent>) or a person’s OAuth access token. ONEBRAIN_URL defaults to https://api.useonebrain.com.

In the snippets, model is any AI SDK language model: a provider’s model, or an AI Gateway id such as 'anthropic/claude-sonnet-5.5'.

1. MCP, no package.

One Brain’s MCP server is at <ONEBRAIN_URL>/mcp. The AI SDK’s MCP client turns its six tools into AI SDK tools:

npm install ai @ai-sdk/mcp
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, isStepCount } from 'ai';

const mcp = await createMCPClient({
  transport: {
    type: 'http',
    url: `${process.env.ONEBRAIN_URL ?? 'https://api.useonebrain.com'}/mcp`,
    headers: { Authorization: `Bearer ${process.env.ONEBRAIN_API_KEY}` },
  },
});
try {
  const { text } = await generateText({
    model,
    tools: await mcp.tools(),
    stopWhen: isStepCount(5),
    prompt: 'Search One Brain: when does Northwind renew?',
  });
  console.log(text);
} finally {
  await mcp.close();
}

To sign a person in with OAuth instead of a key, pass the MCP client an authProvider in place of headers; it runs the OAuth flow against One Brain.

2. The package.

npm install @useonebrain/ai-sdk ai zod

The package’s README has every option.

Recall and capture

withOneBrain wraps the model. Before each call it searches One Brain with the user’s message and gives the model the results as a block of data marked with One Brain’s notice. After the call that answers, it stores the turn as a session with the ref <sessionId>#turn-<n>.

import { generateText } from 'ai';
import { withOneBrain } from '@useonebrain/ai-sdk';

const { text } = await generateText({
  model: withOneBrain(model),
  prompt: 'When does Northwind renew, and who is their champion?',
  providerOptions: { onebrain: { sessionId: 'demo-generate' } },
});
console.log(text);

Streaming works the same. The capture is stored after the stream ends and never holds it:

import { streamText } from 'ai';
import { withOneBrain } from '@useonebrain/ai-sdk';

const result = streamText({
  model: withOneBrain(model),
  prompt: 'Which currency does Northwind want on its invoices?',
  providerOptions: { onebrain: { sessionId: 'demo-stream' } },
});
for await (const chunk of result.textStream) process.stdout.write(chunk);

On Vercel or Cloudflare, pass waitUntil (after from next/server, waitUntil from @vercel/functions, or ctx.waitUntil) so the function stays alive until the capture is stored: withOneBrain(model, { waitUntil: after }).

One conversation, one session id

Pass the same sessionId on every turn. Each turn stores only its own messages:

import { generateText } from 'ai';
import { withOneBrain } from '@useonebrain/ai-sdk';

const brainModel = withOneBrain(model);
const providerOptions = { onebrain: { sessionId: 'demo-chat' } };
const messages = [{ role: 'user', content: 'Who is the champion at Northwind?' }];

const first = await generateText({ model: brainModel, messages, providerOptions });
messages.push(...first.responseMessages, { role: 'user', content: 'And what is their title?' });
const second = await generateText({ model: brainModel, messages, providerOptions });
console.log(first.text, '\n---\n', second.text);

This stores ai-sdk:demo-chat#turn-1 and ai-sdk:demo-chat#turn-2. Recall searches the second turn with both questions, so “And what is their title?” still finds Northwind.

Tools in an agent

onebrainTools() gives the model the six tools. write and forget wait for the user’s approval. In a tool loop, the turn is captured once, by the step that answers:

import { isStepCount, ToolLoopAgent } from 'ai';
import { onebrainTools, withOneBrain } from '@useonebrain/ai-sdk';

const agent = new ToolLoopAgent({
  model: withOneBrain(model, { recall: false, sessionId: 'demo-agent' }),
  instructions:
    'You work from the team knowledge in One Brain. Search it before you answer, and remember new facts the user tells you.',
  tools: onebrainTools(),
  stopWhen: isStepCount(8),
});

const result = await agent.generate({
  prompt:
    'Look up when Northwind renews. Also remember this for the team, in the clients folder: Northwind asked for a 30-day notice before any price change.',
});
console.log(result.text);

Turning capture off

import { generateText } from 'ai';
import { withOneBrain } from '@useonebrain/ai-sdk';

const { text } = await generateText({
  model: withOneBrain(model, { capture: false }),
  prompt: 'In one line: how does Northwind pay?',
  providerOptions: { onebrain: { sessionId: 'demo-no-capture' } },
});
console.log(text);

Capture is on by default and logs one line the first time it runs. When the server refuses a capture, for example because a workspace agent has no capture folder to store into, it logs one warning with what to change and stops capturing until the process restarts. The answer is never held or failed by it.

Capturing in onEnd instead

Without the middleware, store a turn yourself:

import { generateText } from 'ai';
import { captureSession } from '@useonebrain/ai-sdk';

const userMessage = { role: 'user', content: 'Say hello to the Northwind team in five words.' };
await generateText({
  model,
  messages: [userMessage],
  onEnd: ({ responseMessages }) =>
    captureSession({ sessionId: 'demo-on-end', turn: 1, messages: [userMessage, ...responseMessages] }),
});

Skills and the MCP client

import { onebrainMcp } from '@useonebrain/ai-sdk/mcp';

const mcp = await onebrainMcp();
const tools = await mcp.tools();
console.log(Object.keys(tools));
await mcp.close();
import { loadOneBrainSkills } from '@useonebrain/ai-sdk';

const skills = await loadOneBrainSkills();
console.log(skills.map((skill) => [skill.name, skill.files.map((file) => file.path)]));

onebrainMcp is path 1 with the URL and key filled in from the environment (it needs @ai-sdk/mcp). loadOneBrainSkills returns the workspace’s skills in the shape HarnessAgent’s skills setting takes.

A whole chat.

The AI SDK template is a Next.js App Router chat on the package: recall, the six tools with Approve and Deny buttons for write and forget, and capture with the chat’s id as the session id. Deploying it asks for ONEBRAIN_API_KEY and ONEBRAIN_URL.

Deploy with Vercel

Give every person and agent the same brain.

$25 a seat at launch. 14 days free, no card.