← AgenTrace

Documentation

AgenTrace is an MCP memory server for coding agents. It gives your agent persistent memory across sessions — decisions, risks, patterns, and discoveries that survive the context window.

Installation

Add AgenTrace to your agent's MCP config. Works with Claude Code, Cursor, Windsurf, Codex, Cline, and any MCP-compatible agent.

Install the package

npx @theagentrace/mcp

Add to your MCP config (claude_desktop_config.json or .cursor/mcp.json)

{
  "mcpServers": {
    "AgenTrace": {
      "command": "npx",
      "args": ["-y", "@theagentrace/mcp"],
      "env": {
        "AGENTRACE_API_KEY": "your_api_key_here"
      }
    }
  }
}

Get your API key from the dashboard after signing in.

How agents should use it

Add these instructions to your CLAUDE.md, system prompt, or agent rules.

Recommended agent instructions

# Memory — AgenTrace

At the start of every thread:
1. Call session_context() to load active project history
2. Call query_memory({ query: "<task topic>" }) before reading any file

During the thread — save immediately when you discover:
- An architectural decision and why it was made
- A risk, trap, or "do not touch" warning
- A bug root cause or fix
- A pattern or convention that isn't obvious from the code

Use quick_note() for fast captures. Use save_memory_node() for
structured findings with tags and status.

Claude Code — deferred tools

Claude Code registers MCP tools as deferred — the tool names appear in the available-tools list but their schemas are not loaded by default. Calling an AgenTrace tool without loading the schema first will fail with an InputValidationError.

Fix: add a UserPromptSubmit hook in your Claude Code settings that instructs the agent to fetch tool schemas before doing anything else. Once added, it fires automatically on every prompt — you never have to think about it again.

Add to your CLAUDE.md (instructs the agent on every prompt)

## AgenTrace — Claude Code setup

AgenTrace tools are deferred in Claude Code — schemas not loaded by default.
Before reading any file or calling any AgenTrace tool, run:

  ToolSearch("select:mcp__agentrace__session_context,mcp__agentrace__query_memory,
    mcp__agentrace__save_memory_node,mcp__agentrace__append_event,
    mcp__agentrace__link_memory_nodes,mcp__agentrace__get_node")

Then immediately call:
  mcp__agentrace__session_context()
  mcp__agentrace__query_memory({ query: "<task topic>" })

Optional: UserPromptSubmit hook in .claude/settings.json (auto-injects the reminder)

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo 'MANDATORY: AgenTrace tools are deferred. Call ToolSearch first, then session_context, then query_memory.'"
          }
        ]
      }
    ]
  }
}

Tool reference

session_context()

Call this at the start of every thread. Returns the top active nodes and recent events for the current project. Lets the agent load project history before touching any file.

session_context()
query_memory({ query, limit? })

Semantic search across saved nodes by topic. Returns ranked results with an action hint — skip_read means the node is high-confidence and you can act without re-reading the file.

query_memory({
  query: "auth middleware decisions",
  limit: 5
})
save_memory_node({ id, type, label, summary, ... })

Save a finding, decision, risk, or pattern. Use semantic IDs like decision:use-postgres or risk:v1-deprecated. Git context (branch, commit, changed files) is attached automatically.

save_memory_node({
  id: "decision:use-postgres",
  type: "decision",
  label: "Chose PostgreSQL over MongoDB",
  summary: "ACID guarantees and relational joins. Do not revisit.",
  status: "active",
  confidence: 0.95,
  tags: ["database", "architecture"]
})
quick_note({ summary, type?, tags?, cwd? })

Zero-friction capture. Use this mid-session when you find something worth saving but don't want to construct a full node. ID is auto-generated.

quick_note({
  summary: "v1/auth.ts is dead — do not touch. Still receives 5% of prod traffic.",
  type: "risk",
  tags: ["v1", "deprecated"]
})
link_memory_nodes({ from, to, label })

Link two nodes with a labeled edge to show causality or relationship. Edges are used in scoring — well-connected nodes surface higher in recall.

link_memory_nodes({
  from: "bug:auth-timeout",
  to: "decision:increase-jwt-expiry",
  label: "caused"
})
supersede_node({ old_id, new_node })

Replace a stale node while preserving history. The old node is marked superseded, the new one takes its place in retrieval. Use this when a decision changes, not save_memory_node.

supersede_node({
  old_id: "decision:use-rest-api",
  new_node: {
    id: "decision:migrate-to-trpc",
    type: "decision",
    summary: "Moved from REST to tRPC. REST approach had too much boilerplate."
  }
})
append_event({ type, summary, tags?, nodes? })

Log a session milestone or discovery. Events appear in session_context and create a timeline of work across sessions.

append_event({
  type: "finding",
  summary: "Fixed rate limit bug on search — switched to X-Forwarded-For.",
  tags: ["bugfix", "search"],
  nodes: ["finding:rate-limit-fix"]
})
get_node({ id })

Fetch a specific node by ID. Use when you already know the node ID from a previous session_context or query_memory result.

get_node({ id: "decision:use-postgres" })

Node types

Choose the type that best matches what you're saving. Type affects scoring — risks surface when the agent is about to do something dangerous, decisions surface when architecture is discussed.

decision

An architectural or product choice and why it was made. The most valuable node type — prevents re-litigating settled questions.

risk

Something that can break, a trap to avoid, or a "do not touch" warning. Surfaces in recall when the agent is about to do something dangerous.

finding

A discovery, bug fix, or insight from a session. Good for "we tried X and it failed" or "this bug was caused by Y".

behavior

How the system currently behaves — what it does, not how it's built. Use for documenting observed runtime behavior.

implementation

How something is structured in code. Reference to patterns, file locations, or architectural patterns.

concept

An abstract pattern or principle that applies across the codebase.

change

A migration, refactor, or significant code change and its rationale.

issue

A bug or ticket with context on root cause, fix, and linked decisions.

test

A test case, coverage gap, or testing pattern worth remembering.

preference

How the team wants agents to behave. Explicit instructions that should persist.

repo_context

Deployment, environments, build commands, branch rules, CI/CD specifics.

file

A specific file with meaningful semantic context attached — not just its existence, but why it matters.

function

A specific function with context on its contract, gotchas, or invariants.

What not to store

These create noise in retrieval and should be avoided:

  • File trees or directory listings — agents can run find/ls, these go stale immediately
  • Code snippets that belong in the file itself — if it's readable from the source, don't mirror it
  • Generic summaries of files — "this file handles auth" adds nothing a future agent can't derive
  • Things already in git history or comments
  • Temporary state or in-progress work — save the outcome, not the journey
Ask AI about AgenTrace