Integration recipes
Persistent memory without rebuilding your AI pipeline.
SDK/API to ship production memory: save what matters, recall the right context, inject into your prompt. MCP to build in Cursor or Claude while prototyping — not your production backend.
This page is the recipe index. Each path uses the TypeScript SDK helpers (prepareContext, injectContext, saveFromTurn) or the equivalent REST calls below.
The four-step flow (every stack)
| Step | What you do | MemoryNode API |
|---|---|---|
| 1. Save | Persist facts from the user or your app | POST /v1/memories · memory.remember() |
| 2. Recall | Fetch what matters for this turn | POST /v1/search · memory.recall() — or skip if you only need a prompt pack |
| 3. Build context | Get prompt-ready text + citations | POST /v1/context · memory.contextFor() |
| 4. Inject | Merge context_text into your LLM system or user message | Your OpenAI / Anthropic / Vercel AI / LangChain code — unchanged |
| After reply | Optionally save the turn | POST /v1/memories again |
Owner id: pass the same user_id / owner_id as your SaaS logged-in user on every call. See Two-call integration.
Prove the flow in the console Playground first: save → Build context → copy context_text.
Recipe index
| Stack | When to use | Runnable example |
|---|---|---|
| REST (Node) | Any backend, no SDK | examples/integrations/rest-node |
| REST (Python) | Python services | examples/integrations/rest-python |
| TypeScript SDK | Node / TS backends | examples/sdk-quickstart |
| OpenAI Chat Completions | Already on OpenAI HTTP or SDK | examples/integrations/openai |
| MCP (Cursor / Claude Desktop) | Editor or agent IDE | MCP_SERVER.md · examples/cursor-mcp-config.json |
| Anthropic Messages API | Claude in your app | examples/integrations/anthropic |
| Vercel AI SDK | Next.js streamText / generateText | examples/integrations/vercel-ai |
| LangChain | Chains / retrievers | examples/integrations/langchain |
Canonical activation path remains START_HERE → Two-call integration.
REST (Node fetch)
Save → context → inject → LLM reply (requires OPENAI_API_KEY in the demo script — Playground does not run this step).
export MEMORYNODE_API_KEY="mn_live_..."
export MEMORYNODE_USER_ID="user_42"
node examples/integrations/rest-node/demo.mjs
Core calls:
// 1. Save
await fetch(`${BASE}/v1/memories`, {
method: "POST",
headers: authHeaders,
body: JSON.stringify({
user_id: ownerId,
text: "User prefers weekly digests and dark mode.",
}),
});
// 2. Build context (prompt-ready)
const ctxRes = await fetch(`${BASE}/v1/context`, {
method: "POST",
headers: authHeaders,
body: JSON.stringify({
user_id: ownerId,
query: "How should the dashboard feel for this user?",
top_k: 8,
}),
});
const { context_text: contextText } = await ctxRes.json();
// 3. Inject into your LLM (example: OpenAI-shaped messages)
const messages = [
{
role: "system",
content:
"You are a SaaS copilot.\n\nRecalled user context:\n" +
(contextText || "(none yet)"),
},
{ role: "user", content: userQuestion },
];
// 4. Your existing model call — unchanged stack
// await openai.chat.completions.create({ model: "gpt-4o-mini", messages });
Full script: examples/integrations/rest-node/demo.mjs.
REST (Python httpx)
Same four steps with httpx:
pip install httpx
export MEMORYNODE_API_KEY="mn_live_..."
export MEMORYNODE_USER_ID="user_42"
python examples/integrations/rest-python/demo.py
See examples/integrations/rest-python/demo.py.
TypeScript SDK (with helpers)
import { MemoryNode, injectContext } from "@memorynodeai/sdk";
const memory = new MemoryNode(process.env.MEMORYNODE_API_KEY!);
const ownerId = "user_42";
await memory.remember("User prefers weekly digests and dark mode.", { ownerId });
const userQuestion = "How should the dashboard feel for this user?";
const { contextText, systemBlock } = await memory.prepareContext(userQuestion, {
ownerId,
topK: 8,
});
const messages = injectContext(
[{ role: "user", content: userQuestion }],
contextText,
);
// Your existing OpenAI / Anthropic / Vercel AI call with `messages`
await memory.saveFromTurn({
user: userQuestion,
assistant: "Use dark mode and weekly digests.",
ownerId,
saveAssistant: true,
});
Lower-level API (no helpers): memory.contextFor() returns the raw ContextResponse.
Runnable: examples/sdk-quickstart. UI starter: starters/saas-copilot-nextjs.
OpenAI Chat Completions
Use MemoryNode helpers; keep OpenAI for generation.
export MEMORYNODE_API_KEY="mn_live_..."
export OPENAI_API_KEY="sk-..."
node examples/integrations/openai/demo.mjs
Pattern:
memory.remember(...)memory.prepareContext(question, { ownerId })injectContext(messages, contextText)→ OpenAImessagesmemory.saveFromTurn({ user, assistant, saveAssistant: true })
Details: examples/integrations/openai/README.md.
MCP for builders
Production SaaS: integrate with REST or @memorynodeai/sdk first. MCP is for Cursor, Claude Desktop, and other agent IDEs — safe, policy-gated tools on the same backend.
| Use case | Path |
|---|---|
| In-product copilot | REST / SDK — Two-call integration |
| Cursor / Claude Desktop | Hosted MCP or stdio — MCP_SERVER.md |
Agent flow:
- Configure MCP (examples/cursor-mcp-config.json).
- Before answering, call the
contexttool with the user’s question. - Paste the returned bundle into the agent prompt — your agent framework stays the same.
- Call
memoryonly for durable, user-confirmed facts.
Do not replace the two-call REST path in product docs with MCP-only integration.
Anthropic Messages API
export MEMORYNODE_API_KEY="mn_live_..."
export ANTHROPIC_API_KEY="..."
node examples/integrations/anthropic/demo.mjs
Uses prepareContext → systemBlock on the Anthropic system field → saveFromTurn.
Details: examples/integrations/anthropic/README.md.
Vercel AI SDK
Copy route.example.ts into your Next.js app, or run the memory-layer demo:
node examples/integrations/vercel-ai/demo.mjs
streamText works the same — build system from prepareContext before you stream.
Details: examples/integrations/vercel-ai/README.md.
LangChain
node examples/integrations/langchain/demo.mjs
Uses memory-node-retriever.mjs — wire getRelevantDocuments into your prompt template; keep your chain and LLM.
Details: examples/integrations/langchain/README.md.
What runs automatically
Dedupe, lifecycle ranking, and retrieval learning run on the Worker — no extra integrator services. After first recall, see Integration for links and archive/forget.
Next reads
- START_HERE — Playground proof
- TWO_CALL_INTEGRATION — auth,
owner_id, errors - INTEGRATION — context pack, lifecycle
- API reference · SDK · MCP