Skip to main content
Docs
Open console

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)

StepWhat you doMemoryNode API
1. SavePersist facts from the user or your appPOST /v1/memories · memory.remember()
2. RecallFetch what matters for this turnPOST /v1/search · memory.recall() — or skip if you only need a prompt pack
3. Build contextGet prompt-ready text + citationsPOST /v1/context · memory.contextFor()
4. InjectMerge context_text into your LLM system or user messageYour OpenAI / Anthropic / Vercel AI / LangChain code — unchanged
After replyOptionally save the turnPOST /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

Canonical activation path remains START_HERETwo-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:

  1. memory.remember(...)
  2. memory.prepareContext(question, { ownerId })
  3. injectContext(messages, contextText) → OpenAI messages
  4. memory.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 casePath
In-product copilotREST / SDK — Two-call integration
Cursor / Claude DesktopHosted MCP or stdio — MCP_SERVER.md

Agent flow:

  1. Configure MCP (examples/cursor-mcp-config.json).
  2. Before answering, call the context tool with the user’s question.
  3. Paste the returned bundle into the agent prompt — your agent framework stays the same.
  4. Call memory only 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 prepareContextsystemBlock 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

Type to search all pages. navigate · Enter open · Esc close