rust-analyzer-db
A professional Python tool that uses tree-sitter to parse Rust source code, extracts code entities, computes static metrics, and stores everything in a SQLite database for query, search, call-graph analysis, and reporting.
Features
- Full extraction: structs, enums, traits, impls, functions/methods, consts,
statics, mods, macros, type aliases, unions,
usedeclarations,extern crate - Static metrics: cyclomatic complexity, cognitive complexity, nesting depth, branch count, lines of code per function
- Generic parameters & lifetimes: extracted from structs, functions, impls
- Call graph: whole-project or focused subgraph with Graphviz DOT/SVG/PNG/HTML rendering and interactive vis-network visualization
- Public API surface: identify all public items in a project
- Dependency tracking:
usedeclarations andextern cratedeclarations - Complexity report: find the most complex functions in your codebase
- Full-text search: SQLite FTS5 over name, signature, doc, and source
- JSON output: all commands support
--jsonfor machine-readable output - Incremental scanning: unchanged files skipped by content hash
- Structured logging: configurable verbosity and format
- Web frontend: master-panel dashboard with interactive call graph, complexity report, API surface, dependency analysis, and search
- MCP server: expose all analysis tools via Model Context Protocol for AI assistants (Claude Code, Claude Desktop, etc.)
Install
pip install rust-analyzer-db
pip install -e ".[dev]"
Or with just dependencies:
pip install tree-sitter tree-sitter-rust fastapi uvicorn jinja2 python-multipart "mcp>=1.0,<2"
Python 3.10+ required.
Usage
1. Scan a project
rust-analyzer-db scan /path/to/rust/project --db rust_code.db
- Recursively finds all
*.rsfiles (skipstarget/,.git/,node_modules/) - Works on a single file:
rust-analyzer-db scan src/lib.rs - Re-running is incremental (unchanged files skipped)
- Use
--forceto re-parse everything,-qto suppress progress
2. List items
rust-analyzer-db list --kind struct --db rust_code.db
rust-analyzer-db list --kind function --name parse --db rust_code.db
rust-analyzer-db list --json --db rust_code.db
3. Show full source
rust-analyzer-db show new --db rust_code.db --kind method
4. List methods on a type
rust-analyzer-db methods Point --db rust_code.db --full
5. Full-text search
rust-analyzer-db search "distance" --db rust_code.db
rust-analyzer-db search "parse OR tokenize" --db rust_code.db --full
6. Project statistics
rust-analyzer-db stats --db rust_code.db
rust-analyzer-db stats --json --db rust_code.db
7. Complexity report
rust-analyzer-db complexity --db rust_code.db
rust-analyzer-db complexity --min 10 --db rust_code.db
Shows cyclomatic complexity, cognitive complexity, nesting depth, and LOC for every function/method above the threshold.
8. Public API surface
rust-analyzer-db api --db rust_code.db
rust-analyzer-db api --json --db rust_code.db
Lists all pub items grouped by kind.
9. Dependency analysis
rust-analyzer-db deps --db rust_code.db
rust-analyzer-db deps --full --db rust_code.db # show all use paths
10. Call graph
# Whole project
rust-analyzer-db graph --db rust_code.db -o callgraph.svg
# Focused on one function
rust-analyzer-db graph --db rust_code.db --root run_demo --depth 3 -o run_demo.svg
# JSON output
rust-analyzer-db graph --db rust_code.db --json
Flags: --direction callees|callers|both, --no-unresolved,
--format svg|png|pdf|dot|html.
11. Web frontend
# Start the web UI (default: http://localhost:8000)
rust-analyzer-db serve --db rust_code.db
# Custom host/port
rust-analyzer-db serve --db rust_code.db --host 0.0.0.0 --port 8080
The web frontend provides a master-panel style dashboard with:
- Dashboard — project stats, top complex functions, item kind distribution, complexity histogram, largest files
- Items — filterable/sortable/paginated browser for all extracted code entities, with source view modals
- Complexity — ranked complexity report with adjustable threshold and progress-bar indicators
- Call graph — interactive vis-network visualization with root/depth/direction controls
- API surface — public items grouped by kind
- Dependencies — extern crates and
usedeclaration tree - Search — full-text search across names, signatures, docs, and source
All pages also expose JSON endpoints at /api/stats, /api/item/{id},
and /api/graph-data.
12. MCP server (Model Context Protocol)
# Start the MCP server over stdio (for AI assistants)
rust-analyzer-db mcp --db rust_code.db
Exposes Rust code analysis as MCP tools that AI assistants can call via the Model Context Protocol.
Available tools:
| Tool | Description |
|---|---|
scan_project |
Scan a Rust directory/file into the database |
list_items |
List code items with filters (kind, name, target, file) |
get_item |
Get full source and metadata for an item by ID |
search_code |
Full-text search across names, signatures, docs, source |
get_stats |
Project statistics (files, items, call edges) |
complexity_report |
Find complex functions above a threshold |
api_surface |
List all public API items |
dependencies |
Show extern crates and use declarations |
call_graph_info |
Trace callers/callees for a function, or project stats |
methods_of |
List methods on a type or trait |
Register with Claude Code:
claude mcp add rust-analyzer-db -- rust-analyzer-db mcp --db /path/to/rust_code.db
Register with Claude Desktop — add to claude_desktop_config.json:
{
"mcpServers": {
"rust-analyzer-db": {
"command": "rust-analyzer-db",
"args": ["mcp", "--db", "/path/to/rust_code.db"]
}
}
}
What gets captured per item
kind,name,visibility,target,trait_namesignature(functions/methods, without body)doc(doc comments),attributes(#[derive(...)]etc.)start_line/end_line,file_pathsource— exact original source textis_pub,is_const_fn,is_async,is_unsafecyclomatic_complexity,cognitive_complexity,nesting_depth,num_branches,num_function_calls,lines_of_code- Generic parameters and lifetime parameters
- Methods linked to parent impl/trait via
parent_id
Database schema
Two main tables (files, items) plus calls, use_declarations,
extern_crates, generic_params, lifetime_params, and items_fts
(FTS5 index). See rust_analyzer/db.py for the full schema.
Query directly:
sqlite3 rust_code.db "SELECT kind, name, cyclomatic_complexity FROM items WHERE cyclomatic_complexity > 5;"
Development
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Type checking
mypy rust_analyzer/
# Linting
ruff check rust_analyzer/
Architecture
rust_analyzer/
__init__.py - Package version
cli.py - CLI commands and argument parsing
db.py - SQLite storage layer (schema + queries)
extractor.py - tree-sitter extraction + metrics
graph.py - Call graph construction + rendering
web.py - FastAPI web frontend + JSON API
mcp_server.py - MCP server (Model Context Protocol tools)
exceptions.py - Exception hierarchy
logging.py - Structured logging configuration
static/
style.css - Dark master-panel theme
templates/
base.html - Shared layout with sidebar navigation
dashboard.html - Stats cards + charts
items.html - Filterable item browser
complexity.html - Complexity report
graph.html - Interactive vis-network call graph
api_surface.html - Public API grouped by kind
deps.html - Dependencies tree
search.html - Full-text search
Metadata
Release files for rust-analyzer-db 0.3.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rust_analyzer_db-0.3.3.tar.gz | 330.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rust_analyzer_db-0.3.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 552.7 kB
Release files / rust_analyzer_db-0.3.3.tar.gz
| Download URL | rust_analyzer_db-0.3.3.tar.gz |
|---|---|
| Size | 330.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cbade1769c387b650e20062282789c12a7a0a69f65979a701a979fbf0363911
|
|
BLAKE2b-256 checksum How to use checksums |
4c234bba6194a1573355fff25fab88e38d02bd58113bc0cc209a5ebf9e87007f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.
Transparency logRelease files / rust_analyzer_db-0.3.3-py3-none-any.whl
| Download URL | rust_analyzer_db-0.3.3-py3-none-any.whl |
|---|---|
| Size | 222.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a61c059c9707c1f2c26ca10103f13f8baff361d802d1098dd0a55761ce5ed2df
|
|
BLAKE2b-256 checksum How to use checksums |
77eb727ba20180b683c8839d6bf5ea696b5da5975479a79dfb10822c13c25435
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 25, 2026.
Transparency log