loctree-mcp
Structural code intelligence for AI agents. Scan once, query everything — dead exports, circular imports, dependency graphs, and more. CLI + MCP server.
README
<p align="center"> <img src="https://loct.io/assets/loctree-logo.png" width="128" alt="loctree logo"/> </p>
<h1 align="center">loctree</h1>
<p align="center"> <strong>Scan once, query everything.</strong><br/> AI-oriented static analysis for dead exports, circular imports, dependency graphs, and holographic context slices. </p>
<p align="center"> <a href="https://crates.io/crates/loctree"><img src="https://img.shields.io/crates/v/loctree.svg" alt="crates.io"/></a> <a href="https://crates.io/crates/loctree"><img src="https://img.shields.io/crates/d/loctree.svg" alt="downloads"/></a> <a href="https://docs.rs/loctree"><img src="https://docs.rs/loctree/badge.svg" alt="docs.rs"/></a> <a href="https://github.com/Loctree/loctree-ast/actions/workflows/ci.yml"><img src="https://github.com/Loctree/loctree-ast/actions/workflows/ci.yml/badge.svg" alt="CI"/></a> <a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT%20OR%20Apache--2.0-blue.svg" alt="License"/></a> </p>
Install
curl -fsSL https://loct.io/install.sh | sh # CLI + loctree-mcp
cargo install --locked loctree loctree-mcp # Cargo, reproducible
npm install -g loctree # CLI only; published targets follow the latest npm release
brew install loctree/cli/loct # CLI via Homebrew tap
brew install loctree/mcp/loctree-mcp # MCP via Homebrew tap
Public install channels track the latest published release, which can lag behind
the workspace version on main. If you're validating a specific release, check
crates.io, npm, or GitHub Releases rather than assuming branch parity.
Quick Start
Artifacts are stored in your OS cache dir by default (override via LOCT_CACHE_DIR).
loct is the canonical CLI command. loctree remains available as a quiet compatibility alias.
loct # Scan project, write cached artifacts
loct --for-ai # AI-optimized overview (health, hubs, quick wins)
loct slice src/App.tsx --consumers # Context: file + deps + consumers
loct find useAuth # Find symbol definitions
loct find 'Snapshot FileAnalysis' # Cross-match: where terms meet
loct impact src/utils/api.ts # What breaks if you change this?
loct health # Quick summary: cycles + dead + twins
loct dead --confidence high # Unused exports
loct cycles # Circular imports
loct twins # Dead parrots + duplicates + barrel chaos
loct audit # Full codebase review
What It Does
loctree captures your project's real dependency graph in a single scan, then answers structural questions instantly from the snapshot. Designed for AI agents that need focused context without reading every file.
Core capabilities:
- Holographic Slice - extract file + dependencies + consumers in one call
- Cross-Match Search - find where multiple terms co-occur (not flat grep)
- Dead Export Detection - find unused exports across JS/TS, Python, Rust, Go, Dart
- Circular Import Detection - Tarjan's SCC algorithm catches runtime bombs
- Handler Tracing - follow Tauri commands through the entire FE/BE pipeline
- Impact Analysis - see what breaks before you delete or refactor
- jq Queries - query snapshot data with jq syntax (
loct '.files | length')
Why loctree
| grep/rg | LSP | loctree | |
|---|---|---|---|
| Knows imports vs definitions | No | Per-file | Whole graph |
| Dead export detection | No | No | Yes (multi-lang) |
| Cross-file impact analysis | No | Limited | Full transitive |
| AI agent integration | No | No | MCP server + --for-ai |
| Speed on 1M LOC repo | Fast (text) | Slow (indexing) | ~3s (structural) |
| Setup | None | Per-editor | One binary |
MCP Server
loctree ships as an MCP server for seamless AI agent integration:
loctree-mcp # Start via stdio (configure in your MCP client)
7 tools: repo-view, slice, find, impact, focus, tree, follow. Each tool accepts a project parameter — auto-scans on first use, caches snapshots in RAM. Project-agnostic: analyze any repo without configuration.
{
"mcpServers": {
"loctree": {
"command": "loctree-mcp",
"args": []
}
}
}
Direct download users can also fetch signed release assets from the monorepo
GitHub release page, which mirrors both the CLI and loctree-mcp tarballs.
Language Support
| Language | Dead Export Accuracy | Notes |
|---|---|---|
| Rust | ~0% FP | Tested on rust-lang/rust (35K files) |
| Go | ~0% FP | Tested on golang/go (17K files) |
| TypeScript/JavaScript | ~10-20% FP | JSX/TSX, React patterns, Flow, WeakMap |
| Python | ~20% FP | Library mode, __all__, stdlib detection |
| Svelte | <15% FP | Template analysis, .d.ts re-exports |
| Vue | ~15% FP | SFC support, Composition & Options API |
| Dart/Flutter | Full | pubspec.yaml detection |
Auto-detects stack from Cargo.toml, tsconfig.json, pyproject.toml, pubspec.yaml, src-tauri/.
Holographic Slice
Extract 3-layer context for any file:
loct slice src/App.tsx --consumers
Slice for: src/App.tsx
Core (1 files, 150 LOC):
src/App.tsx (150 LOC, ts)
Deps (3 files, 420 LOC):
[d1] src/hooks/useAuth.ts (80 LOC)
[d2] src/contexts/AuthContext.tsx (200 LOC)
[d2] src/utils/api.ts (140 LOC)
Consumers (2 files, 180 LOC):
src/main.tsx (30 LOC)
src/routes/index.tsx (150 LOC)
Total: 6 files, 750 LOC
Cross-Match Search
Multi-term queries show where terms meet, not flat OR:
loct find 'Snapshot FileAnalysis'
=== Cross-Match Files (9) ===
src/snapshot.rs: Snapshot(6), FileAnalysis(4)
src/slicer.rs: Snapshot(2), FileAnalysis(3)
...
=== Symbol Matches (222 in cross-match files) ===
src/snapshot.rs:20 - Snapshot [struct]
src/types.rs:15 - FileAnalysis [struct]
...
=== Parameter Matches (4 cross-matched) ===
src/slicer.rs:45 - snapshot: &Snapshot in build_slice(analyses: &[FileAnalysis])
jq Queries
Query snapshot data directly:
loct '.dead_parrots' # Dead code findings
loct '.files | length' # Count files
loct '.edges[] | select(.from | contains("api"))' # Filter edges
loct '.summary.health_score' # Health score
CI Integration
loct lint --fail --sarif > results.sarif # SARIF for GitHub/GitLab
loct findings | jq '.dead_exports.total' # Check dead export count
loct findings --summary | jq '.health_score' # Health summary JSON
Crates
| Crate | Description |
|---|---|
loctree |
Core analyzer + CLI (loct, loctree) |
report-leptos |
HTML report renderer (Leptos SSR) |
loctree-mcp |
MCP server for AI agents |
Development
make precheck # fmt + clippy + check (run before push)
make install # Install loct, loctree, loctree-mcp
make test # Run all workspace tests
make publish # Cascade publish to crates.io
Badge
[](https://crates.io/crates/loctree)
License
MIT OR Apache-2.0. See LICENSE-MIT and LICENSE-APACHE.
𝚅𝚒𝚋𝚎𝚌𝚛𝚊𝚏𝚝𝚎𝚍. with AI Agents ⓒ 2025-2026 Loctree Team
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。