Code Analyze MCP

io.github.clouatre-labs由 GitHub 账号 clouatre-labs 发布v0.6.0更新于 Oct 24, 2026

MCP server for code structure analysis using tree-sitter.

已验证STDIO仅桌面知识与记忆开发者工具

概览

AI 生成的概览

一个本地代码智能 MCP 服务器,用 tree-sitter 解析代码库,向助手提供目录结构、符号表和调用图,而不是原始文件内容。

可以做什么
生成目录树,统计行数、函数和类数量,并遵循 .gitignore;列出文件的函数、类和导入及其签名与行范围,或提供更精简的模块函数与导入索引。按符号名在目录中追踪调用图,包括调用者、被调用者和调用深度。通过资源模板浏览结构图,查看单个或多个符号的影响范围与子图。创建或覆盖文件,替换精确文本块,支持内容哈希校验和原子批量编辑。运行 shell 命令,输出有上限并经过过滤,完整输出可通过溢出资源读取。校验 path:line 锚点在工作区根目录下是否真实存在。
适用场景
适合助手处理大型或不熟悉的代码库、需要符号查找、调用图或目录结构等结构化上下文而不必读取原始文件的场景。也适合核实引用的文件和行号是否真实存在,以及 IDE 助手、CI 任务等非交互式使用方。
运行要求
作为本地进程运行在用户机器上,可通过 Homebrew、cargo-binstall 或 cargo 安装,或用 Rust 工具链从源码构建。支持 stdio 或 streamable HTTP;HTTP 模式使用端口,由 APTU_CODER_PORT 或 --port 设置,并可通过 APTU_CODER_BEARER_TOKEN 启用可选的 bearer 令牌认证。未声明需要账号或 API 密钥。
安装前请注意
服务器可以写入文件并执行任意 shell 命令,助手因此可能修改或删除机器上的数据,应审慎对待。HTTP 模式在未设置 APTU_CODER_BEARER_TOKEN 时没有认证,且令牌过短只会记录警告。分析缓存会写入本地磁盘目录,配置后指标可导出到文件。按 README 说明,源码在本地解析,不会离开机器。

安装

在 SourceWeft 中

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

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

其他 MCP 客户端

参照 仓库 中的启动说明。

README

aptu-coder

[crates.io] [SLSA Level 3] [OpenSSF Best Practices]

A Model Context Protocol (MCP) code-intelligence server that gives AI coding agents pre-parsed symbol tables and call graphs instead of raw file bytes, cutting token usage by up to 59% in the cited benchmark conditions (see Benchmarks). OpenSSF silver certified: fewer than 1% of open source projects reach this level.

[!NOTE] Native agent tools (regex search, path matching, file reading) handle targeted lookups well. aptu-coder handles the mechanical, non-AI work: mapping directory structure, extracting symbols, and tracing call graphs, so a coding agent's context window is spent reasoning instead of re-deriving structure on every call.

Most code-intelligence tooling for AI agents indexes a codebase into a cloud embedding or vector store and retrieves by similarity search. aptu-coder instead parses the codebase into a structural graph on-device with tree-sitter and serves it locally over MCP: no source code leaves the machine, and retrieval is exact (symbol tables and call graphs) rather than approximate (nearest-neighbor similarity).

Benchmarks

Auth migration task on Claude Code against Django (Python) source tree. Full methodology.

ModeSonnet 4.6Haiku 4.5
MCP112k tokens, $0.39406k tokens, $0.42
Native276k tokens, $0.95473k tokens, $0.53
Savings59% fewer tokens, 59% cheaper14% fewer tokens, 21% cheaper

AeroDyn integration audit task on Claude Code against OpenFAST (Fortran) source tree. Full methodology.

ModeSonnet 4.6Haiku 4.5
MCP472k tokens, $1.65687k tokens, $0.72
Native877k tokens, $2.852162k tokens, $2.21
Savings46% fewer tokens, 42% cheaper68% fewer tokens, 68% cheaper

A real end-to-end multi-agent run against this repository itself: five refactoring issues (#1578–#1582) fixed by the coder skill in one orchestrated session — 23 subagent spawns (5 scout, 1 guard, 10 build, 7 check), ~1h42m, three human interventions — producing PRs #1584–#1588, all merged with CI green. Case study.

Scope of the benchmark claims

The token-savings figures above come from single, focused comprehension tasks where the agent used aptu-coder instead of shell search. Agentic coding loops have bash and ripgrep and can search the repo directly. The v19 benchmark program (N=20 paired sessions, pre-registered claim gate) measured aptu-coder in those loops: no measurable answer-quality gain over bash + ripgrep on structural fan-in tasks (pooled paired F1 diff mean -0.071, 95% CI [-0.179, +0.038]; gate NOT-SUPPORTED); tool activation itself was reliable when tools were surfaced directly. Recommended uses: deterministic verification (verify_anchors against fabricated path:line citations), premise grounding for multi-agent workflows, and non-agentic MCP consumers (IDE assistants, CI jobs, scoring pipelines).

Overview

aptu-coder is a comprehension layer for coding agents: it gives an agent harness precise structural context about a codebase, directory trees, symbol definitions, and call graphs, without the agent reading raw files or re-deriving structure on every call. That prevents context starvation on large or unfamiliar codebases while keeping the result set small enough to fit the model's context window. It supports 18 languages (see Supported Languages) and integrates with any MCP-compatible orchestrator.

Structural context is built once and reused: an on-disk cache keyed by blake3 content hashes keeps results correct across concurrent writes. The same structural graph backs the Knowledge Graph resource surface below. For consumers that hold source text without an on-disk path, aptu-coder-core also exposes analyze_str as a public Rust library API (see ARCHITECTURE.md).

Further reading on the design philosophy: The Agentic SDLC Governance Stack, Context Engineering for Multi-Agent Reliability, and Orchestrating AI Agents: Subagent Architecture.

Supported Languages

LanguageExtensions
Astro.astro
C/C++.c, .cc, .cpp, .cxx, .h, .hpp, .hxx
C#.cs
CSS.css
Fortran.f, .f77, .f90, .f95, .f03, .f08, .for, .ftn
Go.go
HTML.html, .htm
Java.java
JavaScript.js, .mjs, .cjs
JSON.json
Kotlin.kt, .kts
Markdown.md, .mdx
Python.py
Rust.rs
TOML.toml
TSX.tsx
TypeScript.ts
YAML.yaml, .yml

Installation

Homebrew (macOS and Linux)

bash
brew install clouatre-labs/tap/aptu-coder

Update: brew upgrade aptu-coder

cargo-binstall (no Rust required)

bash
cargo binstall aptu-coder

cargo install (requires Rust toolchain)

bash
cargo install aptu-coder

Quick Start

Build from source

bash
cargo build --release

The binary is at target/release/aptu-coder.

Configure MCP Client

Two transports are available. Streamable HTTP is recommended when using orchestrators that spawn delegates (e.g. goose coder): a single server process is shared across the orchestrator and all agents, eliminating extension-drift that occurs when each stdio subprocess gets its own isolated instance.

Streamable HTTP (recommended for multi-agent setups)

With Homebrew, one command starts the server on login and keeps it running:

bash
brew services start aptu-coder

The Homebrew formula starts the server on port 49200 by default. Then add the extension once to ~/.config/goose/config.yaml:

yaml
extensions:  aptu-coder:    type: streamable_http    uri: http://127.0.0.1:49200/mcp    name: aptu-coder    timeout: 300

Or for Claude Code:

bash
claude mcp add --transport http aptu-coder http://127.0.0.1:49200/mcp

To use a different port, set APTU_CODER_PORT before restarting:

bash
APTU_CODER_PORT=4000 brew services restart aptu-coder

To start directly without brew services:

bash
aptu-coder --port 49200# or equivalentlyAPTU_CODER_PORT=49200 aptu-coder

stdio (single-client use)

Suitable when only one process needs the server. The client owns the process lifecycle and spawns it automatically:

bash
claude mcp add --transport stdio aptu-coder -- aptu-coder

Or add manually to .mcp.json at your project root (shared with your team via version control):

json
{  "mcpServers": {    "aptu-coder": {      "command": "aptu-coder",      "args": []    }  }}

Tools

All optional parameters may be omitted. Shared optional parameters for analyze_directory, analyze_file, and analyze_symbol:

ParameterTypeDefaultDescription
summarybooleanautoCompact output; auto-triggers above 50K chars
cursorstring--Pagination cursor from a previous response's next_cursor

Page size is server-owned; there is no client page_size parameter (passing one returns INVALID_PARAMS).

ToolPurposeLanguages
analyze_directoryDirectory tree with LOC, function, and class counts; respects .gitignore; file paths in the output are relative to the working directoryall
analyze_fileFunctions, classes, and imports with signatures and line ranges; returns graceful fallback (line count, file head, no AST) for unsupported extensionsall
analyze_moduleLightweight function and import index (~75% smaller than analyze_file); returns graceful fallback (empty index with note) for unsupported extensionsall
analyze_symbolCall graph for a named symbol across a directory; callers, callees, call depthall
edit_overwriteCreate or overwrite a file; creates parent directoriesany file
edit_replaceReplace a unique exact text block or all non-overlapping occurrences (replace_all=true); errors if zero or multiple matches; empty new_text deletes the block; CRLF normalized before matching; optional expected_content_hash (blake3 hex of raw bytes) rejects stale edits; concurrent edits to the same file are serialized per-path; returns occurrences_replaced count. Batch form: pass edits[] (array of {old_text, new_text, replace_all}) instead of old_text/new_text to apply multiple replacements to one file atomically (any invalid edit aborts with per-index errors, no write)all
exec_commandRun a shell command; returns stdout, stderr, exit code; output capped and filtered; the command is killed when the request is cancelled; server-owned post-exit drain window (500 ms default); heredoc rejected before spawn (file-write pattern, stdin-consuming flag, stdin parameter conflict, or missing closing delimiter); structuredContent carries metadata only (exit code, truncation, collection-error flags), command output lives in the text streamany
verify_anchorsBatch-verify path:line[:symbol] anchors against a workspace root: file exists, 1-based line within range, and optional word-boundary symbol match within a plus or minus 2 line window; fail-closed semantics, never fabricates success; structuredContent carries one verdict per anchor (exists, in_range, symbol_found, window_line)all

Tool parameters, constraints, and examples are available via your MCP client's tool inspector or tools/list response.

Knowledge Graph

analyze_symbol builds a structural graph of the codebase as a side effect: files, symbols, and modules as nodes, connected by typed edges (contains, calls, imports). That graph is exposed to agents as MCP resource templates for navigating relationships beyond a single symbol's immediate call graph. Resources are URI-addressed; use resources/templates/list to discover available templates.

URI TemplateDescription
aptu-coder://graph/{repo_hash}/blast-radius/{symbol}?depth={depth}&format={format}BFS traversal from a symbol outward to configurable depth (default: 3). Returns caller/callee chains in a radial layout.
aptu-coder://graph/{repo_hash}/subgraph/{symbol}?format={format}The full subgraph (callers, callees, and their connections) for a single symbol.
aptu-coder://graph/{repo_hash}/blast-radius-bidirectional/{symbols}?max_nodes={max_nodes}&depth={depth}&format={format}Bidirectional BFS from one or more comma-separated seed symbols walking both callers and callees.

Pagination: Results are paginated; pass the opaque cursor value from a previous response to fetch the next page.

Depth parameter: The blast-radius and blast-radius-bidirectional templates accept an optional depth query parameter (integer in range 1-5, default 3).

Max nodes parameter: The blast-radius-bidirectional template accepts an optional max_nodes query parameter (integer, default 50) that caps the visited node set during traversal.

Format parameter: All three query types accept an optional format query parameter (text or json, default json). When format=text, the response is a prompt-ready plain-text representation generated by render_subgraph_text instead of the JSON nodes/edges structure.

Cold cache: Call analyze_symbol on the directory first to build the graph. Resources return an informational message until the graph is available.

Output Management

For large codebases, several mechanisms prevent context overflow.

Pagination

analyze_file and analyze_symbol append a NEXT_CURSOR: line when output is truncated. Pass the token back as cursor to fetch the next page. summary=true and cursor are mutually exclusive; passing both returns an error.

# Response ends with:NEXT_CURSOR: eyJvZmZzZXQiOjUwfQ==
# Fetch next page:analyze_symbol path: /my/project symbol: my_function cursor: eyJvZmZzZXQiOjUwfQ==

exec_command output caps

exec_command applies three independent byte-level caps to prevent large command outputs from flooding the context:

StreamCapBehavior
stdout30,000 charsTail-preserving; keeps the last 30k chars
stderr10,000 charsTail-preserving; errors appear at the end
combined output_text50,000 charsSafety net after interleaving

The 30k stdout cap is data-driven: analysis of 27,981 observed exec_command calls shows only 0.33% exceed this limit. When any cap fires, output_truncated: true is set in the response and recorded in the JSONL metrics.

Recovering capped output: when output is capped, the response includes MCP resource links (aptu-overflow://slot-{seq}/stdout, /stderr, /interleaved) pointing to the full raw capture for that invocation (last-run-wins); read them via resources/read. If a filter capped the output, a hint line points to the pre-filter capture file.

A server-owned post-exit drain window (500 ms) waits for any background subprocess still holding the pipe open. If it expires before the pipe closes, exit_code is null and output_truncated: true is set.

exec_command output filters

A built-in filter table suppresses per-file noise from chatty CLI tools before output reaches the model. Filters apply to stdout, stderr, and interleaved output on success only; raw output is always preserved on failure.

CommandBehavior
git pullStrips diff-stat noise (pipe bars, create mode, delete mode, rename, mode change lines); empty output replaced with ok (up-to-date)
git fetchStrips From and ref-range lines; caps at 10 lines; empty output replaced with ok fetched
git pushStrips remote: progress lines and To destination lines; caps at 10 lines; empty output replaced with ok pushed
git logCaps at 20 lines
git statusCaps at 20 lines
git showStrips patch hunks (@@ headers and +/- diff lines); caps at 200 lines
git commitStrips GPG signing and gitleaks hook output; caps at 10 lines; empty output replaced with ok committed
git diffStrips ANSI escape sequences; caps at 100 lines; empty output replaced with ok (working tree clean)
git addStrips gitleaks hook output; caps at 5 lines; empty output replaced with ok staged
cargo buildStrips Compiling / Checking / Downloading / Fresh lines; empty output replaced with ok (build clean)
cargo testStrips Compiling / Checking / Fresh lines

Project-local rules can be added in .aptu/filters.toml. Parse errors and unrecognized schema_version values (version != 1) fall back to the built-in table with a logged warning; no crash occurs. When a filter fires, filter_applied in structuredContent identifies which rule matched.

Non-Interactive Pipelines

In single-pass subagent sessions, prompt caches are written but never reused. Benchmarks showed MCP responses writing ~2x more to cache than native-only workflows, adding cost with no quality gain. Set DISABLE_PROMPT_CACHING=1 (or DISABLE_PROMPT_CACHING_HAIKU=1 for Haiku-specific pipelines) to avoid this overhead.

The server's own instructions are deliberately minimal, a single short paragraph: start with analyze_directory for a package/module map, then use analyze_module/analyze_file for per-file detail and analyze_symbol for call graphs, with a pointer to docs/METRICS.md for JSONL metrics and jq recipes. MCP clients that surface server instructions will present this guidance automatically to the agent.

Environment Variables

Cache and runtime

VariableDefaultDescription
APTU_CODER_DIR_CACHE_CAPACITY20LRU cache size for directory-analysis results.
APTU_CODER_DISK_CACHE_DIR$XDG_DATA_HOME/aptu-coder/analysis-cacheDirectory shared by the L2 call-graph cache and the structural-graph cache used by analyze_symbol. Created automatically if it does not exist.
APTU_CODER_DISK_CACHE_DISABLEDunsetSet to 1 to disable the L2 call-graph disk cache entirely.
APTU_CODER_DISK_CACHE_MAX_BYTES536870912 (512 MiB)Max size in bytes for the structural-graph disk cache. LRU-by-mtime eviction runs when exceeded.
APTU_CODER_FILE_CACHE_CAPACITY100LRU cache size for file-analysis results.
APTU_CODER_METRICS_EXPORT_FILEunsetAbsolute path for a one-shot JSONL metrics export on shutdown.
APTU_CODER_PORTunsetPort for streamable HTTP mode. Equivalent to --port N; --port takes precedence. When unset and --port is not passed, stdio mode is used.
APTU_CODER_BEARER_TOKENunsetBearer token for Streamable HTTP transport authentication. A warning is logged if the value is fewer than 32 characters.
APTU_SHELLunsetShell for exec_command. Defaults to bash then /bin/sh.

Observability

For the JSONL schema, OTel configuration, and span attribute policy, see:

Documentation

  • AGENTS.md - Contributor reference: project structure, commands, rmcp footguns, tool parameter constraints
  • ARCHITECTURE.md - Design goals, module map, data flow, language handler system, caching strategy
  • CONTRIBUTING.md - Development workflow, commit conventions, PR checklist
  • DESIGN-GUIDE.md - Design decisions, rationale, and replication guide for building high-performance MCP servers
  • MCP Best Practices - Best practices for agentic loops, orchestration patterns, MCP tool design, memory management, and safety controls
  • METRICS.md - Metrics schema, JSONL format, and retention policy
  • ROADMAP.md - Development history and future direction
  • SECURITY.md - Security policy and vulnerability reporting

License

Apache-2.0. See LICENSE for details.

来源:README.md,提交 fd3016c

工具

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

版本历史

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

评分

已满足适用检查项的 50%

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

  • 近 30 天内可连通25 分

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

  • 已声明认证方式10 分

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

  • 已列出工具15 分

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

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