ast-mcp
AST_MCP serves structural code retrieval over MCP: it parses source with tree-sitter and returns symbols, schemas, or outlines instead of whole files.
Outline a file (
file_outline): get a file's shape—definitions, key paths or heading tree—with bodies elided;mode="names"lists names, lines and counts only. For data files it reports record count, field types,children_countanduniformitywithout returning values inside collections.Fetch a definition (
get_symbol): get one symbol by name, key path (services.web.ports) or heading slug;mode="source"returns the body,signature/docomit it. It never guesses—ambiguous names return candidates, resolvable bypathorline.Search by name (
search_symbols): find definitions, key paths and headings across the repo, filtered bykind,lang,group,path_globandlimit.Get docs only (
get_docstrings): retrieve docstrings without bodies, for a file path or a list of symbols.List dependency edges (
list_imports): imports out of a file, plus exports where the language supports them.Escape hatch (
ast_query): run a raw tree-sitter S-expression query against one file for anything the typed tools flatten away.Budget control everywhere: every tool takes
max_tokens(default 4000); over-budget responses are trimmed, flaggedtruncated: true, and suggest which argument narrows the result.
It is read-only—only .ast_mcp/index.db (and, via init, .mcp.json, .gitignore, CLAUDE.md) is ever written—and responses declare profile and group before the payload so agents know whether symbols, defs, schema or outline is available.
Structural definition extraction for CSS and SCSS stylesheets, allowing an agent to see a stylesheet's shape without reading it in full.
Structural definition extraction for Dockerfiles and docker-compose YAML via the devops/schema profiles, exposing the file's shape and key paths.
Structural definition extraction for GraphQL schema files through the defs profile.
Full symbol extraction for JavaScript files: definitions with signatures, docstrings, nesting and import edges, retrievable by name or as a file outline.
Symbol extraction for Lua, including support for multiple definitions of the same name (e.g. many listeners on one event), which are returned together rather than guessed at.
Outline-profile handling of Markdown: serves the heading/section tree, and heading slugs can be fetched as individual symbols.
Structural definition extraction for Perl files through the defs profile, exposing symbols without full bodies.
Parses Python source with tree-sitter to serve symbols — functions, classes, signatures, docstrings, nesting and imports — so an agent can outline a module or fetch a single definition instead of reading the whole file.
Structural definition extraction for Ruby files through the defs profile, exposing symbol names, lines and counts.
Structural definition extraction for Terraform files through the defs profile, exposing declared resources and blocks by name.
Schema-profile handling of TOML configuration files, exposing key paths and inferred value types.
Full symbol extraction for TypeScript (and TSX) files, exposing definitions, signatures, docstrings and imports for structural retrieval by name or outline.
Schema-profile handling of XML documents, returning structural key paths and inferred value types.
Schema-profile handling of YAML: key paths plus inferred value types, so config shapes can be queried without reading the file.
Structural definition extraction for Zsh (and Bash) shell scripts through the defs profile.
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., "@ast-mcp show me the definition of parse_config"
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.
AST_MCP
Structural code retrieval over MCP. Parses source with tree-sitter and serves
symbols instead of files, so an agent asking "what does parse_config do"
gets 40 lines rather than 2000.
Read-only. The server never writes to your source — the only file it writes is
its own index at .ast_mcp/index.db.
Install
uv tool install ast-mcpOr run it without installing anything:
uvx ast-mcp --versionRequires Python 3.11 or newer.
Related MCP server: Lore MCP Server
Wire it into Claude Code
From the repository you want indexed:
ast-mcp initThat writes an ast-mcp stanza into <repo>/.mcp.json, adds .ast_mcp/ to
.gitignore, writes a short retrieval-routing block into CLAUDE.md, and
builds the index. Claude Code reads .mcp.json at startup, so the next
session in that directory has the tools already connected — no per-session
step.
The CLAUDE.md block is what makes the agent actually reach for the tools;
registration alone tends to leave them idle. It is about thirty lines and says
one thing: name a symbol, key path or heading → these tools; describe
behaviour you cannot name → your semantic retriever; about to edit a file, or
need it byte-for-byte → Read. --no-claude-md skips it.
init merges. Every other server in .mcp.json is left exactly as it was,
and a file it cannot parse is reported rather than overwritten. Re-running it
is a no-op. Pass --dry-run to see the change first.
The stanza it writes carries no absolute paths, so it is safe to commit:
{
"mcpServers": {
"ast-mcp": { "command": "ast-mcp", "args": ["serve"] }
}
}If ast-mcp is not permanently on PATH it records uvx ast-mcp serve
instead. Override either with --command "uv run ast-mcp serve".
CLI
command | what it does |
| register in |
| build or refresh the index; |
| file/symbol counts, index size, freshness, registration |
| tokens served vs. what reading those files whole would have cost |
| the language registry — 27 rows, their extensions and profiles |
| the MCP server over stdio; what Claude Code launches |
Every command takes --root PATH. Root resolution is --root, else
AST_MCP_ROOT, else the working directory. Bare ast-mcp means ast-mcp serve.
Only init writes anything outside .ast_mcp/, and only .mcp.json,
.gitignore and CLAUDE.md. The server itself never writes to your source.
Not every language gets the same treatment
A .py file has functions with signatures and docstrings. A
docker-compose.yml has none of that — it has a shape. A README.md has a
heading tree. Forcing all three through one symbol model produces garbage for
two of them, so there are four extraction profiles:
profile | payload key | what you get | languages |
|
| signature, docstring, nesting, imports | python, javascript, typescript, tsx, go, lua, csharp |
|
| same shape, weaker guarantees — docstrings often | ruby, perl, r, bash, zsh, css, scss, sql, graphql, proto, terraform, dockerfile |
|
| key paths + inferred value types, not funcdefs | json, json5, yaml, toml, xml, csv |
|
| heading / section tree | markdown, html |
27 languages across six groups: core, web, scripting, data, devops,
docs. Every response declares its profile and group before the
payload — read that field, don't assume symbols exists.
Kinds never lie about fidelity. A schema node's kind is a value type
(object, array, string); an outline node's kind is a document structure
(heading, code_block). Nothing outside the symbols/defs profiles ever
claims to be a function or a class.
Tools
tool | use it for |
| the |
| one definition. |
| find things by name across the repo |
| docs without bodies |
| dependency edges out of a file, plus exports where the language has them |
| raw tree-sitter S-expression — the escape hatch |
Every tool takes max_tokens (default 4000). An over-budget response is
trimmed, flagged truncated: true, and tells you which argument narrows it.
Nothing is dropped silently.
get_symbol never guesses. A name matching several symbols returns
ambiguous: true with candidates; pass path or a qualified name to resolve.
Alongside a semantic retriever (optional)
AST_MCP stands alone. Nothing it tells the agent assumes another retrieval tool is registered, and a repo running only this server is a supported setup.
If you also run CCE, --with-cce adds one paragraph to the server's
instructions so the agent knows how to split the work:
ast-mcp init --with-cce # records the flag in .mcp.jsoncontext_search(CCE) — fuzzy semantic retrieval over embedded chunks. For "how does auth work?", "where is rate limiting handled?" — you know the concept but not the name.AST_MCP — exact structural retrieval by name, kind and range. For "show me
TokenStore.refresh", "what's in this config file?", "list everyCREATE TABLEin the repo" — you know the name but not the location.
Rough rule: describing behaviour → context_search. Naming a thing →
AST_MCP. A context_search hit hands you a name; get_symbol turns it into
the exact definition.
Without the flag nothing changes and no CCE mention reaches the agent. Plain
ast-mcp init prints a hint if it notices context-engine in .mcp.json;
it never switches modes for you.
One block, not two
CCE writes its own CLAUDE.md instructions, and they say to use
context_search instead of reading files — with no mention of this server, so
a named symbol gets routed to the semantic retriever too. Two blocks means two
contradictory rules, and the loud one wins.
So init replaces that block rather than adding a second one. It reuses CCE's
own <!-- cce-block-version: N --> markers and keeps the value of N it finds
on disk. CCE decides whether to rewrite by testing for its current tag, so a
later cce init sees a match and leaves the file alone. Run cce init first,
then ast-mcp init.
If CCE later bumps that version and reclaims the slot, ast-mcp status says
so — re-run ast-mcp init to take it back. Nothing outside the marked block
is touched, at any point.
What it costs
The saving grows with file size — the response envelope is fixed cost, so small files benefit least. Measured on this codebase:
file | lines | full read | outline | saving |
| 94 | 789 tok | 352 tok | 2.2x |
| 428 | 3994 tok | 967 tok | 4.1x |
| 457 | 3882 tok | 690 tok | 5.6x |
Below roughly 100 lines it is about break-even against Read. Above that it
pays, and get_symbol on a single definition pays regardless.
A 5000-row CSV or JSON array costs the same as a 3-row one: homogeneous
repeats collapse to one node carrying children_count. The collapse says how
far to trust it — uniformity is uniform, mixed, or unverified (over
5000 elements), checked across the element key sets. No value from inside a
collection comes back with it, so asking a 1.3 MB ban_list.json for its
record shape returns the shape and none of the records.
Measure it on your own repo
Every tool response is logged to .ast_mcp/savings.db — what it served, and
what a whole-file read of every file it cited would have cost.
$ ast-mcp savings
root /home/you/project · 5 queries · last query 2m ago
▰▰▰▰▰▰▰▰▰▱ 90% of a whole-file read saved
whole-file reads 38.5k tokens
served by ast-mcp 3.9k tokens
──────────────────────────────────────
saved 34.6k tokens $0.52
~6.9k tokens / query ~$0.10 / query
by tool:
search_symbols 62% ▰▰▰▰▰▰▱▱▱▱ 21.5k $0.32 · 1 call
file_outline 21% ▰▰▱▱▱▱▱▱▱▱ 7.3k $0.11 · 2 calls--json for the same numbers machine-readably, --reset to start the count
over. Pricing is Opus input ($15/1M); set AST_MCP_PRICE_PER_MTOK for another
model, or AST_MCP_NO_STATS=1 to record nothing at all.
Freshness
The SQLite index is a cache, never an oracle. Every path in a response was
stat-checked against its recorded (mtime_ns, size) during that same call,
and reparsed if it moved. There is no watcher daemon and no stale window.
Development
git clone https://github.com/matthew-brough/AST_MCP && cd AST_MCP
uv sync --all-groups
uv run --group dev pytest -qThe suite runs on 3.11 through 3.14. uv build produces the wheel; the
.scm query files ship inside it, and CI fails the build if any are missing.
SPEC.md is the contract: §V invariants, §I interfaces, §T tasks, §B the log
of what went wrong and what changed because of it.
Available Tools
6 toolsast_queryA
Run a raw tree-sitter S-expression query against one file.
The escape hatch for anything the five typed tools flatten away.
Inputs: path (required), query (required), captures, max_tokens.
file_outlineA
Outline one file: definitions, key paths or headings, bodies elided.
Use this instead of reading a file to find out what is in it.
mode: "full" (default) or "names" — names, lines and counts only, for
enumerating what a file defines.
On a data file this answers record count and field types without returning
any value from inside a collection: each collection carries
children_count and uniformity ("uniform" — every element has element
0's keys; "mixed" — they differ; "unverified" — too many to check).
Inputs: path (required), mode, max_depth, max_tokens, +1 more.
get_docstringsB
Documentation without bodies. Pass exactly one of path or symbols.
Inputs: path, symbols, max_tokens.
get_symbolB
Fetch definitions by name, key path, or heading slug.
mode: "source" (default) returns the body, "signature" and "doc" omit it. A name matching several different symbols returns candidates rather than guessing. A name matching several definitions of the same thing — many Lua listeners on one event — returns all of them in "symbols". line: pick one definition by the start_line a candidate reported.
Inputs: name (required), line, mode, path, +1 more.
list_importsC
Dependency edges out of one file, plus exports where the language has them.
Inputs: path (required), max_tokens.
search_symbolsC
Find definitions, key paths and headings by name across the repository.
group is one of core, web, scripting, data, devops, docs.
Inputs: query (required), kind, lang, group, +3 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Most tools target clearly distinct operations: repository search, single-file outline, raw AST query, imports/exports, and symbol lookup. The main ambiguity is between get_docstrings and get_symbol with mode 'doc', which could serve similar documentation-retrieval purposes.
All names are readable snake_case, but the pattern is mixed: get_docstrings and get_symbol use 'get_', while file_outline, ast_query, list_imports, and search_symbols each start with a different noun or verb. There is no single consistent verb_noun convention, though the names are still predictable enough to navigate.
Six tools is a well-scoped size for an AST/source-analysis server. Each tool covers a meaningful slice of the domain without redundancy or bloat, and ast_query exists as an intentional escape hatch rather than a loosely-scoped extra.
The set covers documentation extraction, file outlining, symbol lookup and search, imports/exports, and raw AST querying, which forms a coherent lifecycle for source exploration. The ast_query escape hatch explicitly fills any gap left by the typed tools, so agents can handle cases outside the common patterns.
Maintenance
Related MCP Connectors
Repository knowledge graph MCP server for codebase understanding and debugging.
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
The official Svelte MCP server providing docs and autofixing tools for Svelte development
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceStandalone MCP server for code structure analysis using tree-sitter. Directory trees, symbol definitions, and call graphs without reading raw source files. Supports Rust, Python, Go, Java, TypeScript, Fortran, JavaScript, C/C++, and C#. Benchmarked up to 68% fewer tokens vs native tools.7Apache 2.0
- AlicenseNot gradedqualityBmaintenanceEnables LLM agents to query a codebase's structural knowledge (symbols, imports, call graphs, etc.) via MCP, reducing tokens and improving correctness compared to raw file access.29 npm7MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that indexes your codebase using tree-sitter AST parsing and gives AI tools instant access to structural intelligence like dependency graphs, call trees, and dead code detection from a local SQLite database.MIT
- AlicenseAqualityCmaintenanceEnables AI coding agents to efficiently explore codebases by providing structural outlines, module digests, symbol bodies, and AST-aware grep via MCP.414 npm1MIT