rust-analyzer-db 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. rust_analyzer_db-0.2.0/.github/workflows/workflow.yml +45 -0
  2. rust_analyzer_db-0.2.0/.gitignore +12 -0
  3. rust_analyzer_db-0.2.0/AGENTS.md +38 -0
  4. rust_analyzer_db-0.2.0/LICENSE +201 -0
  5. rust_analyzer_db-0.2.0/PKG-INFO +302 -0
  6. rust_analyzer_db-0.2.0/README.md +267 -0
  7. rust_analyzer_db-0.2.0/opencode.jsonc +25 -0
  8. rust_analyzer_db-0.2.0/pyproject.toml +71 -0
  9. rust_analyzer_db-0.2.0/requirements.txt +6 -0
  10. rust_analyzer_db-0.2.0/rust_analyzer/__init__.py +1 -0
  11. rust_analyzer_db-0.2.0/rust_analyzer/cli.py +663 -0
  12. rust_analyzer_db-0.2.0/rust_analyzer/db.py +596 -0
  13. rust_analyzer_db-0.2.0/rust_analyzer/exceptions.py +41 -0
  14. rust_analyzer_db-0.2.0/rust_analyzer/extractor.py +640 -0
  15. rust_analyzer_db-0.2.0/rust_analyzer/graph.py +297 -0
  16. rust_analyzer_db-0.2.0/rust_analyzer/logging.py +52 -0
  17. rust_analyzer_db-0.2.0/rust_analyzer/mcp_server.py +516 -0
  18. rust_analyzer_db-0.2.0/rust_analyzer/static/style.css +573 -0
  19. rust_analyzer_db-0.2.0/rust_analyzer/static/vis-network.min.js +34 -0
  20. rust_analyzer_db-0.2.0/rust_analyzer/templates/api_surface.html +85 -0
  21. rust_analyzer_db-0.2.0/rust_analyzer/templates/base.html +82 -0
  22. rust_analyzer_db-0.2.0/rust_analyzer/templates/complexity.html +108 -0
  23. rust_analyzer_db-0.2.0/rust_analyzer/templates/dashboard.html +170 -0
  24. rust_analyzer_db-0.2.0/rust_analyzer/templates/deps.html +63 -0
  25. rust_analyzer_db-0.2.0/rust_analyzer/templates/graph.html +99 -0
  26. rust_analyzer_db-0.2.0/rust_analyzer/templates/items.html +117 -0
  27. rust_analyzer_db-0.2.0/rust_analyzer/templates/search.html +91 -0
  28. rust_analyzer_db-0.2.0/rust_analyzer/web.py +392 -0
  29. rust_analyzer_db-0.2.0/shell.nix +14 -0
  30. rust_analyzer_db-0.2.0/tests/__init__.py +0 -0
  31. rust_analyzer_db-0.2.0/tests/test_cli.py +242 -0
  32. rust_analyzer_db-0.2.0/tests/test_db.py +331 -0
  33. rust_analyzer_db-0.2.0/tests/test_exceptions.py +45 -0
  34. rust_analyzer_db-0.2.0/tests/test_extractor.py +304 -0
  35. rust_analyzer_db-0.2.0/tests/test_graph.py +106 -0
  36. rust_analyzer_db-0.2.0/tests/test_mcp.py +267 -0
  37. rust_analyzer_db-0.2.0/tests/test_web.py +192 -0
@@ -0,0 +1,45 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ id-token: write # Required for PyPI trusted publishing
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Set up Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.12"
20
+
21
+ - name: Install build tools
22
+ run: pip install build
23
+
24
+ - name: Build package
25
+ run: python -m build
26
+
27
+ - name: Upload artifacts
28
+ uses: actions/upload-artifact@v4
29
+ with:
30
+ name: dist
31
+ path: dist/
32
+
33
+ publish:
34
+ needs: build
35
+ runs-on: ubuntu-latest
36
+ environment: pypi
37
+ steps:
38
+ - name: Download artifacts
39
+ uses: actions/download-artifact@v4
40
+ with:
41
+ name: dist
42
+ path: dist/
43
+
44
+ - name: Publish to PyPI
45
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.egg-info/
6
+ dist/
7
+ build/
8
+ *.db
9
+ .code-review-graph/
10
+ .mypy_cache/
11
+ .pytest_cache/
12
+ .ruff_cache/
@@ -0,0 +1,38 @@
1
+ <!-- code-review-graph MCP tools -->
2
+ ## MCP Tools: code-review-graph
3
+
4
+ **IMPORTANT: This project has a knowledge graph. ALWAYS use the
5
+ code-review-graph MCP tools BEFORE using Grep/Glob/Read to explore
6
+ the codebase.** The graph is faster, cheaper (fewer tokens), and gives
7
+ you structural context (callers, dependents, test coverage) that file
8
+ scanning cannot.
9
+
10
+ ### When to use graph tools FIRST
11
+
12
+ - **Exploring code**: `semantic_search_nodes_tool` or `query_graph_tool` instead of Grep
13
+ - **Understanding impact**: `get_impact_radius_tool` instead of manually tracing imports
14
+ - **Code review**: `detect_changes_tool` + `get_review_context_tool` instead of reading entire files
15
+ - **Finding relationships**: `query_graph_tool` with callers_of/callees_of/imports_of/tests_for
16
+ - **Architecture questions**: `get_architecture_overview_tool` + `list_communities_tool`
17
+
18
+ Fall back to Grep/Glob/Read **only** when the graph doesn't cover what you need.
19
+
20
+ ### Key Tools
21
+
22
+ | Tool | Use when |
23
+ | ------ | ---------- |
24
+ | `detect_changes_tool` | Reviewing code changes — gives risk-scored analysis |
25
+ | `get_review_context_tool` | Need source snippets for review — token-efficient |
26
+ | `get_impact_radius_tool` | Understanding blast radius of a change |
27
+ | `get_affected_flows_tool` | Finding which execution paths are impacted |
28
+ | `query_graph_tool` | Tracing callers, callees, imports, tests, dependencies |
29
+ | `semantic_search_nodes_tool` | Finding functions/classes by name or keyword |
30
+ | `get_architecture_overview_tool` | Understanding high-level codebase structure |
31
+ | `refactor_tool` | Planning renames, finding dead code |
32
+
33
+ ### Workflow
34
+
35
+ 1. The graph auto-updates on file changes (via hooks).
36
+ 2. Use `detect_changes_tool` for code review.
37
+ 3. Use `get_affected_flows_tool` to understand impact.
38
+ 4. Use `query_graph_tool` pattern="tests_for" to check coverage.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,302 @@
1
+ Metadata-Version: 2.4
2
+ Name: rust-analyzer-db
3
+ Version: 0.2.0
4
+ Summary: Professional Rust code analysis tool using tree-sitter — extracts, indexes, and analyzes Rust source code with call graphs, complexity metrics, and dependency tracking.
5
+ Project-URL: Repository, https://github.com/jihoo12/rustanalyser
6
+ Author: codeanalyser
7
+ License-Expression: Apache-2.0
8
+ License-File: LICENSE
9
+ Keywords: analysis,call-graph,code-analysis,rust,tree-sitter
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Compilers
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: fastapi>=0.100
23
+ Requires-Dist: jinja2>=3.1
24
+ Requires-Dist: mcp<2,>=1.0
25
+ Requires-Dist: python-multipart>=0.0.6
26
+ Requires-Dist: tree-sitter-rust>=0.24
27
+ Requires-Dist: tree-sitter>=0.23
28
+ Requires-Dist: uvicorn>=0.23
29
+ Provides-Extra: dev
30
+ Requires-Dist: mypy>=1.0; extra == 'dev'
31
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
32
+ Requires-Dist: pytest>=7.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.4; extra == 'dev'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # rust-analyzer-db
37
+
38
+ A professional Python tool that uses **tree-sitter** to parse Rust source code,
39
+ extracts code entities, computes static metrics, and stores everything in a
40
+ **SQLite** database for query, search, call-graph analysis, and reporting.
41
+
42
+ ## Features
43
+
44
+ - **Full extraction**: structs, enums, traits, impls, functions/methods, consts,
45
+ statics, mods, macros, type aliases, unions, `use` declarations, `extern crate`
46
+ - **Static metrics**: cyclomatic complexity, cognitive complexity, nesting depth,
47
+ branch count, lines of code per function
48
+ - **Generic parameters & lifetimes**: extracted from structs, functions, impls
49
+ - **Call graph**: whole-project or focused subgraph with Graphviz DOT/SVG/PNG/HTML
50
+ rendering and interactive vis-network visualization
51
+ - **Public API surface**: identify all public items in a project
52
+ - **Dependency tracking**: `use` declarations and `extern crate` declarations
53
+ - **Complexity report**: find the most complex functions in your codebase
54
+ - **Full-text search**: SQLite FTS5 over name, signature, doc, and source
55
+ - **JSON output**: all commands support `--json` for machine-readable output
56
+ - **Incremental scanning**: unchanged files skipped by content hash
57
+ - **Structured logging**: configurable verbosity and format
58
+ - **Web frontend**: master-panel dashboard with interactive call graph, complexity
59
+ report, API surface, dependency analysis, and search
60
+ - **MCP server**: expose all analysis tools via Model Context Protocol for
61
+ AI assistants (Claude Code, Claude Desktop, etc.)
62
+
63
+ ## Install
64
+
65
+ ```bash
66
+ pip install -e ".[dev]"
67
+ ```
68
+
69
+ Or with just dependencies:
70
+
71
+ ```bash
72
+ pip install tree-sitter tree-sitter-rust fastapi uvicorn jinja2 python-multipart "mcp>=1.0,<2"
73
+ ```
74
+
75
+ Python 3.10+ required.
76
+
77
+ ## Usage
78
+
79
+ ### 1. Scan a project
80
+
81
+ ```bash
82
+ rust-analyzer-db scan /path/to/rust/project --db rust_code.db
83
+ ```
84
+
85
+ - Recursively finds all `*.rs` files (skips `target/`, `.git/`, `node_modules/`)
86
+ - Works on a single file: `rust-analyzer-db scan src/lib.rs`
87
+ - Re-running is **incremental** (unchanged files skipped)
88
+ - Use `--force` to re-parse everything, `-q` to suppress progress
89
+
90
+ ### 2. List items
91
+
92
+ ```bash
93
+ rust-analyzer-db list --kind struct --db rust_code.db
94
+ rust-analyzer-db list --kind function --name parse --db rust_code.db
95
+ rust-analyzer-db list --json --db rust_code.db
96
+ ```
97
+
98
+ ### 3. Show full source
99
+
100
+ ```bash
101
+ rust-analyzer-db show new --db rust_code.db --kind method
102
+ ```
103
+
104
+ ### 4. List methods on a type
105
+
106
+ ```bash
107
+ rust-analyzer-db methods Point --db rust_code.db --full
108
+ ```
109
+
110
+ ### 5. Full-text search
111
+
112
+ ```bash
113
+ rust-analyzer-db search "distance" --db rust_code.db
114
+ rust-analyzer-db search "parse OR tokenize" --db rust_code.db --full
115
+ ```
116
+
117
+ ### 6. Project statistics
118
+
119
+ ```bash
120
+ rust-analyzer-db stats --db rust_code.db
121
+ rust-analyzer-db stats --json --db rust_code.db
122
+ ```
123
+
124
+ ### 7. Complexity report
125
+
126
+ ```bash
127
+ rust-analyzer-db complexity --db rust_code.db
128
+ rust-analyzer-db complexity --min 10 --db rust_code.db
129
+ ```
130
+
131
+ Shows cyclomatic complexity, cognitive complexity, nesting depth, and LOC
132
+ for every function/method above the threshold.
133
+
134
+ ### 8. Public API surface
135
+
136
+ ```bash
137
+ rust-analyzer-db api --db rust_code.db
138
+ rust-analyzer-db api --json --db rust_code.db
139
+ ```
140
+
141
+ Lists all `pub` items grouped by kind.
142
+
143
+ ### 9. Dependency analysis
144
+
145
+ ```bash
146
+ rust-analyzer-db deps --db rust_code.db
147
+ rust-analyzer-db deps --full --db rust_code.db # show all use paths
148
+ ```
149
+
150
+ ### 10. Call graph
151
+
152
+ ```bash
153
+ # Whole project
154
+ rust-analyzer-db graph --db rust_code.db -o callgraph.svg
155
+
156
+ # Focused on one function
157
+ rust-analyzer-db graph --db rust_code.db --root run_demo --depth 3 -o run_demo.svg
158
+
159
+ # JSON output
160
+ rust-analyzer-db graph --db rust_code.db --json
161
+ ```
162
+
163
+ Flags: `--direction callees|callers|both`, `--no-unresolved`,
164
+ `--format svg|png|pdf|dot|html`.
165
+
166
+ ### 11. Web frontend
167
+
168
+ ```bash
169
+ # Start the web UI (default: http://localhost:8000)
170
+ rust-analyzer-db serve --db rust_code.db
171
+
172
+ # Custom host/port
173
+ rust-analyzer-db serve --db rust_code.db --host 0.0.0.0 --port 8080
174
+ ```
175
+
176
+ The web frontend provides a master-panel style dashboard with:
177
+
178
+ - **Dashboard** — project stats, top complex functions, item kind distribution,
179
+ complexity histogram, largest files
180
+ - **Items** — filterable/sortable/paginated browser for all extracted code
181
+ entities, with source view modals
182
+ - **Complexity** — ranked complexity report with adjustable threshold and
183
+ progress-bar indicators
184
+ - **Call graph** — interactive vis-network visualization with root/depth/direction
185
+ controls
186
+ - **API surface** — public items grouped by kind
187
+ - **Dependencies** — extern crates and `use` declaration tree
188
+ - **Search** — full-text search across names, signatures, docs, and source
189
+
190
+ All pages also expose JSON endpoints at `/api/stats`, `/api/item/{id}`,
191
+ and `/api/graph-data`.
192
+
193
+ ### 12. MCP server (Model Context Protocol)
194
+
195
+ ```bash
196
+ # Start the MCP server over stdio (for AI assistants)
197
+ rust-analyzer-db mcp --db rust_code.db
198
+ ```
199
+
200
+ Exposes Rust code analysis as **MCP tools** that AI assistants can call
201
+ via the [Model Context Protocol](https://modelcontextprotocol.io).
202
+
203
+ **Available tools:**
204
+
205
+ | Tool | Description |
206
+ |------|-------------|
207
+ | `scan_project` | Scan a Rust directory/file into the database |
208
+ | `list_items` | List code items with filters (kind, name, target, file) |
209
+ | `get_item` | Get full source and metadata for an item by ID |
210
+ | `search_code` | Full-text search across names, signatures, docs, source |
211
+ | `get_stats` | Project statistics (files, items, call edges) |
212
+ | `complexity_report` | Find complex functions above a threshold |
213
+ | `api_surface` | List all public API items |
214
+ | `dependencies` | Show extern crates and use declarations |
215
+ | `call_graph_info` | Trace callers/callees for a function, or project stats |
216
+ | `methods_of` | List methods on a type or trait |
217
+
218
+ **Register with Claude Code:**
219
+
220
+ ```bash
221
+ claude mcp add rust-analyzer-db -- rust-analyzer-db mcp --db /path/to/rust_code.db
222
+ ```
223
+
224
+ **Register with Claude Desktop** — add to `claude_desktop_config.json`:
225
+
226
+ ```json
227
+ {
228
+ "mcpServers": {
229
+ "rust-analyzer-db": {
230
+ "command": "rust-analyzer-db",
231
+ "args": ["mcp", "--db", "/path/to/rust_code.db"]
232
+ }
233
+ }
234
+ }
235
+ ```
236
+
237
+ ## What gets captured per item
238
+
239
+ - `kind`, `name`, `visibility`, `target`, `trait_name`
240
+ - `signature` (functions/methods, without body)
241
+ - `doc` (doc comments), `attributes` (`#[derive(...)]` etc.)
242
+ - `start_line` / `end_line`, `file_path`
243
+ - `source` — exact original source text
244
+ - `is_pub`, `is_const_fn`, `is_async`, `is_unsafe`
245
+ - `cyclomatic_complexity`, `cognitive_complexity`, `nesting_depth`,
246
+ `num_branches`, `num_function_calls`, `lines_of_code`
247
+ - Generic parameters and lifetime parameters
248
+ - Methods linked to parent impl/trait via `parent_id`
249
+
250
+ ## Database schema
251
+
252
+ Two main tables (`files`, `items`) plus `calls`, `use_declarations`,
253
+ `extern_crates`, `generic_params`, `lifetime_params`, and `items_fts`
254
+ (FTS5 index). See `rust_analyzer/db.py` for the full schema.
255
+
256
+ Query directly:
257
+
258
+ ```bash
259
+ sqlite3 rust_code.db "SELECT kind, name, cyclomatic_complexity FROM items WHERE cyclomatic_complexity > 5;"
260
+ ```
261
+
262
+ ## Development
263
+
264
+ ```bash
265
+ # Install dev dependencies
266
+ pip install -e ".[dev]"
267
+
268
+ # Run tests
269
+ pytest tests/ -v
270
+
271
+ # Type checking
272
+ mypy rust_analyzer/
273
+
274
+ # Linting
275
+ ruff check rust_analyzer/
276
+ ```
277
+
278
+ ## Architecture
279
+
280
+ ```
281
+ rust_analyzer/
282
+ __init__.py - Package version
283
+ cli.py - CLI commands and argument parsing
284
+ db.py - SQLite storage layer (schema + queries)
285
+ extractor.py - tree-sitter extraction + metrics
286
+ graph.py - Call graph construction + rendering
287
+ web.py - FastAPI web frontend + JSON API
288
+ mcp_server.py - MCP server (Model Context Protocol tools)
289
+ exceptions.py - Exception hierarchy
290
+ logging.py - Structured logging configuration
291
+ static/
292
+ style.css - Dark master-panel theme
293
+ templates/
294
+ base.html - Shared layout with sidebar navigation
295
+ dashboard.html - Stats cards + charts
296
+ items.html - Filterable item browser
297
+ complexity.html - Complexity report
298
+ graph.html - Interactive vis-network call graph
299
+ api_surface.html - Public API grouped by kind
300
+ deps.html - Dependencies tree
301
+ search.html - Full-text search
302
+ ```