ast-impact-mapper-mcp
MCP server that analyzes TypeScript/JavaScript codebases via AST parsing and dependency graph tracing to identify affected tests, detect dead code, circular dependencies, and trace import chains, enabling AI agents to run only relevant tests.
README
🗺️ ast-impact-mapper-mcp ✨
"Stop boiling the ocean. Run only the tests that actually care about your changes." 🐸
ast-impact-mapper-mcp is an advanced Model Context Protocol (MCP) server that analyzes your TypeScript/JavaScript codebase using AST parsing (ts-morph) and dependency graph tracing. It helps AI agents (like Claude or Cursor) target only the relevant tests, find dead code, identify circular import dependencies, and trace API mutations.
🧐 Why import graphs?
Guessing affected tests based on matching filenames (e.g. auth.ts -> auth.test.ts) is highly inaccurate. Running the entire test suite on every minor change is extremely slow.
Import graphs do not lie. If a test file transitively imports a modified source file, it must be run. ast-impact-mapper-mcp builds a bidirectional file dependency graph and answers "which tests should I run?" in milliseconds.
💡 Quick Showcase (Real-World e2e Flow)
Imagine your AI agent modifies a shared helper: src/utils/auth.ts. Instead of blindly running all tests or guessing by name, the agent uses this MCP server:
1. Identify Affected Tests
The agent calls get_affected_tests with the changed file:
// Tool Call: get_affected_tests({ changed_files: ["src/utils/auth.ts"] })
{
"changed_files": ["/project/src/utils/auth.ts"],
"affected_tests": ["/project/tests/checkout.spec.ts"],
"total_affected": 1
}
2. Explain the Connection
To understand why checkout.spec.ts depends on auth.ts, the agent calls explain_impact:
// Tool Call: explain_impact({ changed_file: "src/utils/auth.ts", test_file: "tests/checkout.spec.ts" })
{
"found": true,
"import_chain": [
"/project/tests/checkout.spec.ts",
"/project/src/fixtures/user-fixture.ts",
"/project/src/utils/auth.ts"
]
}
Aha! The checkout spec imports the user-fixture, which imports auth!
3. Check for Runtime Impact
If the change in auth.ts was only adding a TypeScript interface (type-only change), calling differentiate_type_impact tells the agent:
{
"files": [{ "file": "/project/src/utils/auth.ts", "runtime_impact": false }],
"total_tests_must_run": 0,
"total_tests_skippable": 1
}
Success! Since it is a type-only change, the agent can skip running tests entirely, saving precious CPU cycles and time.
4. Run Minimal Tests
If it does contain runtime changes, the agent requests the execution command:
// Tool Call: generate_test_command({ changed_files: ["src/utils/auth.ts"], runner: "vitest" })
{
"command": "npx vitest run tests/checkout.spec.ts"
}
🛠️ MCP Tools Reference
All tools are configured with consistent, type-safe schemas (arguments in snake_case).
1. Impact Mapping & Tracing
-
get_affected_testsFinds all test files transitively importing changed source files.
- Arguments:
project_root(string, required): Absolute path to the TypeScript project.changed_files(string[], optional): Modified file paths.git_diff(string, optional): Raw stdout ofgit diff --name-only.
- Returns: Detailed map of changed files, affected tests, and totals.
- Arguments:
-
get_affected_tests_by_branchAutomatically diffs the current state against a base branch using git to find affected tests.
- Arguments:
project_root(string, required)base_branch(string, default:"main"): Branch to compare against.
- Arguments:
-
get_rename_aware_diffHighly robust branch impact analysis that tracks file moves/renames (via
git diff -M) and ignores formatting/whitespace changes.- Arguments:
project_root(string, required)base_branch(string, default:"main")similarity_threshold(number, default:90): % similarity threshold to declare a move.
- Arguments:
-
explain_impactTraces and explains the exact chain of imports showing why a changed source file affects a specific test.
- Arguments:
project_root(string, required)changed_file(string, required)test_file(string, required)
- Arguments:
-
generate_test_commandConstructs CLI commands for test runners (
vitest,jest, orplaywright) matching the affected tests subset.- Arguments:
project_root(string, required)changed_files(string[], required)runner(enum:jest,vitest,playwright, default:vitest)
- Arguments:
2. TypeScript-specific Deep Code Analysis
-
differentiate_type_impactInspects imports and types to isolate type-only changes (interfaces, types, or
import typeexports). Helps skip test execution entirely if the changes do not impact the runtime bundle!- Arguments:
project_root(string, required)changed_files(string[], required)
- Arguments:
-
analyze_api_surface_mutationCompares a file against its
HEADversion and determines if it modifies the public API (breaking_api_change) or only contains internal implementation edits (internal_refactor).- Arguments:
project_root(string, required)file_path(string, required)
- Arguments:
-
generate_skeleton_viewGenerates a token-optimized skeleton of a file by stripping out function and method bodies, keeping only signatures, JSDocs, and line numbers.
- Arguments:
project_root(string, required)file_path(string, required)include_jsdoc(boolean, default:true)include_private_members(boolean, default:false)
- Arguments:
-
get_symbol_dependency_graphTraces declaration-level dependencies (functions, classes, variables) across files, finding internal declarations usage.
- Arguments:
project_root(string, required)file_path(string, required)symbol_name(string, optional): Specific export symbol to map.direction(enum:forward,reverse,bidirectional, default:bidirectional)
- Arguments:
3. Codebase Health & Graph Insights
-
identify_unreachable_modulesFinds orphaned source files that have zero incoming imports (dead code safe to prune). Automatically respects standard entry points.
- Arguments:
project_root(string, required)entry_points(string[], optional): Explicit entry-points to exclude from warning.limit(number, default:50)
- Arguments:
-
detect_architectural_cyclesLocates circular dependency loops (e.g.
A → B → C → A) which cause unpredictable module initialization orders.- Arguments:
project_root(string, required)
- Arguments:
-
get_dependency_graphReturns direct imports/importers of a file in JSON format or as a visual Mermaid TD flowchart.
- Arguments:
project_root(string, required)file_path(string, required)format(enum:json,mermaid, default:json)
- Arguments:
-
get_coverage_gapsIdentifies files with zero import coverage — those that are never imported by any test file.
- Arguments:
project_root(string, required)source_dirs(string[], optional)limit(number, default:50)
- Arguments:
-
get_test_summaryProvides a high-level view of test coverage rate, deepest import chains, and high-risk most-imported modules.
- Arguments:
project_root(string, required)
- Arguments:
-
refresh_projectInvalidates AST and dependency graphs cache. Run this after checking out branches or pulling remote git updates.
- Arguments:
project_root(string, required)
- Arguments:
🚀 Installation & Setup
1. Global Installation
npm install -g ast-impact-mapper-mcp
2. Configure Editor / Agent Client
VS Code / Cursor
Add the following to your .cursor/mcp.json or .vscode/mcp.json:
{
"mcpServers": {
"ast-impact-mapper": {
"command": "npx",
"args": ["-y", "ast-impact-mapper-mcp"]
}
}
}
Claude Code CLI
claude mcp add ast-impact-mapper npx -- -y ast-impact-mapper-mcp
💬 Example Scenario
Imagine you modify a shared page component: src/pages/login-page.ts.
- AI Agent runs
get_rename_aware_diff: It detects that onlytests/auth.spec.tsimports the page object transitively. - AI Agent runs
differentiate_type_impact: It sees you only added a type definition interface, classifying it astype_only_change-> it skips running the test execution completely, saving developer cycles! - AI Agent runs
explain_impact: If asked whytests/auth.spec.tsdepends on it, it renders the path:tests/auth.spec.ts→src/fixtures/app.ts→src/pages/login-page.ts.
🔗 The Ecosystem
ast-impact-mapper-mcpanswers: "Which tests are affected by my changes?" 🗺️flakiness-graph-mcpanswers: "Of those affected tests, which ones are historically unstable?" 📊- Together, they form a perfect feedback loop for running a prioritized, resilient, and minimal test suite.
🛠️ CLI Development
npm run build # Compile TypeScript to dist/
npm run lint # Run ESLint validation
npm run format # Format files via Prettier
npm test # Run unit tests via Vitest
📄 License
MIT © vola-trebla 🐸
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。