codegraph
This MCP server exposes a code knowledge graph: index a repository once, then query symbols, relationships, impact, diffs, architecture and dead code instead of grepping.
Index the repo (
index_repository_tool): build or refresh the graph incrementally, or force a full rebuild;graph_statusreports row counts and DB location.Find symbols (
search_nodes,get_node): look up functions, classes and modules by name, signature or docstring keyword, or fetch one exact node by qname, unique bare name, orpath:line.Trace relationships (
query_graph): callers, callees, imports, imported-by, tests, subclasses, defines, defined-in.Assess change impact (
get_impact_radius): direct and transitive callers, importers and covering tests for a symbol, to a chosen depth.Review diffs (
detect_changes_tool,get_review_context): risk-rank symbols touched by the working tree or a base..HEAD diff, then pull source snippets with callers and tests.Understand architecture (
get_architecture_overview): languages, top-level packages, hub functions, entry points and external dependencies.Clean up (
find_dead_code): surface callables with no callers, tests or subclasses as candidates to inspect.
This is a 10-tool subset of the full 62-tool server, which additionally covers Cypher queries, semantic search, flows, communities, routes and channels, git history, and export/wiki generation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codegraph who calls Invoice.total and which tests cover it?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
codegraph-mcp
A code knowledge graph you can query from an agent. Index a repository once, then ask structural questions — who calls this, what breaks if I change it, which tests cover it, which service calls this endpoint, what does the architecture look like — through an MCP server or a CLI, instead of grepping and reading whole files.
It parses 27 programming languages plus Vue / Svelte components, Jupyter notebooks,
Dockerfiles, docker-compose, Kubernetes, Kustomize, Terraform and Makefiles. Everything
lives in one SQLite file under .codegraph/ in the repo you index: no daemon, no
service, no network access, and no embeddings unless you opt in.
Version 0.2 merges the feature sets of code-review-graph and codebase-memory-mcp into this codebase; see THIRD_PARTY.md.
Why
Agents burn tokens re-discovering the same facts about a codebase: opening files to find
callers, tracing imports by hand, guessing which tests matter. A graph answers those in a
few hundred tokens with exact path:line locations, turns a diff into a ranked list of
"these symbols have many callers and no tests — look here first", and connects things
grep cannot: an HTTP client call to the route that serves it, a Kafka producer to its
consumers, a Kubernetes Service to the Deployment it selects.
Related MCP server: code-graph-mcp
Install
uv pip install git+https://github.com/mooyee0929/codegraph-mcp
# optional: vector search with sentence-transformers
uv pip install "codegraph-mcp[embeddings] @ git+https://github.com/mooyee0929/codegraph-mcp"
# or, from a clone
uv pip install -e ".[dev]"Requires Python 3.11+. Grammars come from tree-sitter-language-pack; nothing is
downloaded at run time.
Quick start
codegraph index # build or refresh .codegraph/graph.db (incremental)
codegraph architecture # languages, layers, entry points, routes, communities
codegraph review --base main # risk-ranked symbols touched by your branch
codegraph install # register the MCP server with Claude CodeEvery command accepts --root <dir> (default: cwd) and --json. Targets can be a full
qname (pkg.billing.Invoice.total), a bare name when it is unique (total), a suffix
(Invoice.total), or a location (pkg/billing.py:10).
CLI
Area | Commands |
Index |
|
Look up |
|
Navigate |
|
Review |
|
Architecture |
|
Services |
|
History |
|
Docs and output |
|
Repos and setup |
|
codegraph <command> --help documents each one. A few examples:
codegraph query callers_of Invoice.total
codegraph trace charge --direction inbound --depth 3
codegraph cypher "MATCH (r:Route)-[:HANDLES]->(f) WHERE r.name STARTS WITH 'POST' RETURN r.name, f.qname"
codegraph find --kind method --min-fan-in 5 --untested
codegraph grep "TODO" --file "src/*"
codegraph semantic "retry failed payment"
codegraph routes --method GET
codegraph hotspots
codegraph visualize && open .codegraph/graph.htmlMCP server
codegraph-mcp --root /path/to/repo # stdio transport
codegraph-mcp --root . --watch --auto-index # keep the graph fresh while serving
codegraph-mcp --root . --tools get_node,trace_path,search_graph # expose only thesecodegraph install registers the server with Claude Code (through claude mcp add
when the CLI is present, otherwise by merging .mcp.json); --hooks also adds a
project-level PostToolUse hook that re-indexes after edits, --dry-run shows the plan,
and codegraph uninstall removes exactly what was added. Manual setup:
{
"mcpServers": {
"codegraph": { "command": "codegraph-mcp", "args": ["--root", ".", "--auto-index"] }
}
}Tools
62 tools. With many clients each tool schema costs context, so --tools /
CODEGRAPH_TOOLS lets you expose a subset.
Area | Tools |
Index |
|
Look up |
|
Navigate |
|
Review |
|
Architecture |
|
Services |
|
History |
|
Docs and output |
|
Repos |
|
Prompts
review_changes, pre_merge_check, debug_issue, architecture_map and
onboard_developer walk the agent through the right tools in order. A typical review:
detect_changes_tool → get_change_impact → get_review_context on the riskiest
symbols → get_impact_radius on anything with high fan-in.
How it works
source files ──parse──▶ nodes + edges ──store──▶ SQLite (+FTS5)
│ │
python: ast │ link ◀───┤ unique-name resolution,
js/ts + 25 more: tree-sitter │ test-coverage inference
infra: yaml / hcl / dockerfile parsers │
passes ◀─┘ routes, channels, clones,
history, communities, flows,
search index, related edgesNodes are modules, classes (any named type: struct, interface, trait, enum),
functions, methods, routes (route:GET /users/{id}), channels (channel:orders) and
infrastructure resources (resource:k8s/Deployment/web). Code qnames come from the
file path (pkg/billing.py → pkg.billing).
Edges are defines, imports, calls, inherits and tests from parsing, plus
derived ones: handles (route → handler), http_calls (client → route), emits /
listens_on (function → channel), similar_to (near-clones), semantically_related,
co_changes (files committed together) and depends_on (infrastructure). Heuristic
edges carry a confidence and a short detail.
Resolution. Parsers resolve what the file's own imports tell them; go.mod, Cargo.toml and package.json workspaces map package names to repo paths. Anything else is stored as a bare name and linked only when exactly one definition has that name. Ambiguous names stay unresolved rather than guessed, and the CLI marks them.
Passes run after linking, in order, whenever the index changed:
Order | Pass | Writes |
12 |
| cross-file imports and calls for the tree-sitter languages, Kubernetes selectors |
20 |
| route nodes for Flask, FastAPI, Django, Express, NestJS, Next.js, Go net/http / gin / echo / chi, Spring, JAX-RS, ASP.NET, Rails, Laravel, gRPC protos, GraphQL schemas |
22 |
| client call sites (fetch, axios, requests, httpx, Go http, RestTemplate, ...) matched to routes |
24 |
| Socket.IO / EventEmitter, Kafka, RabbitMQ, Redis, NATS, Celery, signals, Temporal |
30 |
| MinHash + LSH near-duplicate functions |
35 |
| per-file churn and co-change edges from a bounded |
40 |
| re-applies ingested runtime spans |
60 |
| deterministic Louvain communities with names, cohesion and boundaries |
65 |
| execution flows from entry points with a criticality score |
90 |
| BM25 / TF-IDF index over names, signatures, docs and paths |
95 |
|
|
Skip any with codegraph index --skip-pass NAME.
Risk in review is a small additive score: many callers, no covering tests, high
fan-out, large hunks. change-impact adds the flows and communities a diff touches.
Both are meant to order your attention, not to judge the change.
Incremental indexing hashes file contents; unchanged files are skipped, deleted files are removed, and linking and passes re-run only when something changed. The database is a cache: when its schema version changes it is rebuilt from source.
Configuration
Setting | Effect |
| extra ignore patterns, one per line, matched against names and repo-relative paths |
| comma-separated tool names the MCP server exposes |
| same as |
| where the multi-repo registry lives (default |
| sentence-transformers model for |
Team snapshot. codegraph snapshot export writes .codegraph/graph.db.gz and marks
it binary merge=ours in .gitattributes. Commit it, and teammates' --auto-index
restores it and only re-parses their local changes.
ADRs and notes. codegraph adr keeps architecture decision records as markdown in
docs/adr/ (or the directory named in .adr-dir); codegraph note stores question and
answer pairs in .codegraph/notes/ so later sessions can search them.
Limits
No type inference.
self.client.send()andobj.method()resolve only when the method name is unique across the repo and not a common library name (get,run,send,execute, ...). Until then they show as*.sendand are flagged unresolved.Dynamic dispatch, decorators that rewrite functions,
getattr, runtime-built routes and re-exports are invisible. Route and channel detection is pattern-based.JS default imports bind to the module qname, so
def.run()becomes<module>.run.Communities come from single-resolution Louvain, so one can be internally disconnected; bridge scores above 400 nodes are estimated from a sample.
The Cypher subset has no write clauses,
UNWIND,UNION,CASEor parameters.Passes re-run only when indexed files change; after editing only
.protofiles or pulling new history, runcodegraph index --force.One repository per database; qnames are rooted at the index root. The registry and
cross_repo_*tools join several.
Development
uv venv && uv pip install -e ".[dev]"
uv run pytest -q
uv run ruff check . && uv run ruff format --check . && uv run mypy codegraphFeature code plugs in without touching the core: a module in codegraph/passes/ that
defines PASS, in codegraph/tools/ that defines register(server, ctx), or in
codegraph/commands/ that defines register(add) is discovered automatically.
License
MIT. Ideas and designs ported from the two upstream projects are credited in THIRD_PARTY.md.
Available Tools
10 toolsdetect_changes_toolA
Risk-ranked symbols touched by the current diff (working tree vs HEAD, or base..HEAD when base is given).
Inputs: base. Returns: result
find_dead_codeB
Callables with no callers, tests or subclasses. Candidates, not verdicts.
Inputs: limit. Returns: result
get_architecture_overviewC
Languages, top-level packages, hub functions, entry points and external deps.
Inputs: top. Returns: result
get_impact_radiusB
Blast radius of changing a symbol: direct and transitive callers, importers, tests.
Inputs: target (required), depth. Returns: result
get_nodeA
Look up one symbol by qname, unique bare name, or path:line.
Inputs: target (required). Returns: result
get_review_contextC
Source snippets plus callers and tests for the given symbols.
Inputs: qnames (required), context_lines. Returns: result
graph_statusB
Row counts and where the database lives.
Inputs: no named parameters. Returns: result
index_repository_toolA
Index or refresh the repository graph. Incremental unless force=true.
Inputs: force. Returns: result
query_graphC
Trace one relationship. Patterns: callers_of, callees_of, imports_of, imported_by, tests_for, subclasses_of, defines, defined_in.
Inputs: target (required), pattern (required). Returns: result
search_nodesC
Find functions, classes and modules by name, signature or docstring keyword.
Inputs: query_text (required), limit. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool has a fairly distinct purpose: query_graph traces a single relationship while get_impact_radius computes transitive blast radius, and search_nodes vs get_node differ by fuzzy search vs exact lookup. The only mild overlap is get_review_context, which bundles callers and tests that also appear in get_impact_radius, but the added source snippets keep it differentiated.
Most tools follow a clean verb_noun snake_case pattern (query_graph, get_impact_radius, find_dead_code, search_nodes, get_node). Two outliers carry a redundant '_tool' suffix (detect_changes_tool, index_repository_tool) and graph_status is noun-only, which are minor deviations rather than a broken convention.
Ten tools is well-scoped for a code-graph analysis server, covering setup, exploration, and analysis without redundancy. Every tool earns its place across the indexing/query/analysis lifecycle.
The surface covers the full workflow: indexing, status, symbol search/lookup, relationship tracing, impact analysis, diff risk, review context, architecture overview, and dead-code detection. Minor gaps exist (e.g. no explicit index deletion or cross-repo management), but core lifecycles are well covered.
Maintenance
Related MCP Connectors
Shared context for your codebase: a hosted code knowledge graph over MCP. Free plan, OAuth sign-up.
Hosted code graph over MCP: exact callers, dependencies, and cross-repo blast radius for AI agents.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Related MCP Servers
- AlicenseAqualityCmaintenanceIndexes any TypeScript / React / Next.js repo into a queryable code graph and exposes 13 MCP tools — who-renders, who-calls, find-references, blast-radius, find-cycles, dead-code orphans, and local semantic search — so agents query structure instead of reading whole files. Built on ts-morph, so edges are resolved, not grepped.142MIT
- AlicenseAqualityDmaintenanceIndexes a mono-repo into a knowledge graph and provides MCP tools to query code structure—packages, components, routes, HTTP calls—without file reads or grep round-trips.722 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables people and AI agents to query local code repositories as graphs through stdio MCP tools for project listing, search, dependency tracing, impact analysis, bridge detection, node inspection, bounded code reading, and optional LSP definition/reference lookups.MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI coding agents to query a locally indexed structural code graph — source entities, callers/callees, Git relationships and recorded mistakes — so they retrieve focused, token-bounded context instead of reading entire files. It runs over local SQLite and can be served through a CLI, agent hooks, an MCP executable and an authenticated local dashboard.24 npmMIT