Ast Impact Mapper Mcp

io.github.vola-trebla由 GitHub 账号 vola-trebla 发布v0.3.1更新于 Oct 24, 2026

MCP server that uses TypeScript AST to find which tests are affected by a code change

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

本地 MCP 服务器,用 AST 解析 TypeScript/JavaScript 项目,找出代码改动影响哪些测试,并检查依赖图。

可以做什么
把改动文件或 git 分支差异映射到间接导入它们的测试,并解释每个匹配背后的导入链,支持重命名感知差异和生成 jest、vitest、playwright 运行命令。区分仅类型改动与运行时改动,判断文件是公共 API 变更还是内部重构。追踪声明级符号依赖,并以 JSON 或 Mermaid 流程图展示文件的直接导入与导入者。查找死代码、循环依赖、未被测试导入的文件,并汇总测试覆盖率和高风险模块。生成精简的文件骨架,并刷新缓存的 AST 与依赖图。
适用场景
适合助手在 TypeScript 或 JavaScript 仓库中工作时使用,例如只运行受改动影响的测试、说明某个测试为何相关,或审查导入关系、死代码和循环依赖。
运行要求
作为本地 stdio 进程运行,从 npm 包 ast-impact-mapper-mcp 安装(例如通过 npx)并在客户端配置。需要 Node.js 和本地 TypeScript/JavaScript 项目;分支差异工具需要 git。未声明认证、环境变量或请求头。
安装前请注意
工具接收项目绝对路径并读取本机源文件,基于 git 的工具会检查仓库分支。它只做分析和报告,不修改代码也不自行运行测试,但会生成供助手执行的测试命令。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Ast Impact Mapper Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

🗺️ ast-impact-mapper-mcp ✨

[npm version] [npm downloads] [CI] [License: MIT]

"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:

json
// 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:

json
// 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:

json
{  "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:

json
// 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_tests

    Finds 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 of git diff --name-only.
    • Returns: Detailed map of changed files, affected tests, and totals.
  • get_affected_tests_by_branch

    Automatically 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.
  • get_rename_aware_diff

    Highly 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.
  • explain_impact

    Traces 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)
  • generate_test_command

    Constructs CLI commands for test runners (vitest, jest, or playwright) matching the affected tests subset.

    • Arguments:
      • project_root (string, required)
      • changed_files (string[], required)
      • runner (enum: jest, vitest, playwright, default: vitest)

2. TypeScript-specific Deep Code Analysis

  • differentiate_type_impact

    Inspects imports and types to isolate type-only changes (interfaces, types, or import type exports). Helps skip test execution entirely if the changes do not impact the runtime bundle!

    • Arguments:
      • project_root (string, required)
      • changed_files (string[], required)
  • analyze_api_surface_mutation

    Compares a file against its HEAD version 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)
  • generate_skeleton_view

    Generates 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)
  • get_symbol_dependency_graph

    Traces 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)

3. Codebase Health & Graph Insights

  • identify_unreachable_modules

    Finds 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)
  • detect_architectural_cycles

    Locates circular dependency loops (e.g. A → B → C → A) which cause unpredictable module initialization orders.

    • Arguments:
      • project_root (string, required)
  • get_dependency_graph

    Returns 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)
  • get_coverage_gaps

    Identifies 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)
  • get_test_summary

    Provides a high-level view of test coverage rate, deepest import chains, and high-risk most-imported modules.

    • Arguments:
      • project_root (string, required)
  • refresh_project

    Invalidates AST and dependency graphs cache. Run this after checking out branches or pulling remote git updates.

    • Arguments:
      • project_root (string, required)

🚀 Installation & Setup

1. Global Installation

bash
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:

json
{  "mcpServers": {    "ast-impact-mapper": {      "command": "npx",      "args": ["-y", "ast-impact-mapper-mcp"]    }  }}
Claude Code CLI
bash
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.

  1. AI Agent runs get_rename_aware_diff: It detects that only tests/auth.spec.ts imports the page object transitively.
  2. AI Agent runs differentiate_type_impact: It sees you only added a type definition interface, classifying it as type_only_change -> it skips running the test execution completely, saving developer cycles!
  3. AI Agent runs explain_impact: If asked why tests/auth.spec.ts depends on it, it renders the path: tests/auth.spec.ts → src/fixtures/app.ts → src/pages/login-page.ts.

🔗 The Ecosystem

  • ast-impact-mapper-mcp answers: "Which tests are affected by my changes?" 🗺️
  • flakiness-graph-mcp answers: "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

bash
npm run build        # Compile TypeScript to dist/npm run lint         # Run ESLint validationnpm run format       # Format files via Prettiernpm test             # Run unit tests via Vitest

📄 License

MIT © vola-trebla 🐸

来源:README.md,提交 f895ef2

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.3.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分