Professional Rust code analysis tool using tree-sitter — extracts, indexes, and analyzes Rust source code with call graphs, complexity metrics, and dependency tracking.
Project description
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 -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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rust_analyzer_db-0.2.0.tar.gz.
File metadata
- Download URL: rust_analyzer_db-0.2.0.tar.gz
- Upload date:
- Size: 215.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9d3b3ecd767c8abe419b72e5b2b98240ce1d4945e9311670652d6f9a0636be
|
|
| MD5 |
b18aaab2d537f06cca552ed80b279250
|
|
| BLAKE2b-256 |
7ad2a0cd45b5d5d406f403df3ddaebe6440779ab392d1b27ff714792e8be5ed0
|
Provenance
The following attestation bundles were made for rust_analyzer_db-0.2.0.tar.gz:
Publisher:
workflow.yml on jihoo12/rustanalyser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rust_analyzer_db-0.2.0.tar.gz -
Subject digest:
9b9d3b3ecd767c8abe419b72e5b2b98240ce1d4945e9311670652d6f9a0636be - Sigstore transparency entry: 2246458340
- Sigstore integration time:
-
Permalink:
jihoo12/rustanalyser@96196ebdb047396ceddd4d175688e907dd2e0c85 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jihoo12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@96196ebdb047396ceddd4d175688e907dd2e0c85 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rust_analyzer_db-0.2.0-py3-none-any.whl.
File metadata
- Download URL: rust_analyzer_db-0.2.0-py3-none-any.whl
- Upload date:
- Size: 216.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
51fcff37eab6d66ed288104898ad18e2e87bb0ba40b65316c8ec8b31033261e8
|
|
| MD5 |
177d5488786c94c1043cd9c768ced549
|
|
| BLAKE2b-256 |
ed6a39069b274e62b7da1b535e8b0059b3c764ecc3acd27c5e69fb8026cd2429
|
Provenance
The following attestation bundles were made for rust_analyzer_db-0.2.0-py3-none-any.whl:
Publisher:
workflow.yml on jihoo12/rustanalyser
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rust_analyzer_db-0.2.0-py3-none-any.whl -
Subject digest:
51fcff37eab6d66ed288104898ad18e2e87bb0ba40b65316c8ec8b31033261e8 - Sigstore transparency entry: 2246458748
- Sigstore integration time:
-
Permalink:
jihoo12/rustanalyser@96196ebdb047396ceddd4d175688e907dd2e0c85 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/jihoo12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@96196ebdb047396ceddd4d175688e907dd2e0c85 -
Trigger Event:
release
-
Statement type: