ast-mcp-server
The ast-mcp-server gives coding agents compact, type-aware, compiler-resolved access to TypeScript/JavaScript projects through a safe prepare → review → apply protocol. Here's what you can do:
Reading & Exploration
List files — paginated, deterministic inventory of project source files (with glob filtering)
Get file outline — body-free declaration signatures for quick structural context
Get symbol source — fetch the exact source of a single function, method, class, or type declaration
Search symbols — structurally find declarations by name, kind, or symbol path across the project
Find references — locate all compiler-resolved semantic usages of a symbol, including its declaration
Get diagnostics — retrieve project-wide or file-scoped TypeScript diagnostics (errors/warnings)
Mutations (Prepare → Review → Apply)
Rename a symbol — prepare a project-wide, hash-bound rename plan with diagnostic delta and affected files (no writes until applied)
Replace a symbol body — prepare a body-only replacement preserving the signature (supports functions, methods, accessors, function-valued variables/properties)
Preview an operation — retrieve the complete unified diff for a prepared plan, optionally scoped to one file
Apply an operation — atomically apply a reviewed, hash-bound plan after verifying integrity; conflicts abort before writes, retries are idempotent
Batch/CLI Workflow (ast-tool)
Run declarative DAG-like pipelines chaining read/prepare tools with JSON Pointer
$refresult referencesBounded
foreachfor repeated operations with concurrency controlast-tool validateto check pipelines without running themPrepare operations in one process, apply later across CLI boundaries via
ast-tool applyIdempotent receipt replay for safe re-application
Built-in batch safety limits (1 MiB input, 50 steps, 500 invocations, 16 max concurrency)
Setup
ast-tool setup— interactive wizard that detects Claude Code/Hermes, installs thestructural-code-editingskill, and registers the MCP server
Provides compile-model-aware structural code tools for TypeScript and JavaScript projects, including AST outlines, symbol source retrieval, reference finding, symbol renaming, and safe body replacement through ts-morph.
Click on "Install 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-serverget a compact outline of src/utils.ts"
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-server
ast-mcp-server gives coding agents compact, type-aware access to TypeScript and JavaScript projects. It uses the real compiler project model through ts-morph, so declarations, references, rename locations, and diagnostics come from the AST instead of text-search guesses.
Reads are bounded and structured. Writes follow an explicit prepare → review → apply protocol with immutable hashes, workspace freshness checks, diagnostic guards, and idempotent receipts.
The problem
Coding agents often fall back to two generic operations: read files as plain text and write text patches. That works, but it has three predictable costs:
Too much context. The agent may load hundreds of lines when it only needs one signature or method body. That consumes model context and tokens without improving the answer.
Fragile edits. Text patches do not inherently understand declarations, scopes, overloads, or TypeScript diagnostics. A plausible-looking edit can target the wrong construct or introduce a new compiler error.
Weak cross-file reasoning. Text search can find matching words, but it cannot reliably distinguish two unrelated symbols with the same name. Project-wide references and renames need the compiler's understanding of the program.
Related MCP server: @aiready/ast-mcp-server
What this tool does instead
This MCP server gives the agent structural code tools in addition to generic file reads and writes. Under the hood, ts-morph uses the TypeScript compiler project model, so the server can reason about declarations and references as code rather than undifferentiated text.
Need | Structural operation | Returned scope |
Understand a file |
| Signatures without implementation bodies |
Inspect one declaration |
| Exact source for one function, method, class, or type |
Find usages across the project |
| Compiler-resolved reference locations |
Rename a symbol everywhere |
| A reviewed project-wide rename plan |
Change one implementation |
| A body-only plan that preserves the declaration |
Reads can start with a compact outline and fetch exact source only when needed. Mutations are prepared in memory first, compared against baseline diagnostics, and returned as immutable, hash-bound plans. Nothing is written until the caller reviews and explicitly applies the plan.
Why this helps
Less context: the agent retrieves the smallest structural unit that answers the question instead of loading the complete file by default.
Safer changes: exact symbol selection, diagnostic deltas, workspace freshness checks, and
prepare → review → applyreduce the failure modes of ad hoc text editing.Accurate project-wide operations: references and renames use compiler resolution rather than matching identifier text with grep.
AST-aware editing is not a proof that a change is semantically correct. The safety comes from combining structural selection with diagnostics, exact previews, reviewed hashes, freshness checks, and fail-closed apply semantics.
The included batch benchmark records a 50% reduction in model round-trips and a 95.21% reduction in serialized context for its search-to-source scenario. These are reproducible scenario measurements, not universal token or latency claims.
Requirements
Node.js 20.19 or newer
Corepack with Yarn 4.15.0 (pinned by
packageManager)A target project with a
tsconfig.json
Install
Install the published CLI globally while keeping dependency lifecycle scripts disabled:
npm install --global ast-mcp-server --ignore-scripts
ast-tool setup--ignore-scripts prevents dependencies from running preinstall, install, or postinstall hooks. The package and its current runtime dependencies do not require those hooks.
Install from source
To build the current source instead:
git clone https://github.com/yailPeralta/ast-mcp-server.git
cd ast-mcp-server
corepack enable
yarn install --immutable
yarn buildThe repository pins Yarn 4 and commits enableScripts: false in .yarnrc.yml. Dependency lifecycle scripts are therefore disabled during installation; switching from npm without this setting would merely change logos while preserving the risk.
The package exposes two executables when installed:
ast-mcp-server: MCP stdio server.ast-tool: batch, skill-installation, and agent-setup CLI.
Guided agent setup
The installed package opens the interactive wizard with:
ast-tool setupFrom a source checkout, use the Yarn script; it builds first and then opens the same wizard:
yarn setupThe wizard detects Claude Code and Hermes from PATH, shows their executable and version, selects every detected agent by default, and lets you deselect agents before confirmation. For each selected agent it:
preflights any existing
astMCP registration;installs the bundled
structural-code-editingskill;registers this package's MCP server through the agent's official CLI;
reconnects and verifies the expected tools.
Existing matching registrations and skill files are unchanged. Conflicting MCP registrations fail before any write; remove or rename them explicitly instead of letting a setup script guess. Conflicting skill content also fails closed unless --force-skill is explicit.
For automation, make the target set and confirmation explicit:
ast-tool setup --agents all --yes
ast-tool setup --agents claude --yesFrom a source checkout, replace ast-tool with yarn setup in those commands.
Install the agent skill
The package bundles a structural-code-editing skill that teaches an agent when to use the AST tools, how to minimize context, and how to review mutations safely. Install it for both Claude Code and Hermes with one command:
ast-tool install-skill allOr install one target at a time:
ast-tool install-skill claude
ast-tool install-skill hermesThe default is user scope. It writes to Claude Code's personal skill directory and to the active HERMES_HOME:
Target | Destination |
Claude Code |
|
Hermes |
|
To commit the skill into one project for Claude Code, use project scope:
ast-tool install-skill claude --scope project --project-root /absolute/projectThis writes .claude/skills/structural-code-editing/SKILL.md below that project. Project scope is intentionally rejected for Hermes because Hermes skills belong to a profile, not a source repository.
Installation is idempotent. Existing identical content is left untouched; different content fails closed unless --force is explicit. From an unlinked source checkout, replace ast-tool with yarn node /absolute/path/to/ast-mcp-server/dist/cli.js.
Claude Code detects changes in an existing skill directory live; restart it if the top-level skills directory did not exist when the session started. In Hermes, run /reload-skills or start a new session, then verify with hermes skills list.
install-skill only installs the skill; it does not configure the MCP transport. Use the guided setup command to do both, or complete the client-specific MCP setup below—the instructions are useful, but they have not yet learned to open a stdio socket through positive thinking.
Use with Claude Code
Claude Code supports local stdio MCP servers. After building this repository, register the server with an absolute entrypoint:
AST_MCP_DIR="$(pwd)"
claude mcp add --scope user --transport stdio ast -- \
node "$AST_MCP_DIR/dist/index.js"
claude mcp get astclaude mcp get ast should report Status: ✔ Connected. The -- separator is required: everything after it is the server command, not a Claude Code option.
The example uses --scope user, which makes the server available in all your projects. Use --scope local instead to register it only for the project from which you run the command. Avoid committing a project-scoped .mcp.json that contains another developer's absolute checkout path.
Start Claude Code inside any TypeScript project with a tsconfig.json:
cd /absolute/path/to/your-typescript-project
claudeThen ask Claude to use the ast tools. For example:
Use the ast MCP server to inspect this project.
First search for UserService, then fetch only the exact source of its create method.For a reviewed rename:
Use ast_rename_symbol to prepare renaming UserService.create to createUser.
Do not apply it yet. Show me the affected files, diagnostic delta, plan hash,
and the complete operation preview.After reviewing the preview:
Apply that operation with ast_apply_operation using the exact operation_id and
plan_hash returned by the prepare step.Project-scoped read and prepare tools require project_root. Claude should pass the current project directory or its explicit tsconfig.json path. Preview and apply calls instead use the prepared operation coordinates; the MCP server itself contains no repository-specific paths.
MCP or batch CLI?
Workflow | Recommended interface |
Interactive exploration or one reviewed mutation | Claude Code MCP tools |
A known multi-step read pipeline |
|
Prepare now and apply in a later process |
|
Use /mcp inside Claude Code to inspect server status and tools. Outside the session, use claude mcp list, claude mcp get ast, or claude mcp remove ast -s user.
Other MCP clients
Hermes Agent:
hermes mcp add ast --command node --args /absolute/path/to/ast-mcp-server/dist/index.js
hermes mcp test astProject-scoped tools accept project_root, either the project directory or an explicit tsconfig.json path. The server contains no repository-specific paths.
MCP tools
Tool | Purpose | Mutates files |
| Paginated, project-relative source file inventory | No |
| Body-free declaration signatures; detailed symbol metadata is opt-in | No |
| Exact source for one declaration | No |
| Paginated structural symbol discovery | No |
| Compiler-resolved references with bounded context | No |
| Project- or file-scoped TypeScript diagnostics | No |
| Prepare a project-wide rename | No |
| Prepare a body-only replacement while preserving the signature | No |
| Retrieve the complete retained diff for a prepared plan | No |
| Apply one reviewed, hash-bound plan | Yes |
Read results use project-relative paths, deterministic ordering, structured MCP output, and pagination where result sets can grow with the project.
Batch CLI
ast-tool lets Claude Code and other Bash-capable clients collapse a known structural pipeline into one shell call:
ast-tool validate pipeline.json
ast-tool run pipeline.json
cat pipeline.json | ast-tool run -Example search-to-source pipeline:
{
"version": 1,
"project_root": "/absolute/project",
"steps": [
{
"id": "search",
"tool": "ast_search_symbols",
"input": { "query": "UserService", "limit": 20 }
},
{
"id": "source",
"tool": "ast_get_symbol_source",
"input": {
"file_path": { "$ref": "#/steps/search/symbols/0/file" },
"symbol_path": { "$ref": "#/steps/search/symbols/0/symbol_path" }
}
}
],
"emit": { "$ref": "#/steps/source" }
}A $ref is an RFC 6901 JSON Pointer rooted at prior step results. References cannot point forward. If emit is omitted, only the final step result is returned; intermediate results remain inside the process.
Bounded foreach
{
"version": 1,
"project_root": "/absolute/project",
"limits": { "concurrency": 4 },
"steps": [
{ "id": "files", "tool": "ast_list_files", "input": { "limit": 20 } },
{
"id": "outlines",
"tool": "ast_get_outline",
"foreach": { "$ref": "#/steps/files/files" },
"input": { "file_path": { "$item": "" } }
}
]
}$item accepts an empty pointer for the complete item or /field for one field. Foreach is read-only, order-preserving, fail-fast, and concurrency-bounded.
Batch limits
Input document: 1 MiB.
Steps: 50.
Total tool invocations: 500.
Foreach items per step: 200.
Read concurrency: default 4, maximum 16.
Each retained step result and final serialized output: 10 MiB.
Total retained intermediate context: 50 MiB.
One project root per pipeline.
No branches, eval, embedded JavaScript, while loops, or arbitrary transformations.
Success is one JSON value on stdout. Errors are structured JSON on stderr. Exit code 0 is success, 1 is execution/apply failure, and 2 is usage or schema failure.
Reviewed mutations
MCP process
Rename and body replacement never write directly:
Call
ast_rename_symbolorast_replace_symbol_body.Review the diagnostic delta, affected files,
blocked, andplan_hash.Fetch complete diffs with
ast_get_operation_previewwhen needed.Call
ast_apply_operationwith bothoperation_idandplan_hash.
MCP plans live in a bounded in-memory store and do not survive a server restart.
CLI process boundary
A batch may contain at most one prepare operation. It must be the final step and cannot use foreach. ast_apply_operation and arbitrary preview calls are forbidden inside batch documents.
A CLI prepare writes an exact private plan and returns top-level operation_id, plan_hash, and plan_file even when emit omits them:
ast-tool run prepare-rename.json
ast-tool apply /path/from/plan_file.astplan --plan-hash <reviewed-sha256>The default plan directory is:
${XDG_STATE_HOME:-~/.local/state}/ast-tool/plansSet AST_TOOL_STATE_DIR to isolate it. Directories are mode 0700; plans are mode 0600, atomically replaced, size-bounded, versioned, and expire with the prepared operation. Plan files contain exact proposed source bytes and must be treated as private code.
Apply loads the exact retained postimages, requires the separately supplied reviewed hash, validates serialized byte hashes and contained paths, rechecks the complete source/config workspace, stages writes, verifies postimages, and persists an applied receipt inside the same cooperative workspace lock. A later CLI invocation can replay that receipt idempotently, including after the preparation TTL.
Guarantee boundary
The server does not claim a filesystem-wide transaction:
Replacement is atomic per file where the local filesystem provides atomic rename.
A multi-file apply has a short interval in which some replacements may already be visible.
Rollback is best effort and refuses to overwrite a file changed by another writer after replacement.
MCP and CLI apply share a fail-closed filesystem lock keyed by canonical
tsconfig.jsonwhen they use the same state directory. It does not coordinate editors, NFS writers, or hostile external processes.Receipt persistence runs before that lock is released. If receipt storage fails after source replacement, apply exits non-zero and reports that verified postimages may be present; retry recovers the receipt only when the complete workspace exactly matches the reviewed post-workspace fingerprint.
A hard process crash can leave a stale lock. Remove it only after inspecting its metadata and proving no apply is running; exact complete postimages can then recover the receipt, while partial or divergent state remains a conflict.
Source encoding support is UTF-8, with or without BOM. Unsupported encodings are rejected.
Development gates
yarn format:check
yarn lint
yarn typecheck
yarn test
yarn build
yarn test:mcp
yarn test:cli
yarn test:package
yarn npm audit --all --recursive
yarn pack --dry-runtest:mcp exercises the built stdio server. test:cli runs a read pipeline and a prepare/apply/replay workflow across separate Node processes.
Benchmarks
yarn benchmark /absolute/project --sample 20 --output benchmark/results/project.json
yarn benchmark:corpus benchmark/task-corpus.json --output benchmark/results/self-corpus.json
yarn benchmark:batch --iterations 5 --output benchmark/results/self-batch.jsonThe batch benchmark compares two separate client calls with one batch invocation in fresh Node processes, recording model round-trips, actual tool invocations, wall time, maximum RSS, and serialized character counts. Character counts are not model-specific token estimates. See benchmark/README.md for methodology and limitations.
Scope
TypeScript and JavaScript projects understood by the TypeScript compiler.
Structural rename and callable-body replacement.
Declarative DAG-like pipelines with prior-result references and bounded foreach.
No arbitrary signature migration, file creation/deletion plans, cross-language refactors, or general-purpose scripting language.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseAqualityDmaintenanceA TypeScript-aware MCP server that provides coding agents with repository discovery, code intelligence, and web project context for local codebases. It enables deep symbol navigation, diagnostic reporting, and structural analysis of monorepos without requiring full IDE integration.Last updated7201MIT
- Alicense-qualityCmaintenanceAST-aware TypeScript/JavaScript codebase exploration for AI agents, providing high-precision symbol resolution, reference finding, and structural analysis via MCP tools.Last updated496MIT
- Alicense-qualityAmaintenanceA local MCP server that gives AI coding agents symbol definitions, dependency graphs, and a live architecture vocabulary for TypeScript/JavaScript repos, with no network or embeddings.Last updated22MIT
- Alicense-qualityDmaintenanceMCP server providing 29 tools across 5 layers for semantic TypeScript/JavaScript code intelligence, enabling AI agents to find references, trace impacts, guard APIs, and explain errors without text-search false positives.Last updated91MIT
Related MCP Connectors
User-owned memory for AI agents, Copilot, Claude, IDEs, CLIs, and chat apps over remote MCP.
A MCP server built for developers enabling Git based project management with project and personal…
MCP server for generating rough-draft project plans from natural-language prompts.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/yailPeralta/ast-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server