Integration
Memory for Vercel AI SDK agents
Harny gives each person who uses your app a private memory the app's AI can read. This page shows how to add Harny memory to an AI SDK agent through the Harny MCP server.
What the framework does not keep
- Which value is current. Harny stores dated memories, so a changed value with a newer timestamp becomes the current value and the earlier one stays answerable by date.
- When a fact happened. Harny records a timestamp for each memory, so recall can filter by when something happened.
- One person's memory. Harny keeps each person's memory separate from others. Calls made with a person's key are scoped to that person.
The pattern: the Harny MCP server
The Harny MCP server is at https://api.harny.ai/v1/mcp/mcp (Streamable HTTP). The header key belongs to one person (fsk_), so the tools the agent calls read and write only that person's memory.
import { generateText } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";
export async function ask(question: string, userKey: string) {
const harny = await createMCPClient({
transport: {
type: "http",
url: "https://api.harny.ai/v1/mcp/mcp",
// the signed-in person's key, set by your application
headers: { Authorization: `Bearer ${userKey}` },
},
});
try {
const { text } = await generateText({
model, // the model you already use with the AI SDK
tools: await harny.tools(),
prompt: question,
});
return text;
} finally {
await harny.close();
}
}What the tools return
The server lists the tools your key may call. A person's key (starts with fsk_) reaches the memory tools for that person only.
assemble_contextrecalls ranked context for the person whose key you hold.ingest_textwrites a note or fact into that person's memory.describeis available with any key.
When to use which
- Use the AI SDK's own state for the work of the current run, such as the messages and tool results in the session.
- Add Harny when the agent needs memory that lasts across sessions, keeps dates, and shows which fact is current for a person.
Frequently asked questions
Is a package needed?
The page uses the AI SDK's MCP client to reach the Harny MCP server at https://api.harny.ai/v1/mcp/mcp.
Where does the user id come from?
The user id is not chosen by the model. The key in the MCP header belongs to one person (fsk_), so Harny scopes every call to that person's memory.
Keep reading
Go on. Get Harny.
The first 500 monthly-active end users are free for good. Create an app key and make your first call in minutes.