Skip to main content

MCP Server

Memtrace ships an MCP (Model Context Protocol) server that exposes memory tools over stdio. This enables integration with any MCP-compatible client — Claude Code, Claude Desktop, Cursor, Windsurf, Cline, Zed, VS Code Copilot, Gemini CLI, and more.

The MCP server is a thin adapter: it receives tool calls over stdio and forwards them to a running Memtrace instance via the Go SDK.

Prerequisites

  • A running Memtrace instance
  • A Memtrace API key (mtk_...)

Build

make build-mcp

This produces a memtrace-mcp binary. The MCP server is built with CGO_ENABLED=0 — no C dependencies, easy to cross-compile and distribute.

Configuration

VariableDefaultDescription
MEMTRACE_URLhttp://localhost:9100Memtrace instance URL
MEMTRACE_API_KEY(required)Memtrace API key

Integration

Claude Code

Add to your Claude Code MCP settings (~/.claude/settings.json or project .mcp.json):

{
"mcpServers": {
"memtrace": {
"command": "/path/to/memtrace-mcp",
"env": {
"MEMTRACE_URL": "http://localhost:9100",
"MEMTRACE_API_KEY": "mtk_..."
}
}
}
}

Claude Desktop

Add to claude_desktop_config.json:

{
"mcpServers": {
"memtrace": {
"command": "/path/to/memtrace-mcp",
"env": {
"MEMTRACE_URL": "http://localhost:9100",
"MEMTRACE_API_KEY": "mtk_..."
}
}
}
}

Cursor / Windsurf / Other MCP Clients

The pattern is the same — point the MCP client at the memtrace-mcp binary with the required env vars. Consult your client's documentation for the exact config file location.

Tools

The MCP server exposes 7 tools, consolidated for LLM ergonomics (fewer tools = better tool selection by the model).

memtrace_remember

Store a memory. Use this to record actions, observations, events, or any information the agent should remember later.

ParameterTypeRequiredDefaultDescription
agent_idstringyesAgent ID
contentstringyesMemory content text
memory_typestringnoepisodicepisodic, decision, entity, session
event_typestringnogeneralEvent type (e.g. page_crawled, error, api_call)
session_idstringnoSession ID to scope this memory to
tagsstring[]noTags for categorization
importancefloatno0Importance score 0.0 to 1.0
metadataobjectnoArbitrary key-value metadata

memtrace_recall

Retrieve recent memories for an agent. Returns memories in reverse chronological order.

ParameterTypeRequiredDefaultDescription
agent_idstringyesAgent ID
sincestringno24hTime window (e.g. 2h, 24h, 7d)
session_idstringnoFilter by session ID
memory_typestringnoFilter by memory type
limitintno50Max results

Search memories with structured filters: by content text, memory types, tags, importance, and time range.

ParameterTypeRequiredDefaultDescription
agent_idstringnoFilter by agent ID
content_containsstringnoSearch text within memory content
memory_typesstring[]noFilter by memory types
tagsstring[]noFilter by tags
sincestringnoTime window (e.g. 2h, 24h)
min_importancefloatnoMinimum importance score 0.0 to 1.0
limitintno50Max results

memtrace_decide

Log a decision with reasoning. Creates an auditable record of what was decided and why.

ParameterTypeRequiredDefaultDescription
agent_idstringyesAgent ID
decisionstringyesThe decision that was made
reasoningstringyesWhy this decision was made

memtrace_session_create

Start a new session — a bounded context for a unit of work. Memories can be scoped to sessions.

ParameterTypeRequiredDefaultDescription
agent_idstringyesAgent ID that owns this session
metadataobjectnoSession metadata (e.g. goal, context)

memtrace_session_context

Get LLM-ready session context as formatted markdown. Returns all memories for a session grouped by type, ready to inject into a prompt.

ParameterTypeRequiredDefaultDescription
session_idstringyesSession ID
sincestringnoallTime window (e.g. 4h)
include_typesstring[]noallMemory types to include
max_tokensintnoApproximate max token budget for context

memtrace_agent_register

Register a new agent. Required before storing memories for that agent.

ParameterTypeRequiredDefaultDescription
namestringyesAgent name (used as the agent ID)
descriptionstringnoWhat this agent does

Example Workflow

Once configured, an LLM using Memtrace tools might:

  1. Register itself: memtrace_agent_register(name: "code-reviewer")
  2. Create a session: memtrace_session_create(agent_id: "code-reviewer", metadata: {goal: "review PR #42"})
  3. Remember as it works: memtrace_remember(agent_id: "code-reviewer", session_id: "sess_...", content: "Found SQL injection in auth.go:45")
  4. Decide on approach: memtrace_decide(agent_id: "code-reviewer", decision: "Flag as critical", reasoning: "SQL injection is OWASP top 10")
  5. Recall on next session: memtrace_recall(agent_id: "code-reviewer", since: "7d") — remembers what it found before
  6. Get context: memtrace_session_context(session_id: "sess_...") — inject full session history into prompt

Usage in Claude Code

Once configured, Claude Code will have access to all 7 Memtrace tools. You can use them naturally in conversation:

User: Register yourself as "code-reviewer" and create a session for reviewing PR #42

Claude: I'll register as a code reviewer and create a session.
[calls memtrace_agent_register and memtrace_session_create]

User: Review this file and remember any security issues you find

Claude: I'll analyze the code for security issues.
[reviews code, calls memtrace_remember to store findings]
Found SQL injection vulnerability in auth.go:45. I've stored this finding.

User: What security issues did you find in the last week?

Claude: Let me check my memories.
[calls memtrace_recall with since: "7d"]
Here are the security issues I found...

Development

Build from source:

cd arc-memory
make build-mcp

Test locally:

export MEMTRACE_URL="http://localhost:9100"
export MEMTRACE_API_KEY="mtk_..."
./memtrace-mcp

The MCP server will start and wait for stdio input following the Model Context Protocol specification.