code-analyze-mcp
Standalone MCP server for code structure analysis using tree-sitter.
Overview
code-analyze-mcp is a Model Context Protocol server that analyzes code structure across 5 programming languages. It exposes three tools: analyze_directory (file tree with metrics), analyze_file (functions, classes, imports from a single file), and analyze_symbol (call graph for a named symbol). It integrates with any MCP-compatible orchestrator (Claude Code, Kiro, Fast-Agent, MCP-Agent, and others), minimizing token usage while giving the LLM precise structural context.
Installation
Homebrew (macOS and Linux)
Update: brew upgrade code-analyze-mcp
cargo-binstall (no Rust required)
cargo install (requires Rust toolchain)
Quick Start
Build from source
The binary is at target/release/code-analyze-mcp.
Configure MCP Client
Add to .mcp.json at your project root (shared with your team via version control):
Or add via the Claude Code CLI:
Tools
All optional parameters may be omitted. Shared optional parameters across tools:
| Parameter | Type | Default | Description |
|---|---|---|---|
summary |
boolean | auto | Compact output; auto-triggers above 50K chars |
cursor |
string | -- | Pagination cursor from a previous response's next_cursor |
page_size |
integer | 100 | Items per page |
force |
boolean | false | Bypass output size warning |
analyze_directory
Walks a directory tree, counts lines of code, functions, and classes per file. Respects .gitignore rules.
Required: path (string) -- directory to analyze
Additional optional: max_depth (integer, default unlimited) -- recursion limit; use 2-3 for large monorepos
Example output:
src/ [328 LOC | F:28 C:5]
main.rs [18 LOC | F:1 C:0]
lib.rs [156 LOC | F:12 C:3]
parser.rs [89 LOC | F:8 C:2]
formatter.rs [65 LOC | F:7 C:0]
languages/ [142 LOC | F:19 C:5]
mod.rs [45 LOC | F:5 C:2]
rust.rs [97 LOC | F:14 C:3]
Total: 4 files, 328 LOC, 28 functions, 5 classes
analyze_file
Extracts functions, classes, imports, and type references from a single file.
Required: path (string) -- file to analyze
Additional optional: ast_recursion_limit (integer, default 256) -- tree-sitter recursion cap for stack safety
Example output:
FILE: src/lib.rs [156 LOC | F:12 C:3]
CLASSES:
CodeAnalyzer:20
SemanticExtractor:45
FUNCTIONS:
new:27
analyze:35
extract:52
format_content:78
build_index:89
IMPORTS:
rmcp (3)
serde (2)
tree_sitter (4)
thiserror (1)
REFERENCES:
methods: [analyze, extract, format_content]
types: [AnalysisResult, SemanticData, ParseError]
fields: [path, mode, language]
analyze_symbol
Builds a call graph for a named symbol across all files in a directory. Uses sentinel values <module> (top-level calls) and <reference> (type references). Functions called >3 times show (•N) notation.
Required:
path(string) -- directory to searchsymbol(string) -- symbol name, case-sensitive exact-match
Additional optional:
follow_depth(integer, default 1) -- call graph traversal depthmax_depth(integer, default unlimited) -- directory recursion limitast_recursion_limit(integer, default 256) -- tree-sitter recursion cap for stack safety
Example output:
FOCUS: analyze
DEPTH: 2
FILES: 12 analyzed
DEFINED:
src/lib.rs:35
CALLERS (incoming):
main -> analyze [src/main.rs:12]
<module> -> analyze [src/lib.rs:40]
process_request -> analyze [src/handler.rs:88]
CALLEES (outgoing):
analyze -> determine_mode [src/analyze.rs:44]
analyze -> format_output [src/formatter.rs:12] (•2)
analyze -> validate_params [src/validation.rs:5]
determine_mode -> is_directory [src/utils.rs:23]
Output Management
For large codebases, two 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.
# Response ends with:
NEXT_CURSOR: eyJvZmZzZXQiOjUwfQ==
# Fetch next page:
analyze_symbol path: /my/project symbol: my_function cursor: eyJvZmZzZXQiOjUwfQ==
Summary Mode
When output exceeds 50K chars, the server auto-compacts results using aggregate statistics. Override with summary: true (force compact) or summary: false (disable).
# Force summary for large project
# Disable summary (get full details, may be large)
Supported Languages
| Language | Extensions | Status |
|---|---|---|
| Rust | .rs |
Implemented |
| Python | .py |
Implemented |
| TypeScript | .ts, .tsx |
Implemented |
| Go | .go |
Implemented |
| Java | .java |
Implemented |
Documentation
- ARCHITECTURE.md - Design goals, module map, data flow, language handler system, caching strategy
- CONTRIBUTING.md - Development workflow, commit conventions, PR checklist
- SECURITY.md - Security policy and vulnerability reporting
License
Apache-2.0. See LICENSE for details.