loctree-mcp
Official安装
curl -fsSL https://loct.io/install.sh | sh # One-liner (installs from crates.io)或者直接通过 Cargo 安装:
cargo install loctree # CLI: loct, loctree
cargo install loctree-mcp # MCP server for AI agentsRelated MCP server: MCP Codebase Server
快速开始
工件默认存储在您的操作系统缓存目录中(可通过 LOCT_CACHE_DIR 覆盖)。
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功能特性
loctree 通过单次扫描捕获项目的真实依赖图,随后即可从快照中即时回答结构性问题。专为需要聚焦上下文而无需阅读每个文件的 AI 智能体而设计。
核心能力:
全息切片 (Holographic Slice) - 一次调用即可提取文件 + 依赖项 + 使用者
交叉匹配搜索 (Cross-Match Search) - 查找多个术语共同出现的位置(非简单的 grep)
死代码导出检测 (Dead Export Detection) - 查找 JS/TS、Python、Rust、Go、Dart 中未使用的导出
循环引用检测 (Circular Import Detection) - 使用 Tarjan 的 SCC 算法捕获运行时炸弹
处理程序追踪 (Handler Tracing) - 追踪 Tauri 命令在整个前端/后端管道中的流向
影响分析 (Impact Analysis) - 在删除或重构之前查看会产生什么影响
jq 查询 - 使用 jq 语法查询快照数据 (
loct '.files | length')
MCP 服务器
loctree 作为 MCP 服务器发布,可与 AI 智能体无缝集成:
loctree-mcp # Start via stdio (configure in your MCP client)工具:repo-view、slice、find、impact、focus、tree。每个工具都接受一个 project 参数——首次使用时自动扫描,并将快照缓存在内存中。
{
"mcpServers": {
"loctree": {
"command": "loctree-mcp",
"args": []
}
}
}语言支持
语言 | 死代码导出准确度 | 备注 |
Rust | ~0% FP | 在 rust-lang/rust (35K 文件) 上测试 |
Go | ~0% FP | 在 golang/go (17K 文件) 上测试 |
TypeScript/JavaScript | ~10-20% FP | JSX/TSX, React 模式, Flow, WeakMap |
Python | ~20% FP | 库模式, |
Svelte | <15% FP | 模板分析, .d.ts 重导出 |
Vue | ~15% FP | SFC 支持, Composition & Options API |
Dart/Flutter | 完全支持 | pubspec.yaml 检测 |
自动从 Cargo.toml、tsconfig.json、pyproject.toml、pubspec.yaml、src-tauri/ 检测技术栈。
全息切片
为任何文件提取 3 层上下文:
loct slice src/App.tsx --consumersSlice 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交叉匹配搜索
多术语查询显示术语相交的位置,而非简单的 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 查询
直接查询快照数据:
loct '.dead_parrots' # Dead code findings
loct '.files | length' # Count files
loct '.edges[] | select(.from | contains("api"))' # Filter edges
loct '.summary.health_score' # Health scoreCI 集成
loct lint --fail --sarif > results.sarif # SARIF for GitHub/GitLab
loct --findings | jq '.dead_parrots | length' # Check dead code count
loct doctor && echo 'Clean' # Health gateCrates
Crate | 描述 |
核心分析器 + CLI ( | |
HTML 报告渲染器 (Leptos SSR) | |
面向 AI 智能体的 MCP 服务器 |
开发
make precheck # fmt + clippy + check (run before push)
make install # Install loct + loctree-mcp
make test # Run all workspace tests
make publish # Cascade publish to crates.io徽章
[](https://crates.io/crates/loctree)许可证
MIT 或 Apache-2.0。请参阅 LICENSE-MIT 和 LICENSE-APACHE。
VibeCrafted with AI Agents (c)2026 Loctree Team
This server cannot be deployed
Maintenance
Related MCP Connectors
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
AI-powered codebase analysis — call graphs, security, dead code, complexity. 150+ tools.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server that indexes your codebase using tree-sitter AST parsing and gives AI tools instant access to structural intelligence like dependency graphs, call trees, and dead code detection from a local SQLite database.MIT
- AlicenseNot gradedqualityDmaintenanceMCP server for semantic codebase navigation that builds an AST index of symbols, imports, and exports, providing AI agents with tools to search, explore, and understand code.MIT
- AlicenseNot gradedqualityDmaintenanceA local-first codebase intelligence layer for AI coding agents, providing a persistent, queryable model of a repository via an MCP server and CLI to enable structure queries instead of reading many files.Apache 2.0
- AlicenseBqualityBmaintenanceIndexes a Python/JS/TS repository into a local SQLite knowledge graph so agents can trace callers, callees, imports, subclasses and covering tests, measure impact radius, rank diff risk, and summarize architecture without grepping files. Exposes these queries as MCP tools alongside an equivalent CLI, with no daemon, embeddings, or network access.10MIT