codecompass-mcp 2.0.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 (38) hide show
  1. codecompass_mcp-2.0.0/LICENSE +21 -0
  2. codecompass_mcp-2.0.0/PKG-INFO +368 -0
  3. codecompass_mcp-2.0.0/README.md +330 -0
  4. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/PKG-INFO +368 -0
  5. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/SOURCES.txt +36 -0
  6. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/dependency_links.txt +1 -0
  7. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/entry_points.txt +3 -0
  8. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/requires.txt +18 -0
  9. codecompass_mcp-2.0.0/codecompass_mcp.egg-info/top_level.txt +6 -0
  10. codecompass_mcp-2.0.0/config.py +16 -0
  11. codecompass_mcp-2.0.0/graph/__init__.py +0 -0
  12. codecompass_mcp-2.0.0/graph/cli.py +13 -0
  13. codecompass_mcp-2.0.0/graph/code_graph_client.py +485 -0
  14. codecompass_mcp-2.0.0/graph/code_query_cli.py +504 -0
  15. codecompass_mcp-2.0.0/graph/mcp_server.py +280 -0
  16. codecompass_mcp-2.0.0/graph/setup.py +255 -0
  17. codecompass_mcp-2.0.0/ingestion/__init__.py +0 -0
  18. codecompass_mcp-2.0.0/ingestion/chunker.py +70 -0
  19. codecompass_mcp-2.0.0/ingestion/code_normalizer.py +158 -0
  20. codecompass_mcp-2.0.0/ingestion/code_parser.py +709 -0
  21. codecompass_mcp-2.0.0/ingestion/entity_resolver.py +179 -0
  22. codecompass_mcp-2.0.0/ingestion/file_watcher.py +165 -0
  23. codecompass_mcp-2.0.0/ingestion/graph_writer.py +17 -0
  24. codecompass_mcp-2.0.0/ingestion/hierarchy_builder.py +148 -0
  25. codecompass_mcp-2.0.0/ingestion/reader_agent.py +135 -0
  26. codecompass_mcp-2.0.0/main.py +306 -0
  27. codecompass_mcp-2.0.0/models/__init__.py +0 -0
  28. codecompass_mcp-2.0.0/models/code_types.py +35 -0
  29. codecompass_mcp-2.0.0/models/types.py +45 -0
  30. codecompass_mcp-2.0.0/pyproject.toml +57 -0
  31. codecompass_mcp-2.0.0/setup.cfg +4 -0
  32. codecompass_mcp-2.0.0/tests/test_batch_impact.py +198 -0
  33. codecompass_mcp-2.0.0/tests/test_blast_radius.py +179 -0
  34. codecompass_mcp-2.0.0/tests/test_code_parser.py +121 -0
  35. codecompass_mcp-2.0.0/tests/test_ingestion.py +90 -0
  36. codecompass_mcp-2.0.0/tests/test_lit_css_parser.py +171 -0
  37. codecompass_mcp-2.0.0/utils/__init__.py +0 -0
  38. codecompass_mcp-2.0.0/utils/formatting.py +24 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mmkumar5401
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: codecompass-mcp
3
+ Version: 2.0.0
4
+ Summary: Structural code context for AI coding agents — MCP tools for blast radius, impact, deps, and more
5
+ Author: CodeCompass contributors
6
+ License: MIT
7
+ Keywords: ai,code-graph,mcp,llm,coding-agent,neo4j,tree-sitter
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Code Generators
16
+ Classifier: Topic :: Software Development :: Compilers
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: anthropic>=0.40.0
21
+ Requires-Dist: neo4j>=5.18.0
22
+ Requires-Dist: pypdf2>=3.0.0
23
+ Requires-Dist: python-dotenv>=1.0.0
24
+ Requires-Dist: rich>=13.0.0
25
+ Requires-Dist: tqdm>=4.66.0
26
+ Requires-Dist: tree-sitter>=0.21.0
27
+ Requires-Dist: tree-sitter-python>=0.21.0
28
+ Requires-Dist: tree-sitter-javascript>=0.21.0
29
+ Requires-Dist: tree-sitter-typescript>=0.21.0
30
+ Requires-Dist: tree-sitter-html>=0.21.0
31
+ Requires-Dist: tree-sitter-css>=0.21.0
32
+ Requires-Dist: watchdog>=4.0.0
33
+ Requires-Dist: mcp>=1.0.0
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ # CodeCompass — Code Intelligence Engine for AI Coding Agents
40
+
41
+ Full-indexes an average repository in seconds, a large monorepo in minutes. Answers structural queries in under 3 seconds — *"what should I read before editing X?"*
42
+
43
+ Neo4j-backed code dependency graph. Ingest once, then opencode's MCP tools (`blast_radius`, `impact`, `deps`, `trace`, `tree`, `styles`, `batch_impact`) tell the agent exactly which files to read — no blind exploration.
44
+
45
+ ---
46
+
47
+ ## What's new in v2.0
48
+
49
+ | Feature | Description |
50
+ |---|---|
51
+ | PyPI package | `pip install codecompass-mcp` — works with any MCP-compatible agent |
52
+ | MCP server | Code graph exposed as native opencode tools — `blast_radius`, `impact`, `deps`, `trace`, `tree`, `styles`, `batch_impact`, `list_projects` |
53
+ | opencode plugin | Session memory auto-saves on compaction + idle |
54
+ | One-command setup | `pip install` + `codecompass ingest-code` — no clone required |
55
+ | Auto-registration | `ingest-code` writes `AGENTS.md` (opencode convention) instead of `CLAUDE.md` |
56
+
57
+ ---
58
+
59
+ ## What it does
60
+
61
+ Once configured, opencode has 8 native MCP tools for graph queries. The agent calls them automatically — no manual CLI needed.
62
+
63
+ ```
64
+ Agent sees these tools in every session:
65
+ list_projects → "what repos are indexed?"
66
+ blast_radius → "what files will my change touch?"
67
+ impact → "what calls this function / uses this element?"
68
+ deps → "what does this file import?"
69
+ trace → "what's the forward call chain?"
70
+ tree → "show me the project structure"
71
+ styles → "what CSS targets this element?"
72
+ batch_impact → "union blast radius for a multi-file PR"
73
+ ```
74
+
75
+ Instructions (loaded via `opencode/instructions.md`) mandate: **always query the graph before editing code.**
76
+
77
+ ### When to use which tool
78
+
79
+ | Scenario | Tool |
80
+ |---|---|
81
+ | About to edit one file or symbol | `blast_radius` first |
82
+ | Planning a PR touching N files | `batch_impact` |
83
+ | Renaming or removing a function | `impact` |
84
+ | Understanding what a file imports | `deps` |
85
+ | Tracing a call chain forward | `trace` |
86
+ | Orienting in an unfamiliar project | `tree` |
87
+ | Finding which CSS uses a design token | `impact "token-name"` |
88
+
89
+ ---
90
+
91
+ ## Setup
92
+
93
+ ### Prerequisites
94
+
95
+ - Python 3.10+
96
+ - Neo4j (any of the options below)
97
+ - opencode CLI
98
+
99
+ ### 1. Install the package
100
+
101
+ ```bash
102
+ pip install codecompass-mcp
103
+ ```
104
+
105
+ ### 2. Start Neo4j
106
+
107
+ Pick one:
108
+
109
+ **Docker (fastest)**
110
+ ```bash
111
+ docker run -d --name neo4j -p 7474:7474 -p 7687:7687 \
112
+ -e NEO4J_AUTH=neo4j/password123 neo4j:5.18
113
+ ```
114
+
115
+ **Docker Compose** — clone the repo and run:
116
+ ```bash
117
+ git clone https://github.com/<owner>/codecompass.git
118
+ cd codecompass
119
+ docker compose up -d
120
+ ```
121
+
122
+ **Neo4j Desktop** — Download from [neo4j.com/download](https://neo4j.com/download)
123
+
124
+ **AuraDB (cloud)** — [neo4j.com/cloud/aura](https://neo4j.com/cloud/aura)
125
+
126
+ ### 3. Configure
127
+
128
+ ```bash
129
+ cp .env.example .env
130
+ # Set NEO4J_URI, NEO4J_USER, NEO4J_PASSWORD
131
+ # ANTHROPIC_API_KEY is optional — only needed for document ingestion
132
+ ```
133
+
134
+ ### 4. Ingest a codebase
135
+
136
+ ```bash
137
+ codecompass ingest-code /path/to/repo --project <name>
138
+ ```
139
+
140
+ This writes a `## Code graph` section into the project's `AGENTS.md` automatically.
141
+
142
+ ### 5. Register with opencode
143
+
144
+ Run the setup wizard — it writes instructions, the memory plugin, helper scripts, and prints the config block:
145
+
146
+ ```bash
147
+ codecompass setup
148
+ ```
149
+
150
+ This outputs JSON to merge into `~/.config/opencode/opencode.json`. The resulting config:
151
+
152
+ ```json
153
+ {
154
+ "instructions": ["~/.config/opencode/codecompass/instructions.md"],
155
+ "mcp": {
156
+ "codecompass": {
157
+ "type": "local",
158
+ "command": ["codecompass-mcp"]
159
+ }
160
+ },
161
+ "plugin": ["~/.config/opencode/codecompass/plugins/memory.ts"]
162
+ }
163
+ ```
164
+
165
+ All files are self-contained in `~/.config/opencode/codecompass/` — no repo clone needed.
166
+
167
+ ### 6. Open opencode
168
+
169
+ ```bash
170
+ opencode
171
+ ```
172
+
173
+ Ask "what ingested projects are available?" — it should use `list_projects` to answer.
174
+
175
+ ### Docker (alternative)
176
+
177
+ Prefer everything containerized? Pull the pre-built image:
178
+
179
+ ```bash
180
+ docker pull ghcr.io/<owner>/codecompass:latest
181
+ docker run -d -p 8000:8000 \
182
+ -e NEO4J_URI=bolt://<host>:7687 \
183
+ -e NEO4J_USER=neo4j \
184
+ -e NEO4J_PASSWORD=password123 \
185
+ ghcr.io/<owner>/codecompass:latest
186
+ ```
187
+
188
+ Then configure opencode with `"type": "http", "url": "http://localhost:8000/sse"` for the MCP server. Run `codecompass setup` for instructions + plugin files.
189
+
190
+ ---
191
+
192
+ ## Commands
193
+
194
+ ### `ingest-code`
195
+
196
+ ```bash
197
+ codecompass ingest-code /path/to/repo --project <name>
198
+ codecompass ingest-code /path/to/repo --project <name> --normalize
199
+ codecompass ingest-code /path/to/repo --project <name> --dump-triples /tmp/raw.json
200
+ ```
201
+
202
+ ### `watch`
203
+
204
+ Keep the graph live as you edit files:
205
+
206
+ ```bash
207
+ codecompass watch /path/to/repo --project <name>
208
+ ```
209
+
210
+ Watches for file creates, modifies, deletes, and renames. Incrementally re-ingests only changed files. The query CLI warns if the watcher isn't running.
211
+
212
+ ### `load-triples`
213
+
214
+ Load pre-processed triples (e.g. after external normalization):
215
+
216
+ ```bash
217
+ codecompass load-triples /tmp/normalized.json --project <name>
218
+ ```
219
+
220
+ ### Direct CLI queries (bypassing the agent)
221
+
222
+ ```bash
223
+ python -m graph.code_query_cli --blast-radius path/to/file.py --project <project>
224
+ python -m graph.code_query_cli --impact "FunctionName" --project <project>
225
+ python -m graph.code_query_cli --tree <project>
226
+ ```
227
+
228
+ ---
229
+
230
+ ## Session lifecycle
231
+
232
+ ```
233
+ Open opencode (any directory)
234
+
235
+ MCP tools registered (blast_radius, impact, deps, ...) + instructions loaded
236
+
237
+ You ask questions / make edits
238
+
239
+ Agent queries graph via MCP tools before touching code
240
+
241
+ Compaction fires → plugin writes learnings to memory/learnings.md
242
+
243
+ Session idle → plugin logs metadata to memory/session_log.md
244
+ ```
245
+
246
+ ---
247
+
248
+ ## Common first-session tasks
249
+
250
+ ```
251
+ In opencode, just ask naturally — instructions guide the agent:
252
+
253
+ "what ingested projects are available?"
254
+ → agent calls list_projects()
255
+
256
+ "what would break if I rename write_code_triple?"
257
+ → agent calls impact("write_code_triple", "codecompass")
258
+
259
+ "I'm about to edit code_parser.py — what else is affected?"
260
+ → agent calls blast_radius("ingestion/code_parser.py", "codecompass")
261
+
262
+ "I'm changing these 3 files — full blast radius?"
263
+ → agent calls batch_impact("file1, file2, file3", "codecompass")
264
+
265
+ "show me the codecompass project structure"
266
+ → agent calls tree("codecompass")
267
+ ```
268
+
269
+ ---
270
+
271
+ ## How it works
272
+
273
+ ```
274
+ Source files
275
+
276
+
277
+ hierarchy_builder.py — walks repo, writes Project → Folder → File skeleton
278
+
279
+
280
+ code_parser.py — tree-sitter extraction (no API calls)
281
+ │ Python, JS, TS, TSX → CALLS, IMPORTS, INHERITS
282
+ │ CSS, SCSS → DEFINED_IN, USES_VAR, IMPORTS
283
+ │ HTML → REFERENCES, INCLUDES
284
+ │ .styles.ts (Lit) → secondary CSS pass on css`...` blocks
285
+ │ → USES_VAR + DEFINED_IN for design tokens
286
+
287
+ Neo4j — typed relationships: [:CALLS], [:IMPORTS],
288
+ [:INHERITS], [:STYLES], [:DEFINED_IN], [:USES_VAR], …
289
+
290
+
291
+ mcp_server.py — MCP server exposing 8 tools (blast_radius, impact,
292
+ deps, trace, tree, styles, batch_impact, list_projects)
293
+
294
+
295
+ opencode agent — calls MCP tools from any directory via instructions
296
+ ```
297
+
298
+ Typed relationships (not generic `RELATION {type: ...}`) mean variable-length path queries are index-scannable on Neo4j Community Edition.
299
+
300
+ ---
301
+
302
+ ## Project structure
303
+
304
+ ```
305
+ codecompass/
306
+ ├── graph/
307
+ │ ├── code_graph_client.py Neo4j I/O — nodes, edges, traversal queries
308
+ │ ├── code_query_cli.py CLI — blast-radius / batch-impact / deps /
309
+ │ │ impact / trace / styles / tree
310
+ │ └── mcp_server.py MCP server — exposes 8 tools to opencode
311
+ ├── ingestion/
312
+ │ ├── code_parser.py tree-sitter extraction + Lit css`...` pass
313
+ │ ├── hierarchy_builder.py Project → Folder → File skeleton
314
+ │ ├── file_watcher.py incremental updates on file change
315
+ │ └── code_normalizer.py optional Haiku normalization pass
316
+ ├── memory/
317
+ │ ├── decisions.md architectural decisions (append-only)
318
+ │ └── learnings.md session learnings (auto-saved by plugin)
319
+ ├── models/
320
+ │ └── code_types.py CodeTriple, FileNode, FolderNode
321
+ ├── opencode/
322
+ │ ├── config.template.json opencode config template (MCP + plugin + instructions)
323
+ │ ├── instructions.md graph-first query rules loaded into every session
324
+ │ ├── plugins/memory.ts session memory plugin (compaction + idle hooks)
325
+ │ └── scripts/ Python helpers called by the plugin
326
+ ├── config.py Neo4j config from .env
327
+ ├── main.py CLI: ingest-code / load-triples / watch
328
+ ├── install.sh one-command setup
329
+ └── docker-compose.yml Neo4j container
330
+ ```
331
+
332
+ ---
333
+
334
+ ## Automatic AGENTS.md registration
335
+
336
+ Every `ingest-code` run writes a `## Code graph` block into the target project's `AGENTS.md` (creating the file if it doesn't exist). The block is wrapped in HTML comment markers so re-ingesting safely updates it in place.
337
+
338
+ This means opencode automatically picks up the right `--project` name and query commands the next time a session opens in that directory — no manual setup.
339
+
340
+ ---
341
+
342
+ ## Troubleshooting
343
+
344
+ **`connection refused` on Neo4j**
345
+ Neo4j is not running. Start your DBMS or use `docker run -d neo4j`.
346
+
347
+ **`authentication failure` on Neo4j**
348
+ Password in `.env` doesn't match. Reset it in Neo4j Desktop or recreate the Docker container.
349
+
350
+ **`codecompass: command not found`**
351
+ Run `pip install codecompass-mcp` to install the CLI.
352
+
353
+ **MCP tools not appearing**
354
+ Run `opencode debug config` to verify the codecompass MCP server is registered. Restart opencode after config changes.
355
+
356
+ **`memory/learnings.md` is empty**
357
+ Learnings are saved when compaction fires during long sessions. The plugin writes entries automatically on compaction and idle events.
358
+
359
+ ---
360
+
361
+ ## Limitations
362
+
363
+ - Structure only — the graph knows what calls what, not what anything *means*
364
+ - Supported languages: Python, JS, TS, TSX, HTML, CSS, SCSS, `.styles.ts` (Lit)
365
+ - External callers (consumers outside the ingested repo) won't appear in `impact`
366
+ - Lit CSS extraction covers explicit `var(--foo)` usages and `:host { --foo: ... }` declarations; generated property names from `theme.props()` patterns are not yet indexed
367
+ - If Neo4j is down, the MCP server returns a clear error instead of a traceback
368
+ - The watcher (`codecompass watch`) is separate from the MCP server — keep it running for live re-indexing on file changes