Skip to main content
Glama
Context-MCP

Context-MCP

by yesheng-oss

Persistent memory and codebase knowledge graph for AI coding assistants — delivered as a single MCP server.

One shared context store across Claude Code, VS Code Copilot, Google Antigravity (2.0 / IDE / CLI), Codex CLI, Hermes Agent, Claude.ai, and ChatGPT. Save context from one AI, pick it up in another.


The Problem

Every conversation with an AI assistant starts from zero. The AI re-reads files it already read yesterday, re-discovers architecture it already understood, re-derives decisions that were already made. You repeat context. You paste the same background.

This gets worse as projects grow — reading 20 files to answer "what calls this function?" burns thousands of tokens every time.


Related MCP server: hive-memory

What It Solves

  • Persistent memory — decisions, bugs, notes, and config saved across sessions, loaded automatically at conversation start

  • Shared store — ~/.context-mcp/projects/<name>/ per-project on your machine; all AI tools read and write it

  • ContextGraph — build a knowledge graph of your codebase once, answer structural questions in ~500 tokens instead of ~50,000

The repository includes a reproducible offline benchmark for measuring context compression and retrieval quality; reported values are generated locally from the benchmark fixture.

Context Subgraph Pipeline

Code files ──Tree-sitter AST──> entities + relations ──> ContextGraph cache
                                                          │
AI task ──lexical seeds──> relation-aware BFS ──> rank + recency ──> token budget
                                                          │
                                                          └──> compact MCP context

codegraph_context keeps callers, dependencies, imports, inheritance and implementation paths together while enforcing the requested token budget. It returns tokens_used, candidate_count, dropped_count, drop_reasons, and path metadata so an agent can explain why context was selected or omitted.

Run the reproducible offline benchmark with:

python scripts/benchmark_context.py --budget 160

The benchmark reports Top-K recall, path accuracy, latency, budget compliance, and context compression using a fixed graph fixture. It does not call an external model or online API.


Installation

npm install -g context-mcp-server

Requires Node.js ≥ 18. Installs context-mcp, context-mcp-http, and the ctx CLI.

ContextGraph requires uv (Python runner). Memory tools work without it.

# macOS / Linux
curl -Ls https://astral.sh/uv/install.sh | sh

# Windows
winget install astral-sh.uv

Quick Start

Run from your project root:

ctx install --initial

This installs Node.js + Python (ContextGraph) dependencies. Run once after installing the npm package.

Then write MCP config + AI instruction files:

ctx install --all

To install for a specific platform only:

ctx install --claude      # Claude Code
ctx install --vscode      # VS Code Copilot
ctx install --antigravity # Google Antigravity (2.0 / IDE / CLI)
ctx install --codex       # Codex CLI
ctx install --hermes      # Hermes Agent

For Codex project installs, ctx install --codex writes:

  • .codex/config.toml with [mcp_servers.context-mcp] MCP configuration.

  • AGENTS.md with Context-MCP usage rules for Codex.

  • .codex/hooks/ pre/post shell hook scripts for project-local Codex sessions.

For web clients (Claude.ai, ChatGPT), start the HTTP server:

ctx online               # start in background, prints OAuth credentials + URL
ctx online --restart     # force restart
ctx online --port 3200   # different port

Claude Code plugin

This repo is also a self-hosted Claude Code plugin marketplace — an alternative to ctx install --claude that doesn't require cloning or npm-installing anything yourself:

claude plugin marketplace add yesheng-oss/789
claude plugin install context-mcp@context-mcp-marketplace

or from inside a session: /plugin marketplace add yesheng-oss/789 then /plugin install context-mcp@context-mcp-marketplace. This installs the context-mcp skill, the Bash pre/post-tool-use hooks, and registers the MCP server (still launched via npx context-mcp-server@latest) — everything ctx install --claude writes into ~/.claude/, bundled as one installable unit. ctx install --initial is still required once to install the ContextGraph Python environment.


CLI Reference

Both ctx and context are aliases for the same CLI.

ctx                            # interactive mode (UI)

# Context
ctx list [project]             # list entries by tree: graph / context / summary / plans
ctx projects                   # all projects with graph status + recent entries
ctx search "query"             # keyword → semantic fallback search
ctx add                        # add entry interactively
ctx summary [project]          # summarize recent entries

# Delete
ctx delete <id-prefix>         # delete one entry
ctx delete project <name>      # delete all entries for a project

# Server
ctx online                     # start HTTP server (idempotent)
ctx online --restart           # force stop + restart
ctx settings                   # view and edit config interactively

# Install
ctx install --initial          # install / update Node.js + Python deps
ctx install --all              # write config + rules for all platforms

Security

File and git tools are sandboxed to your project root. Pass rootPath when calling context.resume:

{ "action": "resume", "project": "my-app", "rootPath": "/home/user/my-app" }

Any file or git operation outside that directory is rejected. Applies to all HTTP-connected clients.


Features

Memory

  • context.resume — loads recent entries, active plans, and graph status; registers rootPath for sandboxing

  • context.save — store context as note (or compaction for session summaries); categorize with free-form tags

  • context.get / context.update / context.delete — full CRUD, single or batch

  • search — keyword-first, semantic fallback

  • plan — auto-triggered when AI makes any plan; saves a markdown summary to a planDir you specify

  • Auto-deduplication on save; auto-compact at 20 entries → stored in summary.json

ContextGraph

Also called CodeGraph. MCP tools use the codegraph_* prefix — both names mean the same thing.

Step 1 — Build (once per project, runs locally, no API cost):

codegraph_build(path)

Parses codebase via tree-sitter AST (16 languages, regex fallback). Extracts functions, classes, imports, call edges, and inheritance. Every node carries a full enriched schema: signature, params, return_type, docstring, side_effect, exported, complexity, last_modified. PageRank scores all nodes by connectivity. Metadata saved to <project>/codegraph-cache/.

Step 2 — Query (instant, forever):

codegraph_arch(path, limit?)                     → module map: every file, its exports, its imports
codegraph_query(path, question?, node?)          → structural question OR single-node lookup (or both)
codegraph_nodes(path, type, token_budget?)       → all nodes of a type, sorted by PageRank
codegraph_filter(path, node_type?, exported?,    → predicate filter: side_effect, return_type,
  side_effect?, return_type?, called_by?,          called_by, file_pattern — rank-sorted output
  calls?, file_pattern?, token_budget?)
codegraph_report(path)                           → god nodes, clusters, surprising connections
codegraph_affected(path, node, depth?)           → BFS blast radius — what breaks if you change X?

codegraph_query accepts question (natural language), node (exact/partial name), or both. codegraph_filter answers property questions ("which functions have side effects?", "all exported async handlers") without reading any files. Pass token_budget to any tool to get the highest-rank results within a token limit.

What's in each node (v1.2+):

Field

Example

signature

function fetchUser(id: string): Promise<User>

return_type

Promise<User>

side_effect

true (db write, HTTP call, fs op detected)

exported

true

docstring

first comment or JSDoc string

rank

PageRank score — higher = more connected

inherits / implements

parent class / interface names

Step 3 — Visualize (auto-generated on every build):

codegraph_html(path, formats?)            → regenerate visualizations on demand

Every codegraph_build automatically writes to <project>/codegraph-cache/:

  • graph.html — interactive vis.js force graph (dark theme, search, community toggle)

  • tree.html — D3 collapsible file hierarchy

  • callflow.html — Mermaid architecture diagrams per community

  • graph.graphml — Gephi / yEd export

  • obsidian/ — per-node .md vault with [[wikilinks]]

File & Git Tools

Available to HTTP-connected clients (Claude.ai, ChatGPT). Local AI clients use their native IDE tools.

  • read_file, write_file, patch_file, create_dir, list_dir, delete_file

  • git_status, git_diff, git_log, git_add, git_commit, git_push, git_pull, git_branch, git_stash, git_reset, git_show

Enable git tools with --access-git flag or access_git: true in config.


Server Flags

context-mcp [--data-dir <path>]

context-mcp-http [--port <number>] [--host <string>] [--access-git] [--data-dir <path>]

Default port: 3100. Default data dir: ~/.context-mcp.


Config Reference

~/.context-mcp/contextconfig.json — auto-created on first run:

Field

Default

Description

client_id

"context-mcp"

OAuth client ID

client_secret

auto-generated

OAuth signing secret

port

3100

HTTP server port

host

"localhost"

HTTP bind host

access_git

false

Enable git tools for HTTP clients

public_url

null

Public URL for ctx online output

allowed_redirect_uris

["https://claude.ai"]

OAuth redirect URI whitelist

allowed_origins

[]

Extra CORS origins

Edit with ctx settings.


Available Tools

9 tools
codegraph_affectedA

BFS traversal: given a node name, find every node that would be affected if you change it — callers, importers, inheritors, etc. Use before refactoring to understand blast radius. Returns affected nodes with file paths, relation types, and traversal depth.

Inputs: node (required), path (required), depth.

codegraph_archA

Return a module map: every file with its exported functions/classes and what it imports. Use this to understand project structure without reading any files. Call after codegraph_build. Much faster than reading each file.

Inputs: path (required), limit.

codegraph_buildA

Scan a project directory and build the knowledge graph from code files. Uses tree-sitter AST (with regex fallback) for all code files. Fast, local, no API key needed. Run once per project; rebuild whenever code changes.

Inputs: path (required), cluster.

codegraph_contextA

Build a bounded, token-budgeted context subgraph for an AI coding task. Finds query-matching seed nodes, expands callers/dependencies/imports up to max_hops, ranks candidates, and returns compact nodes, relationship paths, budget usage, candidate counts, and per-item drop reasons.

Inputs: path (required), top_k, max_hops, question, +1 more.

codegraph_filterA

Filter graph nodes by semantic properties. Results sorted by PageRank (most connected first). All filters optional — combine freely. node_type: function|class|module|file. exported/side_effect: bool. return_type: substring match. called_by/calls: node name. file_pattern: glob. token_budget: max tokens in response.

Inputs: path (required), calls, limit, exported, +6 more.

codegraph_htmlA

Generate interactive vis.js HTML graph visualization. Dark theme, search box, community toggle, click-to-inspect node panel. Outputs codegraph-cache/graph.html. Also generates graph.graphml and obsidian/ vault.

Inputs: path (required), formats.

codegraph_nodesB

List all nodes of a given type, sorted by PageRank (most connected first).

Inputs: path (required), type (required), limit, token_budget.

codegraph_queryA

Ask a structural question about the codebase OR look up a specific node by name — or both in one call. Pass question for natural-language traversal: what calls X, what does module Y depend on. Pass node for fast single-node lookup: returns type, file, depends_on, used_by. Pass both to get node detail + surrounding graph context together. Returns structured text within token_budget. Use before reading any files.

Inputs: path (required), node, question, token_budget.

codegraph_reportC

Return CODEGRAPH_REPORT.md — god nodes, clusters, surprising connections, suggested questions.

Inputs: path (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 9 tools

    Disambiguation4/5

    Each tool has a clearly different job—build, query, contextualize, report, list, visualize, impact, filter, architectural map—but some overlap exists: codegraph_query and codegraph_context both return graph context, and codegraph_nodes is essentially a restricted version of codegraph_filter. The descriptions are strong enough that an agent can usually choose correctly.

    Naming Consistency4/5

    All tools share the consistent codegraph_ prefix and snake_case, and the suffixes are short and readable. However, they mix verb-style suffixes (build, query, filter) with noun-style suffixes (context, report, nodes, html, arch), so the set is not a strict verb_noun pattern.

    Tool Count5/5

    Nine tools is well within the ideal range and appropriate for a code-graph server. Each tool corresponds to a distinct workflow: building, querying, contextualizing, reporting, listing, visualizing, impact analysis, filtering, and architectural mapping.

    Completeness5/5

    The tool surface covers the full lifecycle of a code knowledge graph: build, inspect, filter, query, analyze impact, generate reports, and export visualization. There are no obvious missing operations that would block an agent from using the graph effectively; rebuild-on-change is handled via codegraph_build.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Provides persistent memory and a codebase knowledge graph for AI coding assistants, enabling shared context across multiple tools like Claude, Cursor, and ChatGPT, with significant token reduction.
      5
      34 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI coding agents with persistent, graph-connected memory across projects, enabling cross-project context retrieval via synaptic connections and hybrid search.
      3 npm
      8
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides persistent codebase memory and semantic context for AI agents via AST-aware chunking and symbol graph indexing.
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides a local long-term memory layer for AI coding tools like Cursor and Claude Code, enabling cross-session, cross-tool sharing of project facts, user preferences, decisions, and workflows.
      25 npm
      2
      MIT