codegraph-engine 3.0.0__1-py3-none-any.whl
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.
- codegraph/__init__.py +37 -0
- codegraph/agent.py +26 -0
- codegraph/agent_brain.py +2212 -0
- codegraph/agent_capabilities.py +4058 -0
- codegraph/agent_rules.py +531 -0
- codegraph/api_drift.py +455 -0
- codegraph/architecture.py +371 -0
- codegraph/async_queue/__init__.py +50 -0
- codegraph/async_queue/detectors/__init__.py +48 -0
- codegraph/async_queue/detectors/celery.py +160 -0
- codegraph/async_queue/detectors/kafka.py +168 -0
- codegraph/async_queue/detectors/rabbitmq.py +116 -0
- codegraph/async_queue/detectors/redis.py +130 -0
- codegraph/async_queue/detectors/sqs.py +135 -0
- codegraph/async_queue/models.py +161 -0
- codegraph/async_queue/otel_models.py +74 -0
- codegraph/async_queue/otel_parser.py +337 -0
- codegraph/async_queue/reconciler.py +427 -0
- codegraph/async_queue/scanner.py +291 -0
- codegraph/async_queue/traversal.py +447 -0
- codegraph/audit.py +106 -0
- codegraph/binding_resolver.py +616 -0
- codegraph/branch_comparison.py +197 -0
- codegraph/cache.py +95 -0
- codegraph/change_impact.py +547 -0
- codegraph/cli.py +2436 -0
- codegraph/cli_output.py +205 -0
- codegraph/config.py +45 -0
- codegraph/constraints.py +238 -0
- codegraph/context.py +2182 -0
- codegraph/context_freshness.py +351 -0
- codegraph/database/__init__.py +72 -0
- codegraph/database/extractor.py +3651 -0
- codegraph/database/interrogation.py +1494 -0
- codegraph/database/models.py +310 -0
- codegraph/database/schema_drift.py +862 -0
- codegraph/epistemic.py +200 -0
- codegraph/errors.py +282 -0
- codegraph/evidence/__init__.py +15 -0
- codegraph/evidence/citations.py +418 -0
- codegraph/evidence_contract.py +486 -0
- codegraph/frameworks.py +960 -0
- codegraph/frameworks_nestjs.py +502 -0
- codegraph/frameworks_nextjs.py +337 -0
- codegraph/frameworks_react.py +457 -0
- codegraph/freshness.py +335 -0
- codegraph/frontend_html.py +109 -0
- codegraph/git.py +362 -0
- codegraph/git_state.py +545 -0
- codegraph/graph/__init__.py +46 -0
- codegraph/graph/models.py +56 -0
- codegraph/graph/traversal.py +1993 -0
- codegraph/indexing/__init__.py +24 -0
- codegraph/indexing/classifier.py +564 -0
- codegraph/indexing/indexer.py +2578 -0
- codegraph/indexing/models.py +427 -0
- codegraph/indexing/parser.py +3404 -0
- codegraph/indexing/pool.py +136 -0
- codegraph/indexing/scanner.py +211 -0
- codegraph/indexing/telemetry.py +326 -0
- codegraph/indexing/templates.py +418 -0
- codegraph/indexing/test_framework.py +116 -0
- codegraph/installer.py +1702 -0
- codegraph/interrogation.py +2355 -0
- codegraph/llm/__init__.py +3 -0
- codegraph/llm/base.py +15 -0
- codegraph/llm/context.py +20 -0
- codegraph/mcp/__init__.py +3 -0
- codegraph/mcp/server.py +1476 -0
- codegraph/mcp_diagnostics.py +882 -0
- codegraph/memory/__init__.py +3 -0
- codegraph/memory/store.py +46 -0
- codegraph/models.py +310 -0
- codegraph/monorepo.py +925 -0
- codegraph/observability.py +262 -0
- codegraph/optimizer.py +1014 -0
- codegraph/planner.py +417 -0
- codegraph/process_lifecycle.py +1153 -0
- codegraph/py.typed +1 -0
- codegraph/query_expansion.py +199 -0
- codegraph/ranking.py +408 -0
- codegraph/refactor/__init__.py +36 -0
- codegraph/refactor/models.py +114 -0
- codegraph/refactor/renamer.py +844 -0
- codegraph/refactor/transactions.py +414 -0
- codegraph/resolver.py +3968 -0
- codegraph/resources/__init__.py +46 -0
- codegraph/resources/cache.py +117 -0
- codegraph/resources/coalescer.py +83 -0
- codegraph/resources/debouncer.py +98 -0
- codegraph/resources/governor.py +219 -0
- codegraph/resources/monitor.py +102 -0
- codegraph/resources/policy.py +123 -0
- codegraph/retrieval_policy.py +320 -0
- codegraph/roblox.py +2174 -0
- codegraph/route_composer.py +363 -0
- codegraph/route_topology.py +172 -0
- codegraph/runtime/__init__.py +51 -0
- codegraph/runtime/collector.py +155 -0
- codegraph/runtime/db_watcher.py +191 -0
- codegraph/runtime/ingestor.py +692 -0
- codegraph/runtime/models.py +130 -0
- codegraph/runtime/port_inspector.py +304 -0
- codegraph/runtime/reconciliation.py +492 -0
- codegraph/runtime/runner.py +353 -0
- codegraph/runtime/trace_linker.py +175 -0
- codegraph/search/__init__.py +25 -0
- codegraph/search/hybrid.py +846 -0
- codegraph/search/semantic.py +28 -0
- codegraph/security/__init__.py +51 -0
- codegraph/security/paths.py +189 -0
- codegraph/security/redaction.py +633 -0
- codegraph/semantic_conflicts.py +270 -0
- codegraph/semantic_decorators.py +372 -0
- codegraph/structural_diff.py +542 -0
- codegraph/styles.py +144 -0
- codegraph/symbol_history.py +277 -0
- codegraph/target_resolver.py +348 -0
- codegraph/task.py +637 -0
- codegraph/tool_selection_eval.py +1158 -0
- codegraph/tsconfig.py +236 -0
- codegraph/ui/__init__.py +6 -0
- codegraph/ui/server.py +755 -0
- codegraph/watcher.py +323 -0
- codegraph_engine-3.0.0.dist-info/METADATA +859 -0
- codegraph_engine-3.0.0.dist-info/RECORD +130 -0
- codegraph_engine-3.0.0.dist-info/WHEEL +6 -0
- codegraph_engine-3.0.0.dist-info/entry_points.txt +2 -0
- codegraph_engine-3.0.0.dist-info/licenses/LICENSE +21 -0
- codegraph_engine-3.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,859 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codegraph-engine
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Deep deterministic repository intelligence for AI coding agents (code, dependencies, databases, and runtime observations)
|
|
5
|
+
Author: CodeGraph contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/raghurammrsd/CODE_GRAPH_MCP
|
|
8
|
+
Project-URL: Repository, https://github.com/raghurammrsd/CODE_GRAPH_MCP
|
|
9
|
+
Project-URL: Documentation, https://github.com/raghurammrsd/CODE_GRAPH_MCP/blob/main/docs/agent-brain.md
|
|
10
|
+
Project-URL: Changelog, https://github.com/raghurammrsd/CODE_GRAPH_MCP/blob/main/CHANGELOG.md
|
|
11
|
+
Project-URL: Issues, https://github.com/raghurammrsd/CODE_GRAPH_MCP/issues
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pydantic>=2.7
|
|
21
|
+
Requires-Dist: typer>=0.12
|
|
22
|
+
Requires-Dist: mcp<2,>=1.0
|
|
23
|
+
Provides-Extra: mcp
|
|
24
|
+
Requires-Dist: mcp<2,>=1.0; extra == "mcp"
|
|
25
|
+
Provides-Extra: system
|
|
26
|
+
Requires-Dist: psutil>=5.9; extra == "system"
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="docs/assets/codegraph_logo.jpg" alt="CodeGraph MCP — Deep Deterministic Repository Intelligence for AI Coding Agents" width="500" />
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<h1 align="center">CodeGraph MCP: Full-Stack Knowledge Graph & Semantic Intelligence for AI Coding Agents</h1>
|
|
39
|
+
|
|
40
|
+
<p align="center">
|
|
41
|
+
<strong>Deterministic AST-Verified Codebase Intelligence • Sub-15ms Live Watcher • Context Window Optimization</strong><br>
|
|
42
|
+
<em>Deterministic Model Context Protocol (MCP) server for Cursor, Claude Code, GitHub Copilot, Antigravity, Cline, Windsurf & Codex.</em>
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
<p align="center">
|
|
46
|
+
<a href="https://github.com/raghurammrsd/CODE_GRAPH_MCP"><img src="https://img.shields.io/github/stars/raghurammrsd/CODE_GRAPH_MCP?style=for-the-badge&logo=github&color=gold" alt="GitHub Stars" /></a>
|
|
47
|
+
<a href="https://pypi.org/project/codegraph-engine/"><img src="https://img.shields.io/badge/pypi-codegraph--engine-3776AB.svg?style=for-the-badge&logo=pypi" alt="PyPI: codegraph-engine" /></a>
|
|
48
|
+
<a href="src/codegraph/mcp/server.py"><img src="https://img.shields.io/badge/MCP-70%20Verified%20Tools-2ea043.svg?style=for-the-badge" alt="MCP Tools: 70 verified" /></a>
|
|
49
|
+
<a href="tests/"><img src="https://img.shields.io/badge/pytest-980%2B%20passed%20(100%25)-brightgreen.svg?style=for-the-badge&logo=pytest" alt="Tests: 980+ passed" /></a>
|
|
50
|
+
<a href="pyproject.toml"><img src="https://img.shields.io/badge/ruff-0%20errors-success.svg?style=for-the-badge" alt="Ruff: 0 errors" /></a>
|
|
51
|
+
<a href="src/codegraph/"><img src="https://img.shields.io/badge/mypy-strict%20(120%20files)-blue.svg?style=for-the-badge" alt="Mypy: strict" /></a>
|
|
52
|
+
</p>
|
|
53
|
+
|
|
54
|
+
> CodeGraph MCP provides deterministic, evidence-backed repository intelligence through Abstract Syntax Trees, framework router hierarchies, database lineage, and runtime observation.
|
|
55
|
+
|
|
56
|
+
<p align="center">
|
|
57
|
+
<a href="https://raghurammrsd.github.io/CODE_GRAPH_MCP/"><strong>Documentation Site</strong></a> •
|
|
58
|
+
<a href="https://pypi.org/project/codegraph-engine/3.0.0/"><strong>PyPI Package</strong></a> •
|
|
59
|
+
<a href="#overview"><strong>Overview</strong></a> •
|
|
60
|
+
<a href="#interactive-web-dashboard--vs-code-extension"><strong>Web Dashboard & VS Code</strong></a> •
|
|
61
|
+
<a href="#the-three-pillars-of-codegraph-mcp"><strong>The Three Pillars</strong></a> •
|
|
62
|
+
<a href="#2-quickstart-30-second-setup"><strong>Quickstart</strong></a> •
|
|
63
|
+
<a href="#4-real-world-cli-outputs"><strong>CLI Outputs</strong></a> •
|
|
64
|
+
<a href="#6-database-intelligence"><strong>Database Intelligence</strong></a> •
|
|
65
|
+
<a href="#7-zero-friction-runtime-intelligence--static-reconciliation"><strong>Runtime Evidence</strong></a> •
|
|
66
|
+
<a href="#8-git-aware-repository-intelligence"><strong>Git Intelligence</strong></a> •
|
|
67
|
+
<a href="#measured-performance--real-metrics-benchmark"><strong>Benchmarks</strong></a> •
|
|
68
|
+
<a href="docs/agent-brain.md"><strong>70-Tool Reference</strong></a> •
|
|
69
|
+
<a href="https://github.com/raghurammrsd/CODE_GRAPH_MCP"><strong>GitHub</strong></a>
|
|
70
|
+
</p>
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Overview
|
|
75
|
+
|
|
76
|
+
### The Problem
|
|
77
|
+
|
|
78
|
+
When AI coding agents (such as Claude Code, Cursor, or Antigravity) explore complex enterprise repositories, text-based search (grep/ripgrep) forces them to parse large, multi-thousand-line files to reconstruct call chains, router mounts, dependency injection graphs, and ORM schemas. This consumes 60% to 80% of the LLM context window with irrelevant code and frequently leads to hallucinations regarding entity relationships and database structures.
|
|
79
|
+
|
|
80
|
+
### The Solution: CodeGraph MCP
|
|
81
|
+
|
|
82
|
+
**CodeGraph MCP provides deterministic, compiler-grade repository intelligence through the Model Context Protocol.** Instead of guessing based on lexical approximations, the AI agent queries a local, persistent SQLite index for verified AST relationships, framework router trees, database lineages, and live runtime observations—resolved in sub-5ms latency.
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
86
|
+
│ AI CODING AGENT │
|
|
87
|
+
│ (Claude Code • Cursor • Antigravity) │
|
|
88
|
+
└──────────────────────────────┬──────────────────────────────┘
|
|
89
|
+
│ Model Context Protocol (stdio / SSE)
|
|
90
|
+
▼
|
|
91
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
92
|
+
│ CODEGRAPH MCP ENGINE │
|
|
93
|
+
├──────────────────────────────┬──────────────────────────────┤
|
|
94
|
+
│ AST Code Relationships │ Framework Route Hierarchy │
|
|
95
|
+
│ (Callers, Callees, DI) │ (FastAPI, Django, Express) │
|
|
96
|
+
├──────────────────────────────┼──────────────────────────────┤
|
|
97
|
+
│ Database Lineage & Schemas │ Non-Invasive Dev Tracing │
|
|
98
|
+
│ (SQLAlchemy, Prisma, ORM) │ (HTTP metrics, exceptions) │
|
|
99
|
+
└──────────────────────────────┴──────────────────────────────┘
|
|
100
|
+
│
|
|
101
|
+
▼
|
|
102
|
+
Deterministic • Local-First • Verified Evidence
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Core Architecture Capabilities
|
|
106
|
+
|
|
107
|
+
- **Deterministic Evidence Guarantee**: Every returned entity and relationship is statically verified via Abstract Syntax Trees or explicitly flagged as `UNKNOWN` / `POSSIBLE`. CodeGraph MCP provides deterministic, evidence-backed repository intelligence across application code, databases, runtime behavior, and Git history.
|
|
108
|
+
- **Sub-5ms Freshness Verification**: Monotonic commit tracking validates `git rev-parse HEAD` and porcelain status instantly, avoiding full-tree re-indexing on unchanged codebases.
|
|
109
|
+
- **Context Window Optimization**: Yields 65% to 85% token reduction by returning structured, bounded source slices rather than entire file dumps.
|
|
110
|
+
- **Zero-Friction Dev Interception (`codegraph run`)**: Wraps local development servers (e.g., `codegraph run npm run dev`, `codegraph run uvicorn main:app`) to capture real HTTP routes, latencies, and stack traces without application code changes.
|
|
111
|
+
- **Multi-Agent Setup (`codegraph install`)**: Automatically detects, configures, and verifies integrations for Claude Code, Cursor, Antigravity, and Cline.
|
|
112
|
+
|
|
113
|
+
> **Supported Languages & Frameworks:** Python (`FastAPI`, `Flask`, `Django`, `SQLAlchemy`, `PyTorch`, `Celery`, `LangChain`, `LlamaIndex`, `Ray`, `pytest`) and TypeScript / JavaScript (`.ts`, `.tsx`, `.js`, `.jsx`, `React`, `Next.js`, `NestJS`, `Express.js`, `Prisma`, `Drizzle`, `Mongoose`).
|
|
114
|
+
|
|
115
|
+
<p align="center">
|
|
116
|
+
<img src="docs/assets/codegraph_full_architecture.svg" alt="CodeGraph MCP Comprehensive Full-Stack Architecture Pipeline" width="950" />
|
|
117
|
+
</p>
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Measured Performance & Real Metrics Benchmark
|
|
124
|
+
|
|
125
|
+
Performance and retrieval accuracy are verified across two empirical evaluation suites: a **32-task agent navigation simulation** ([`src/codegraph/tool_selection_eval.py`](src/codegraph/tool_selection_eval.py)) measuring agent trajectory efficiency, and a **50-task diagnostic benchmark** ([`benchmarks/run_v21_eval.py`](benchmarks/run_v21_eval.py)) evaluating multi-file recall, coverage, and context boundaries:
|
|
126
|
+
|
|
127
|
+
| Performance Metric | Unassisted AI Agents (Raw Grep / File Dumps) | CodeGraph MCP Engine | Measured Result | Evaluation Suite |
|
|
128
|
+
| :--- | :---: | :---: | :---: | :---: |
|
|
129
|
+
| **Unsupported Relationship Claims** | 18.5% – 34.0% false edges | **0.0%** (AST / Framework verified) | **100% eliminated** | 32-Task Navigation Eval |
|
|
130
|
+
| **Exploration Tool Calls** | 164 total tool calls (~5.1 / task) | **71 tool calls** (~2.2 / task) | **56.7% fewer tool calls** | 32-Task Navigation Eval |
|
|
131
|
+
| **Context Consumption (Prompt Tokens)** | 3,000 – 12,000+ tokens / task | **~510 tokens** avg payload | **72% – 85% token savings** | 32-Task Navigation Eval |
|
|
132
|
+
| **Direct File Token Reduction** | Full file reads required | Bounded slices via `get_file` | **41.8% token reduction** | 50-Task Retrieval Benchmark |
|
|
133
|
+
| **Task Coverage & Symbol Recall** | Baseline lexical match | **88.0% coverage / 61.9% recall** | **Verified ground truth** | 50-Task Retrieval Benchmark |
|
|
134
|
+
| **Incremental File Reindexing (Live)** | Full rescan required (1.2s – 6.5s) | **< 15ms per file (`codegraph watch`)** | **In-memory cache patch** | Live OS Kernel Watcher |
|
|
135
|
+
| **Single-File Full Re-index (Cold CLI)** | Full rescan required (4.4s) | **3.665s** (2,504 files) | **16.9% faster** | 4-Tier Stress Benchmark |
|
|
136
|
+
| **Repository Freshness Check** | 450ms – 2,100ms disk stat checks | **< 5ms (Git commit fast path)** | **99% faster checks** | Git Fast Path Check |
|
|
137
|
+
| **Symbol Grounding & Resolution** | Manual file scanning | **< 2ms in-memory SQLite** | **Sub-millisecond resolution** | SQLite Indexed Lookup |
|
|
138
|
+
| **Automated Test Suite Quality** | — | **980+ passed tests (100% pass rate)** | **Zero regressions** | Pytest CI/CD Suite |
|
|
139
|
+
|
|
140
|
+
<p align="center">
|
|
141
|
+
<img src="docs/assets/performance_comparison.svg" alt="CodeGraph MCP — Measured Context & Exploration Efficiency" width="850" />
|
|
142
|
+
</p>
|
|
143
|
+
|
|
144
|
+
<p align="center">
|
|
145
|
+
<img src="docs/assets/large_repo_scaling.svg" alt="CodeGraph MCP — Large Repository Scaling up to 2,504 Files / ~120k LOC" width="850" />
|
|
146
|
+
</p>
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Interactive Web Dashboard & VS Code Extension
|
|
151
|
+
|
|
152
|
+
CodeGraph v3.0 introduces a zero-configuration local visual dashboard and official VS Code integration for real-time visual inspection of your repository's AST relationships, full-stack routes, and PR blast radius.
|
|
153
|
+
|
|
154
|
+
### 1. Interactive Knowledge Graph Web Dashboard (`codegraph ui`)
|
|
155
|
+
|
|
156
|
+
Launch the local visualizer with a single command:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# Launch interactive dashboard on http://127.0.0.1:8765
|
|
160
|
+
codegraph ui
|
|
161
|
+
|
|
162
|
+
# Custom port or headless server (no automatic browser launch)
|
|
163
|
+
codegraph ui --port 9000 --no-browser
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The Web Dashboard delivers:
|
|
167
|
+
- **Interactive Knowledge Visualizer**: Search and inspect any symbol, route, or model across Python and TypeScript.
|
|
168
|
+
- **Full-Stack Route Explorer**: Visualizes frontend fetchers (`fetch<T>()`, `axios`) matched to backend handlers (FastAPI, Flask, Django, Express, NestJS).
|
|
169
|
+
- **Database Lineage Matrix**: Real-time table relationship map showing exact static writers and readers (PostgreSQL, SQLite, Prisma, Drizzle, SQLAlchemy, Mongoose).
|
|
170
|
+
- **PR Blast Radius & Risk Tiering**: Live risk assessment, highlighting modified call chains and covering tests before submitting pull requests.
|
|
171
|
+
- **REST & SSE Endpoints**: Integrated REST API (`/api/status`, `/api/routes`, `/api/drift`, `/api/impact`, `/api/graph`) enabling external tools to query graph state.
|
|
172
|
+
|
|
173
|
+
### 2. Official VS Code Extension (`vscode-extension`)
|
|
174
|
+
|
|
175
|
+
The CodeGraph VS Code extension brings deterministic repository intelligence directly into your editor:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Package and install the extension
|
|
179
|
+
cd vscode-extension
|
|
180
|
+
code --install-extension codegraph-3.0.0.vsix
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Features included in the VS Code sidebar:
|
|
184
|
+
- **Full-Stack Routes View**: Tree view of all discovered endpoints, clicking any item navigates directly to the route handler definition.
|
|
185
|
+
- **Database Lineage & Models View**: Inspect tables, fields, readers, and writers side-by-side with source code.
|
|
186
|
+
- **PR Blast Radius Explorer**: Select any active file to view downstream callers, impacted routes, and tests to run.
|
|
187
|
+
- **In-Editor Knowledge Graph Panel (`CodeGraph: Open Visual Knowledge Graph Dashboard`)**: Opens the visual web dashboard side-by-side in a VS Code Webview panel.
|
|
188
|
+
- **Safe AST Rename (`CodeGraph: Safe AST Rename Symbol`)**: Deterministic symbol refactoring across all call sites and route handlers.
|
|
189
|
+
- **Live Watcher Integration (`CodeGraph: Start Sub-15ms Live Watcher Daemon`)**: One-click background watcher launch.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## The Three Pillars of CodeGraph MCP
|
|
194
|
+
|
|
195
|
+
### AI / ML & PyTorch Stack Intelligence
|
|
196
|
+
CodeGraph MCP natively parses AI/ML architectures and agent pipelines into deterministic graph facts:
|
|
197
|
+
- **PyTorch nn.Module Forward Resolution**: Submodule and model instance calls (`model(x)`, `self.encoder(x)`) automatically resolve to `Encoder.forward` emitting `DISPATCHES_FORWARD` (`AST_VERIFIED`).
|
|
198
|
+
- **LangChain & LlamaIndex Agent Tools**: Statically detects `@tool`, `@function_tool`, and dynamic agent registries, connecting agent capabilities to handler implementations (`AGENT_TOOL`).
|
|
199
|
+
- **LangChain LCEL Pipelines**: Tracks pipe syntax (`prompt | model | parser`) as executable pipeline dataflow (`CHAINS_TO`).
|
|
200
|
+
- **Distributed Ray Tasks**: Detects `@ray.remote` actor decorators and `task.remote()` invocations (`DISPATCHES_RAY_TASK`).
|
|
201
|
+
|
|
202
|
+
### Pillar 1: The Unified Full-Stack Bridge (`codegraph api-drift`)
|
|
203
|
+
Bridges frontend client fetchers and backend API handlers across languages without manual tracing:
|
|
204
|
+
- **Client Route Extraction**: Statically parses React / Next.js / Vue / Nuxt `fetch<T>()`, `axios.get<T>()`, `useSWR<T>()`, `useQuery<T>()`, and `$fetch<T>()` alongside TypeScript request/response interfaces.
|
|
205
|
+
- **Universal Route Normalization**: Matches parameterized paths (`/api/v1/orders/:id`, `/api/orders/${orderId}`, `/orders/{order_id}`) directly to backend routes in FastAPI, Flask, Django, Express, and NestJS.
|
|
206
|
+
- **Cross-Language Drift Detection**: Flags field name mismatches, type incompatibilities, missing nullable fields, and orphaned client routes before deployment.
|
|
207
|
+
|
|
208
|
+
### Pillar 2: Semantic Change Impact & PR Blast Radius Engine (`codegraph impact`)
|
|
209
|
+
Full-stack downstream impact analysis from code symbols to production infrastructure:
|
|
210
|
+
- **Blast Radius Tracing**: Traces any symbol or git diff $\to$ direct/transitive callers $\to$ React UI components $\to$ HTTP routes $\to$ DB readers/writers $\to$ covering tests $\to$ monorepo packages.
|
|
211
|
+
- **PR Risk Scoring (0–100)**: Quantitative risk evaluation categorized into `LOW`, `MEDIUM`, `HIGH`, and `CRITICAL`.
|
|
212
|
+
- **Breaking Change Detection**: Identifies public API modifications, DB mutations, and untested code paths.
|
|
213
|
+
- **Smart Test Execution**: Generates targeted test commands (e.g. `pytest tests/test_orders.py -k "test_a or test_b"`) running only the affected test suite.
|
|
214
|
+
|
|
215
|
+
### Pillar 3: Incremental Live Watcher & Instant Cache Invalidation (`codegraph watch`)
|
|
216
|
+
Zero-heat, real-time file system monitoring with sub-15ms incremental reindexing:
|
|
217
|
+
- **Kernel-Push Event Monitoring**: Uses OS-level kernel events (macOS FSEvents, Linux inotify, Windows ReadDirectoryChangesW) via `watchdog`.
|
|
218
|
+
- **250ms Sliding Debounce**: Coalesces rapid multi-file edit bursts from formatters, linters, or git operations into single atomic passes.
|
|
219
|
+
- **Sub-15ms Incremental Reindexing**: Bypasses full-disk traversal; only re-indexes modified files (`Indexer.reindex_paths`) and advances generation counters.
|
|
220
|
+
- **Instant In-Memory Cache Busting**: Automatically purges LRU memory caches (`_PARSE_CACHE`, `_GRAPH_CACHE`) and SQLite context caches upon file mutation.
|
|
221
|
+
|
|
222
|
+
## 1. What's New in v3.0.0
|
|
223
|
+
|
|
224
|
+
Version `3.0.0` delivers major advancements in **Git-Aware Intelligence**, **Interactive Visualization**, **Engine Robustness**, and **Context Token Optimization**:
|
|
225
|
+
|
|
226
|
+
### 1.1 Git-Aware Repository Intelligence
|
|
227
|
+
|
|
228
|
+
Understand how code evolves across branches, commits, and working tree edits with sub-millisecond freshness verification:
|
|
229
|
+
|
|
230
|
+
| Capability | CLI Command | MCP Tool | How It Solves Agent Failure Modes |
|
|
231
|
+
| :--- | :--- | :--- | :--- |
|
|
232
|
+
| **Working-Tree Freshness** | `codegraph git-state` | `get_git_state` | Tracks branch, HEAD vs indexed commit, modified/staged files with sub-millisecond status caching. Surfaces `CLEAN`, `DIRTY`, `STALE`, `REINDEXING`, `ERROR`. |
|
|
233
|
+
| **Structural AST Diff** | `codegraph git-diff [base] [head]` | `compare_git` | Semantic diff across Git revisions: identifies added/removed/modified functions, changed parameter signatures, and affected routes—not merely raw line diffs. |
|
|
234
|
+
| **Deep Impact & Visual Tree** | `codegraph git-impact --tree` | `get_change_impact` | Traverses downstream callers, callees, framework routes, DB writers, and affected test suites with token-bounded ranking and terminal ASCII tree visualization. |
|
|
235
|
+
| **Semantic Merge Conflicts** | `codegraph git-conflicts [base] [head]` | `detect_semantic_conflicts` | Detects silent contract breaks before merge: invoking functions or route handlers that were deleted or modified on the target branch. |
|
|
236
|
+
| **Context Freshness Gate** | `codegraph check-freshness [task]` | `check_context_freshness` | Determines whether previously compiled context remains `VALID`, `PARTIALLY_STALE`, or `STALE` without re-running full graph queries if unrelated files changed. |
|
|
237
|
+
| **Deterministic Symbol History** | `codegraph symbol-history <sym>` | `trace_symbol_history` | Reconstructs the exact commit lifecycle of any symbol (introduced, modified, moved, renamed, or deleted) with confidence labels. |
|
|
238
|
+
|
|
239
|
+
### 1.2 Engine Robustness & Accuracy Hardening
|
|
240
|
+
|
|
241
|
+
- **Modern FastAPI Dependency Injection**: First-class tracking for `Annotated[..., Depends(...)]` type aliases (e.g. `SessionDep = Annotated[Session, Depends(get_db)]`, `CurrentUser`, `TokenDep`) resolving callers of DB and security providers directly to consuming route handlers.
|
|
242
|
+
- **Python Syntax Auto-Repair**: Auto-recovers unparenthesized multi-exception syntax (`except A, B:`) across newer Python host runtimes so core dependency modules never fail AST extraction.
|
|
243
|
+
- **Strict Endpoint Scoping**: Prevents cross-file name collisions (e.g., matching same-named endpoints across disparate router modules) to maintain 0% false edge rates.
|
|
244
|
+
- **Token Budget & Noise Suppression**: Context compilation strictly adheres to `max_tokens` limits by summarizing auxiliary sections. Graph traversals automatically filter noisy tensor and dictionary primitive methods (`size`, `shape`, `stack`, `get`), keeping token payloads lean.
|
|
245
|
+
|
|
246
|
+
### 1.3 Enterprise Concurrency & Runtime Interceptor
|
|
247
|
+
|
|
248
|
+
| Capability | Mechanism | Impact |
|
|
249
|
+
| :--- | :--- | :--- |
|
|
250
|
+
| **Runtime Interceptor** | `codegraph run <cmd>` non-invasive wrappers (`NODE_OPTIONS` / `PYTHONSTARTUP`) | Zero application code modifications; streams live HTTP routes, latencies, and exception traces into `.codegraph/runtime.sqlite3`. |
|
|
251
|
+
| **WAL Database Concurrency** | Permanent `WAL` mode, `synchronous = NORMAL`, `busy_timeout = 15000` (15s), `cache_size = -64000` (64MB) | Eliminates `database is locked` errors during parallel AI pair-programming interrogation. |
|
|
252
|
+
| **Index Freshness Fast Path** | Instant verification: checks `git rev-parse HEAD` and `git status --porcelain` | Reduces index freshness verification from seconds to `< 5ms` on clean repositories. |
|
|
253
|
+
| **Bounded Pagination** | `limit`, `offset`, `total_count`, and `has_more` on all route, table, and context queries | Prevents token blowups on large repositories with tens of thousands of endpoints. |
|
|
254
|
+
| **Multi-Transport MCP** | Hot-reconnecting `--transport sse` alongside default `stdio` | Prevents MCP client crash loops on server restarts or IDE reconnections. |
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## 2. Quickstart (30-Second Setup)
|
|
259
|
+
|
|
260
|
+
### Step 1: Install the Package
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
pip install "codegraph-engine[mcp]"
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Step 2: Configure Your AI Coding Agents (`codegraph install`)
|
|
267
|
+
|
|
268
|
+
CodeGraph MCP includes an interactive, idempotent onboarding installer ([`src/codegraph/installer.py`](src/codegraph/installer.py)) that detects installed AI coding agents (**Claude Code**, **Cursor**, **Antigravity**, **Codex CLI**, **Gemini CLI**, and **Cline**), configures `mcpServers.codegraph`, installs marker-bounded routing instructions (`<!-- CODEGRAPH:START -->` … `<!-- CODEGRAPH:END -->`), and verifies server health:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
# Interactive setup (detects installed agents, previews planned changes, asks confirmation)
|
|
272
|
+
codegraph install
|
|
273
|
+
|
|
274
|
+
# Non-interactive setup for all detected agents in the current project
|
|
275
|
+
codegraph install --yes --target auto --location local
|
|
276
|
+
|
|
277
|
+
# Preview exact file modifications without writing anything
|
|
278
|
+
codegraph install --dry-run
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Step 3: Initialize & Verify Your Project Index
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
cd your-project
|
|
285
|
+
codegraph init
|
|
286
|
+
codegraph status
|
|
287
|
+
codegraph doctor
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
> **Dynamic Index Hot-Reloading:** If your AI coding agent launches `codegraph mcp serve` before you run `codegraph init`, you do **not** need to restart your IDE or MCP session. As soon as `codegraph init` or `codegraph index` creates or updates `.codegraph.sqlite3`, the running MCP server automatically detects the database on the next tool call and refreshes its in-memory graph cache (`get_repository_status(reload=True, reindex=True)` can also be invoked directly by the agent).
|
|
291
|
+
|
|
292
|
+
### Step 4: Run With Zero-Friction Telemetry (`codegraph run`)
|
|
293
|
+
|
|
294
|
+
Wrap your development server transparently to stream real HTTP routes, durations, and uncaught exceptions directly into CodeGraph MCP:
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
# Node / Express / Next.js
|
|
298
|
+
codegraph run npm run dev
|
|
299
|
+
|
|
300
|
+
# Python / FastAPI / Uvicorn
|
|
301
|
+
codegraph run uvicorn main:app --reload
|
|
302
|
+
|
|
303
|
+
# Django
|
|
304
|
+
codegraph run python manage.py runserver
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 3. Core Architecture & Mental Model
|
|
310
|
+
|
|
311
|
+
```mermaid
|
|
312
|
+
flowchart TD
|
|
313
|
+
A["AI Coding Agent (Claude, Cursor, Antigravity, Cline)"] --> B["CodeGraph MCP Server (stdio or SSE)"]
|
|
314
|
+
B --> C["Deterministic Repository Intelligence"]
|
|
315
|
+
|
|
316
|
+
C --> D["AST Semantic Graph (Callers, Callees, References, DI)"]
|
|
317
|
+
C --> E["Literal & Regex Text Search (search_code)"]
|
|
318
|
+
C --> F["Bounded Source Inspection (get_file)"]
|
|
319
|
+
C --> G["Database Intelligence (Tables, ORM, Migrations, R/W)"]
|
|
320
|
+
C --> H["Zero-Friction Runtime Telemetry (codegraph run)"]
|
|
321
|
+
|
|
322
|
+
D --> I["Structured Evidence + Epistemic Labels"]
|
|
323
|
+
E --> I
|
|
324
|
+
F --> I
|
|
325
|
+
G --> I
|
|
326
|
+
H --> I
|
|
327
|
+
|
|
328
|
+
I --> J["Context Optimization & Secret Redaction"]
|
|
329
|
+
J --> A
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Routing Each Question to the Right Primitive
|
|
333
|
+
|
|
334
|
+
```text
|
|
335
|
+
STRUCTURAL → Graph tools (find_symbol, find_callers, find_callees, find_references, find_routes)
|
|
336
|
+
TEXTUAL → search_code (literal/regex search across Python, HTML/Jinja, JS/TS, CSS, YAML/JSON, SQL)
|
|
337
|
+
SOURCE → get_file (bounded start_line..end_line source inspection with truncation metadata)
|
|
338
|
+
GRAPH → Trace tools (trace_path, trace_flow, analyze_impact, get_git_impact)
|
|
339
|
+
DATABASE → Database tools (get_db_schema, find_db_tables, find_db_readers, find_db_writers, get_db_impact)
|
|
340
|
+
RUNTIME → Runtime tools (codegraph run, ingest_runtime_traces, get_runtime_trace, reconcile_static_runtime)
|
|
341
|
+
EDITING → Native agent / IDE editing tools
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
## 4. Real-World CLI Outputs
|
|
347
|
+
|
|
348
|
+
Below are exact, verifiable outputs produced by CodeGraph MCP v3.0.0:
|
|
349
|
+
|
|
350
|
+
### 1. Zero-Friction Runtime Interceptor (`codegraph run`)
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
$ codegraph run python3 -c "print('>> Dev server active on port 8000')"
|
|
354
|
+
>> Dev server active on port 8000
|
|
355
|
+
```
|
|
356
|
+
*HTTP requests, status codes, and exceptions are automatically streamed to `.codegraph/runtime.sqlite3` with child exit codes preserved.*
|
|
357
|
+
|
|
358
|
+
### 2. Instant Index Freshness Check (`codegraph status`)
|
|
359
|
+
|
|
360
|
+
```bash
|
|
361
|
+
$ codegraph status .
|
|
362
|
+
{
|
|
363
|
+
"repository": "/Users/raghuram/Documents/ChatGPT/MCP",
|
|
364
|
+
"freshness": "FRESH",
|
|
365
|
+
"freshness_detail": "Index matches current repository state.",
|
|
366
|
+
"files": 190,
|
|
367
|
+
"chunks": 1965,
|
|
368
|
+
"symbols": 1947,
|
|
369
|
+
"framework_routes": 0,
|
|
370
|
+
"graph_edges": 12712,
|
|
371
|
+
"resource_profile": "BALANCED",
|
|
372
|
+
"pressure_level": "NORMAL",
|
|
373
|
+
"activity_mode": "IDLE",
|
|
374
|
+
"estimated_memory_mb": 43.23,
|
|
375
|
+
"modified_files": [],
|
|
376
|
+
"deleted_files": [],
|
|
377
|
+
"parse_failed_files": []
|
|
378
|
+
}
|
|
379
|
+
```
|
|
380
|
+
*Validated in `< 5ms` via the Git commit diff fast path.*
|
|
381
|
+
|
|
382
|
+
### 3. Incremental Indexing with 16-Phase Telemetry (`codegraph index --verbose`)
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
$ codegraph index --verbose
|
|
386
|
+
Phase: Repository Scan
|
|
387
|
+
190 / 190 files | 100% | elapsed: 0.09s | rate: 128,203 files/min | memory: 42 MB
|
|
388
|
+
Phase: Post-Processing
|
|
389
|
+
190 / 190 files | 100% | elapsed: 0.62s | rate: 18,273 files/min | memory: 67 MB
|
|
390
|
+
Phase: Symbol Resolution
|
|
391
|
+
190 / 190 files | 100% | elapsed: 0.80s | rate: 14,311 files/min | memory: 91 MB
|
|
392
|
+
Phase: Relationship Resolution
|
|
393
|
+
190 / 190 files | 100% | elapsed: 1.49s | rate: 7,648 files/min | memory: 116 MB
|
|
394
|
+
Phase: Database Analysis
|
|
395
|
+
190 / 190 files | 100% | elapsed: 1.77s | rate: 6,424 files/min | memory: 120 MB
|
|
396
|
+
Phase: Final Commit & Checkpoint
|
|
397
|
+
190 / 190 files | 100% | elapsed: 2.59s | rate: 4,396 files/min | memory: 141 MB
|
|
398
|
+
|
|
399
|
+
Summary: elapsed=2.595s peak_rss=141.0MB max_wal=9.44MB final_wal=0.00MB commits=15 checkpoints=15
|
|
400
|
+
[repository_scan] 88.1ms files=190 items=190 writes=0
|
|
401
|
+
[ast_parsing] 154.7ms files=13 items=3322 writes=0
|
|
402
|
+
[database_analysis] 283.9ms files=13 items=1631 writes=0
|
|
403
|
+
[symbol_resolution] 52.5ms files=190 items=5854 writes=0
|
|
404
|
+
[relationship_resolution] 694.0ms files=190 items=32806 writes=0
|
|
405
|
+
[sqlite_writes] 1146.4ms files=13 items=50206 writes=50208
|
|
406
|
+
scanned=190 indexed=13 unchanged=177 removed=0
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### 4. Bounded Monorepo Route Discovery (`codegraph routes --limit 3`)
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
$ codegraph routes --limit 3
|
|
413
|
+
Found 3 route(s):
|
|
414
|
+
[GET] /api/v1/health -> health_check (src/app/api.py:14) [fastapi]
|
|
415
|
+
[POST] /api/v1/orders -> create_order (src/app/orders.py:42) [fastapi]
|
|
416
|
+
[GET] /api/v1/users/{id} -> get_user (src/app/users.py:88) [fastapi]
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### 5. Safe Background Process Termination (`codegraph stop --json`)
|
|
420
|
+
|
|
421
|
+
```bash
|
|
422
|
+
$ codegraph stop --json
|
|
423
|
+
{
|
|
424
|
+
"status": "ok",
|
|
425
|
+
"stopped_count": 0,
|
|
426
|
+
"stale_cleaned_count": 0,
|
|
427
|
+
"processes": []
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
---
|
|
432
|
+
|
|
433
|
+
## 5. AI/ML & Backend Architecture Examples
|
|
434
|
+
|
|
435
|
+
### Example 1: Model Inference Service Flow
|
|
436
|
+
|
|
437
|
+
```text
|
|
438
|
+
POST /v1/predict (FastAPI Route)
|
|
439
|
+
↓ HANDLED_BY (FRAMEWORK_VERIFIED)
|
|
440
|
+
predict_endpoint (Handler)
|
|
441
|
+
↓ INJECTS (DATAFLOW_VERIFIED)
|
|
442
|
+
get_inference_service (DI Provider)
|
|
443
|
+
↓ CALLS (AST_VERIFIED)
|
|
444
|
+
InferenceService.run_inference
|
|
445
|
+
├──►CALLS (AST_VERIFIED) ──► FeaturePreprocessor.transform
|
|
446
|
+
├──►CALLS (AST_VERIFIED) ──► FraudClassifier.forward
|
|
447
|
+
├──►CALLS (AST_VERIFIED) ──► ScorePostprocessor.calibrate
|
|
448
|
+
└──►CALLS (AST_VERIFIED) ──► PredictionRepository.log_prediction
|
|
449
|
+
↓ WRITES_TABLE (AST_VERIFIED)
|
|
450
|
+
db:table:postgresql.public.prediction_logs
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
**What CodeGraph MCP structurally proves**:
|
|
454
|
+
- `find_routes(path="/v1/predict")` resolves composed router prefixes (`MOUNTS`) to `predict_endpoint`.
|
|
455
|
+
- `trace_path(from_symbol="predict_endpoint", to_symbol="log_prediction")` proves the multi-hop execution chain across DI injection, preprocessing, model execution, and persistence.
|
|
456
|
+
- `get_db_impact(symbol="InferenceService.run_inference")` identifies downstream writes to `prediction_logs`.
|
|
457
|
+
|
|
458
|
+
### Example 2: Training & Evaluation Pipeline
|
|
459
|
+
|
|
460
|
+
```text
|
|
461
|
+
train_cli (CLI Command Handler)
|
|
462
|
+
↓ COMMAND_HANDLER (FRAMEWORK_VERIFIED)
|
|
463
|
+
TrainingPipeline.run
|
|
464
|
+
├──►CALLS (AST_VERIFIED) ──► DatasetBuilder.load_splits
|
|
465
|
+
├──►CALLS (AST_VERIFIED) ──► TokenizerTransform.encode_batch
|
|
466
|
+
├──►CALLS (AST_VERIFIED) ──► Trainer.fit_epoch
|
|
467
|
+
├──►CALLS (AST_VERIFIED) ──► CheckpointManager.save_weights
|
|
468
|
+
└──►CALLS (AST_VERIFIED) ──► Evaluator.compute_metrics
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
**What CodeGraph MCP structurally proves**:
|
|
472
|
+
- `find_callees(symbol="TrainingPipeline.run")` enumerates every stage of the pipeline with exact file and line ranges.
|
|
473
|
+
- `find_tests(symbol="Evaluator.compute_metrics")` locates the unit and regression tests covering metric calculation.
|
|
474
|
+
- When a transform or model class is dynamically instantiated from a YAML string (`getattr(models, cfg.arch)`), CodeGraph MCP explicitly records `POSSIBLE_CALLS` (`POSSIBLE`) or `UNRESOLVED_REFERENCE` (`UNKNOWN`) rather than fabricating a false static call edge.
|
|
475
|
+
|
|
476
|
+
### Example 3: LLM Agent & Tool Registry
|
|
477
|
+
|
|
478
|
+
```text
|
|
479
|
+
POST /api/chat (LLM Endpoint)
|
|
480
|
+
↓ HANDLED_BY (FRAMEWORK_VERIFIED)
|
|
481
|
+
chat_handler
|
|
482
|
+
↓ CALLS (AST_VERIFIED)
|
|
483
|
+
AgentRunner.execute_step
|
|
484
|
+
├──►REGISTERS / REGISTERED_HANDLER ──► ToolRegistry ("search_orders", "refund_order")
|
|
485
|
+
├──►CALLS (AST_VERIFIED) ──► ContextBuilder.compile
|
|
486
|
+
├──►READS_TABLE (AST_VERIFIED) ──► db:table:postgresql.public.conversations
|
|
487
|
+
└──►CALLS (AST_VERIFIED) ──► ModelProviderClient.generate
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
**What CodeGraph MCP structurally proves**:
|
|
491
|
+
- Tracks decorator and call-based registrations (`@tool_registry.register("search_orders")`) via `REGISTERS` and `REGISTERED_HANDLER` edges.
|
|
492
|
+
- Tracks environment variable dependencies (`os.getenv("OPENAI_API_KEY")`) as `READS_ENV` edges with the variable name only—never indexing or exposing secret values.
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## 6. Database Intelligence
|
|
497
|
+
|
|
498
|
+
[`src/codegraph/database/`](src/codegraph/database/) provides static schema, ORM model, migration, and query extraction across **SQLAlchemy**, **Django ORM**, **SQLModel**, **Prisma** (`.prisma`), **Alembic**, **Django Migrations**, and **Raw SQL** (`PostgreSQL`, `MySQL`, `SQLite`).
|
|
499
|
+
|
|
500
|
+
```text
|
|
501
|
+
POST /orders
|
|
502
|
+
↓ HANDLED_BY (FRAMEWORK_VERIFIED)
|
|
503
|
+
OrderService.create_order
|
|
504
|
+
↓ CALLS (AST_VERIFIED)
|
|
505
|
+
OrderRepository.insert_order
|
|
506
|
+
↓ WRITES_TABLE (AST_VERIFIED)
|
|
507
|
+
db:table:postgresql.public.orders
|
|
508
|
+
↓ FOREIGN_KEY_TO (AST_VERIFIED)
|
|
509
|
+
orders.user_id ──► users.id
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
### Capabilities Exposed by the 11 Database MCP Tools
|
|
513
|
+
- **Table & Column Discovery** (`get_db_schema`, `get_db_table`, `find_db_tables`, `find_db_columns`): Extract tables, column types, nullability, defaults, primary keys (`HAS_PRIMARY_KEY`), indexes (`HAS_INDEX`), unique/check constraints, and foreign keys (`FOREIGN_KEY_TO`).
|
|
514
|
+
- **ORM Mapping** (`find_db_models`): Map SQLAlchemy `__tablename__`, Django `models.Model` (`Meta.db_table`), SQLModel `table=True`, and Prisma `model` blocks via `MAPS_TO_TABLE` and `MAPS_TO_COLUMN`.
|
|
515
|
+
- **Readers, Writers & Callers** (`find_db_readers`, `find_db_writers`, `find_db_callers`, `find_db_queries`): Identify every function or method that executes `SELECT` (`READS_TABLE`) or `INSERT` / `UPDATE` / `DELETE` / `.add()` / `.save()` (`WRITES_TABLE`) against a table.
|
|
516
|
+
- **Migration Lineage & Schema Blast Radius** (`find_db_relationships`, `get_db_impact`): Track Alembic (`op.create_table`, `op.add_column`) and Django (`migrations.CreateModel`, `migrations.AddField`) operations (`MIGRATES_TABLE`) and compute bidirectional code $\leftrightarrow$ database impact.
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## 7. Zero-Friction Runtime Intelligence & Static Reconciliation
|
|
521
|
+
|
|
522
|
+
Static analysis proves what **can** happen structurally; runtime telemetry records what **was observed** during execution. CodeGraph MCP v3.0.0 brings them together transparently:
|
|
523
|
+
|
|
524
|
+
```text
|
|
525
|
+
STATIC GRAPH (AST + Framework + Dataflow + DB)
|
|
526
|
+
+
|
|
527
|
+
RUNTIME OBSERVATION (codegraph run / OTel JSON / JSONL / SQL Logs)
|
|
528
|
+
↓
|
|
529
|
+
reconcile_static_runtime()
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### Reconciliation Outcomes ([`ReconciliationStatus`](src/codegraph/runtime/models.py))
|
|
533
|
+
|
|
534
|
+
| Reconciliation Status | Static Graph | Runtime Trace | Meaning |
|
|
535
|
+
| :--- | :---: | :---: | :--- |
|
|
536
|
+
| **`CONFIRMED_RUNTIME_PATH`** | Present | Observed | Static relationship is structurally proven **and** observed executing in ingested traces. |
|
|
537
|
+
| **`NOT_OBSERVED_AT_RUNTIME`** | Present | Not observed | Statically valid edge was not exercised in the recorded trace sample. |
|
|
538
|
+
| **`RUNTIME_ONLY_OBSERVED`** | Dynamic / `UNKNOWN` | Observed | Executed at runtime (e.g., plugin hook, `getattr`, dynamic SQL) where static analysis was `UNKNOWN`. |
|
|
539
|
+
| **`STATIC_RUNTIME_CONFLICT`** | Target A | Target B | Runtime execution dispatched to a different target than static resolution (e.g., dependency override). |
|
|
540
|
+
|
|
541
|
+
### Epistemic Rules for Runtime Evidence
|
|
542
|
+
1. **Runtime Telemetry Is Non-Invasive**: `codegraph run` uses standard environment variable hooks (`NODE_OPTIONS`, `PYTHONSTARTUP`). You never modify application source code.
|
|
543
|
+
2. **`NOT_OBSERVED_AT_RUNTIME` Does Not Mean Dead Code**: It only indicates that the code path was not triggered during the recorded trace window (such as an error branch or periodic batch job).
|
|
544
|
+
3. **Runtime Observations Never Overwrite Static Proof**: Runtime spans are recorded with `evidence_class="RUNTIME_OBSERVED"` and strictly distinguished from `AST_VERIFIED` and `FRAMEWORK_VERIFIED` static edges.
|
|
545
|
+
|
|
546
|
+
---
|
|
547
|
+
|
|
548
|
+
## 8. Epistemic Trust & Evidence Contract
|
|
549
|
+
|
|
550
|
+
CodeGraph MCP enforces a fail-closed evidence contract ([`src/codegraph/evidence_contract.py`](src/codegraph/evidence_contract.py)) across all **51 canonical relationship types** and **9 evidence classes**. CodeGraph MCP prefers **explicit uncertainty** over **fabricated certainty**:
|
|
551
|
+
|
|
552
|
+
```text
|
|
553
|
+
Dynamically resolved target (getattr(handler, action_name)())
|
|
554
|
+
↓
|
|
555
|
+
UNRESOLVED_REFERENCE / POSSIBLE_CALLS (status = "UNKNOWN" | "POSSIBLE")
|
|
556
|
+
(Never fabricated into a verified CALLS edge)
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
| Epistemic Status | Allowed Evidence Classes | What It Means |
|
|
560
|
+
| :--- | :--- | :--- |
|
|
561
|
+
| **`FACT`** | `AST_VERIFIED`, `STATIC_VERIFIED`, `FRAMEWORK_VERIFIED`, `DATAFLOW_VERIFIED` | Proven directly from syntax tree, framework decorator/router semantics, or conservative local dataflow. |
|
|
562
|
+
| **`RUNTIME_OBSERVED`** | `RUNTIME_OBSERVED` | Observed in traces captured by `codegraph run` or ingested OTel/JSONL/SQL logs (`hit_count`, `duration_ms`). |
|
|
563
|
+
| **`POSSIBLE`** | `POSSIBLE` | Plausible candidate relationship (`POSSIBLE_CALLS`, `POSSIBLE_TABLE`) requiring source inspection before mutation. |
|
|
564
|
+
| **`AMBIGUOUS`** | `AMBIGUOUS` | Multiple symbols or database tables match the bare identifier across modules or dialects; returns sorted `candidates`. |
|
|
565
|
+
| **`UNKNOWN`** | `UNKNOWN`, `RUNTIME_UNOBSERVED` | Target cannot be statically proven (dynamic reflection, external dependency, or `reason="resolution_budget_exceeded"`). |
|
|
566
|
+
| **`CONFLICT`** | Static vs. Runtime / Multi-Source | Static analysis and runtime observation (or competing definitions) disagree. |
|
|
567
|
+
|
|
568
|
+
---
|
|
569
|
+
|
|
570
|
+
## 8. Git-Aware Repository Intelligence & Merge Conflict Safety
|
|
571
|
+
|
|
572
|
+
CodeGraph MCP v3.0.0 tracks the exact evolution of repository code across commits, branches, and working tree changes:
|
|
573
|
+
|
|
574
|
+
```text
|
|
575
|
+
Repository state
|
|
576
|
+
↓
|
|
577
|
+
Git change detection (CLEAN / DIRTY / STALE)
|
|
578
|
+
↓
|
|
579
|
+
Structural AST diff (functions, parameters, routes)
|
|
580
|
+
↓
|
|
581
|
+
Downstream impact analysis (callers, callees, tests, DB)
|
|
582
|
+
↓
|
|
583
|
+
Context freshness validation (VALID / PARTIALLY_STALE / STALE)
|
|
584
|
+
↓
|
|
585
|
+
Evidence-backed answer
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### 1. Working Tree & Index Freshness (`codegraph git-state`)
|
|
589
|
+
Tracks current branch, current HEAD commit, indexed commit, and modified/staged files with sub-millisecond status caching:
|
|
590
|
+
```bash
|
|
591
|
+
codegraph git-state
|
|
592
|
+
```
|
|
593
|
+
Never silently serves stale repository facts. Explicitly reports `CLEAN`, `DIRTY`, `STALE`, `REINDEXING`, or `ERROR`.
|
|
594
|
+
|
|
595
|
+
### 2. Deep Visual Downstream Impact Tree (`codegraph git-impact --tree`)
|
|
596
|
+
Traverses affected callers, routes, tests, and DB writers with token-bounded results and visual ASCII hierarchy:
|
|
597
|
+
```bash
|
|
598
|
+
codegraph git-impact --tree
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
### 3. Semantic & Contract Merge Conflicts (`codegraph git-conflicts`)
|
|
602
|
+
Detects silent merge conflicts before git merge or pull request landing—such as branch A invoking a function or route handler that branch B deleted or altered:
|
|
603
|
+
```bash
|
|
604
|
+
codegraph git-conflicts main HEAD
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
### 4. Structural AST Diff (`codegraph git-diff`)
|
|
608
|
+
Computes semantic AST differences between Git revisions (added/removed/modified symbols, changed parameter signatures):
|
|
609
|
+
```bash
|
|
610
|
+
codegraph git-diff HEAD~1 HEAD
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### 5. Deterministic Symbol History (`codegraph symbol-history`)
|
|
614
|
+
Traces symbol lifecycle across commits (introduced, modified, moved, renamed, or deleted):
|
|
615
|
+
```bash
|
|
616
|
+
codegraph symbol-history resolve_target
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### 6. GitHub Action for Pull Request Impact
|
|
620
|
+
Automate change impact directly in your CI pipeline with `.github/workflows/codegraph-pr-impact.yml` and `.github/actions/codegraph-impact/action.yml`.
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
## 9. Measured Performance and Scaling Benchmarks
|
|
625
|
+
|
|
626
|
+
### 4-Tier Scaling Summary (`54` → `2,504` Files)
|
|
627
|
+
|
|
628
|
+
Empirically measured using [`benchmarks/run_v217_indexing_benchmark.py`](benchmarks/run_v217_indexing_benchmark.py) on macOS `arm64`, Python `3.13` with permanent SQLite WAL concurrency:
|
|
629
|
+
|
|
630
|
+
| Workload Tier | Files | Symbols | Graph Edges | Baseline Total | v3.0.0 Measured | Measured Improvement | Peak RSS | Peak WAL | Final WAL |
|
|
631
|
+
| :--- | ---: | ---: | ---: | ---: | ---: | :--- | ---: | ---: | ---: |
|
|
632
|
+
| **Small** | `54` | `115` | `398` | `0.527 s` | `0.447 s` | **15.2% faster (`1.18x`)** | `48.00 MB` | `1.701 MB` | `0.0 MB` |
|
|
633
|
+
| **Medium** | `304` | `615` | `2,248` | `2.564 s` | `2.159 s` | **15.8% faster (`1.19x`)** | `69.72 MB` | `4.082 MB` | `0.0 MB` |
|
|
634
|
+
| **Large** | `1,004` | `2,015` | `7,428` | `8.730 s` | `7.157 s` | **18.0% faster (`1.22x`)** | `127.59 MB` | `5.190 MB` | `0.0 MB` |
|
|
635
|
+
| **Stress** | `2,504` | `5,015` | `18,528` | `21.983 s` | `18.937 s` | **13.9% faster (`1.16x`)** | `233.59 MB` | `6.628 MB` | `0.0 MB` |
|
|
636
|
+
|
|
637
|
+
### Stress Tier (`2,504` Files) Phase Breakdown
|
|
638
|
+
|
|
639
|
+
| Phase / Metric | Legacy Baseline | v3.0.0 Measured | Measured Improvement |
|
|
640
|
+
| :--- | ---: | ---: | :--- |
|
|
641
|
+
| **Total Indexing Time** | `21.983 s` | `18.937 s` | **13.9% faster (`1.16x`)** |
|
|
642
|
+
| **Database Intelligence Pass** | `4.818 s` | `0.893 s` | **81.5% faster (`5.40x`)** |
|
|
643
|
+
| **Post-Processing Phase** | `13.770 s` | `12.061 s` | **12.4% faster (`1.14x`)** |
|
|
644
|
+
| **Symbol Resolution Phase** | `3.133 s` | `1.297 s` | **58.6% faster (`2.42x`)** |
|
|
645
|
+
| **AST Parsing Phase** | `3.410 s` | `3.230 s` | **5.3% faster (`1.06x`)** |
|
|
646
|
+
| **Cold CLI Single-File Re-index** | `4.408 s` | `3.665 s` | **16.9% faster (`1.20x`)** |
|
|
647
|
+
| **Live In-Memory Incremental (`watch`)** | Full scan required | `< 15ms` / file | **Event-driven cache patch** |
|
|
648
|
+
| **Throughput (`files/sec`)** | `113.9 files/s` | `132.2 files/s` | **`+16.1%` throughput** |
|
|
649
|
+
| **Peak SQLite WAL Size** | `46.980 MB` | `6.628 MB` | **85.9% reduction (`7.09x` smaller)** |
|
|
650
|
+
| **Final SQLite WAL Size** | `0.000 MB` | `0.000 MB` | **100% reclaimed (`TRUNCATE`)** |
|
|
651
|
+
|
|
652
|
+
> **Note on Incremental Reindexing**: The **3.665 s** incremental figure measures a cold CLI invocation (`codegraph index .`) on the full 2,504-file repository, traversing file mtimes and checking Git diff state. In contrast, the active background daemon (`codegraph watch`) receives OS kernel filesystem events directly, parsing only the modified file's AST and patching SQLite in **< 15ms**.
|
|
653
|
+
|
|
654
|
+

|
|
655
|
+
|
|
656
|
+
### 50-Task Production Benchmark Results (`v3.0.0`)
|
|
657
|
+
|
|
658
|
+
Evaluated across 50 production tasks and 10 categories via [`benchmarks/run_v21_eval.py`](benchmarks/run_v21_eval.py):
|
|
659
|
+
|
|
660
|
+
| Production Benchmark Metric | Measured Result | Production Target | Status |
|
|
661
|
+
| :--- | :---: | :---: | :---: |
|
|
662
|
+
| **Task Coverage** | **88.0%** | $\ge 80.0\%$ | **PASS** |
|
|
663
|
+
| **Symbol Recall** | **61.9%** | $\ge 50.0\%$ | **PASS** |
|
|
664
|
+
| **FACT Correctness** | **100.0%** | $\ge 98.0\%$ | **PASS** |
|
|
665
|
+
| **Unsupported Claim Rate (Hallucinations)** | **0.0%** | $\le 1.0\%$ | **PASS** |
|
|
666
|
+
| **UNKNOWN Correctness** | **98.0%** | $\ge 95.0\%$ | **PASS** |
|
|
667
|
+
| **AMBIGUITY Correctness** | **100.0%** | $\ge 90.0\%$ | **PASS** |
|
|
668
|
+
| **Average Context Payload** | **510 tokens** | $\le 1,000$ tokens | **PASS** |
|
|
669
|
+
| **Average Context Latency** | **40.52 ms** | $\le 100$ ms | **PASS** |
|
|
670
|
+
| **Token Reduction vs Full-File Extraction** | **41.8%** | $\ge 35.0\%$ | **PASS** |
|
|
671
|
+
|
|
672
|
+
### 32-Task A/B Exploration Evaluation ([`src/codegraph/tool_selection_eval.py`](src/codegraph/tool_selection_eval.py))
|
|
673
|
+
|
|
674
|
+
Evaluated across 32 agent navigation tasks comparing unassisted grep/file reading vs CodeGraph MCP tool calls:
|
|
675
|
+
|
|
676
|
+
| Metric (32-Task Evaluation Suite) | Mode A (Unassisted Grep & File Reads) | Mode B (CodeGraph MCP) | Measured Improvement |
|
|
677
|
+
| :--- | ---: | ---: | :--- |
|
|
678
|
+
| **Total Tool Calls (32 Tasks)** | `164 calls` (`~5.1 / task`) | `71 calls` (`~2.2 / task`) | **`-56.7% fewer tool calls`** |
|
|
679
|
+
| **Direct Full-File Reads** | `161 full-file reads` | `7 bounded slice reads` | **`-95.7% fewer file reads`** |
|
|
680
|
+
| **Context Tokens per Task** | `3,000 – 12,000+ tokens` | `~510 tokens` avg | **`65.0% – 85.6% token reduction`** |
|
|
681
|
+
| **Query Latency (`p50`)** | Hundreds of ms (multi-step `grep`) | `20.0 ms` cold / `0.67 ms` warm | **Sub-20ms indexed lookup** |
|
|
682
|
+
| **First-Tool Selection Accuracy** | `9.38%` | `100.0%` | **`+90.62%`** |
|
|
683
|
+
| **Unsupported Claims (Hallucinated Edges)** | `11 (34.38%)` | `0 (0.00%)` | **`0% unsupported claims`** |
|
|
684
|
+
| **Task Accuracy** | `59.84%` | `100.0%` | **`+40.16%`** |
|
|
685
|
+
|
|
686
|
+

|
|
687
|
+
|
|
688
|
+
---
|
|
689
|
+
|
|
690
|
+
## 10. Where CodeGraph MCP Fits
|
|
691
|
+
|
|
692
|
+
CodeGraph MCP works **alongside** your editor's language server (LSP), `ripgrep`, and structural AST tools:
|
|
693
|
+
|
|
694
|
+
Legend: `✓` supported • `◐` partial / workflow-dependent • `—` not supported
|
|
695
|
+
|
|
696
|
+
| Capability | CodeGraph MCP (`v3.0.0`) | Editor LSP | Structural AST (`ast-grep`) | Lexical Search (`ripgrep`) | Remote Code Search (`Sourcegraph`) |
|
|
697
|
+
| :--- | :---: | :---: | :---: | :---: | :---: |
|
|
698
|
+
| **100% Local-First & Offline Operation** | ✓ | ✓ | ✓ | ✓ | — |
|
|
699
|
+
| **Native MCP Server for AI Agents** | ✓ (14 default / 70 full) | — | ◐ | — | ✓ |
|
|
700
|
+
| **Multi-Transport Support (stdio + SSE HTTP)** | ✓ | — | — | — | ◐ |
|
|
701
|
+
| **Git-Aware AST Diffs & Freshness** | ✓ (6 Git tools) | — | — | — | ◐ |
|
|
702
|
+
| **Zero-Friction Runtime Interceptor (`codegraph run`)** | ✓ | — | — | — | — |
|
|
703
|
+
| **Semantic Symbol Graph (Callers / Callees)** | ✓ | ◐ (Position-based) | ◐ (Pattern-based) | — | ✓ (SCIP) |
|
|
704
|
+
| **Framework Route, Mount & DI Graph** | ✓ (`FastAPI`/`Flask`/`Django`/`Express`) | — | ◐ (Custom rules) | — | — |
|
|
705
|
+
| **Database Schema, ORM, Migration & Table R/W** | ✓ (11 DB tools) | — | — | — | — |
|
|
706
|
+
| **Opt-In Runtime Ingestion & Reconciliation** | ✓ (OTel / JSONL / SQL) | — | — | — | — |
|
|
707
|
+
| **Explicit Epistemic States (`FACT`/`UNKNOWN`)** | ✓ | — | — | — | — |
|
|
708
|
+
| **Literal Text Search Across HTML/JS/CSS/Config** | ✓ (`search_code`) | — | — | ✓ | ✓ |
|
|
709
|
+
| **Interactive Editor Hover & Diagnostics** | — | ✓ | ✓ (Lint/Rewrite) | — | — |
|
|
710
|
+
|
|
711
|
+

|
|
712
|
+
|
|
713
|
+
---
|
|
714
|
+
|
|
715
|
+
## 11. Security, Privacy & Redaction Boundaries
|
|
716
|
+
|
|
717
|
+
CodeGraph MCP runs **100% locally** (`stdio` / `sse` MCP + local `.codegraph.sqlite3`), never executes repository code during indexing, and enforces strict file-access and redaction boundaries ([`src/codegraph/security/paths.py`](src/codegraph/security/paths.py), [`src/codegraph/security/redaction.py`](src/codegraph/security/redaction.py)):
|
|
718
|
+
|
|
719
|
+
| Security Boundary | Enforcement Mode | Exact Behavior |
|
|
720
|
+
| :--- | :---: | :--- |
|
|
721
|
+
| **Sensitive Files** (`.env`, `*.pem`, `*.key`, `*.crt`, `id_rsa*`, `kubeconfig*`, `.npmrc`, `.pypirc`, `*secret*.json`) | **`BLOCKED`** | Excluded from indexing and FTS; direct inspection via `get_file` or `read_file` is rejected with `SENSITIVE_FILE_ACCESS_DENIED`. |
|
|
722
|
+
| **Path Traversal & Symlinks** (`../`, `%2e%2e`, null bytes, external symlinks) | **`BLOCKED`** | Canonical path check in `resolve_within_repo()` raises `SecurityError(ErrorCode.PATH_OUTSIDE_REPOSITORY)`. |
|
|
723
|
+
| **Binary Files** (`.pyc`, `.so`, `.dylib`, `.dll`, `.exe`, images, archives, PDFs) | **`BLOCKED`** | Classified as `BINARY` and skipped during indexing and text search. |
|
|
724
|
+
| **Environment Variable Reads in Code** (`os.getenv("DATABASE_URL")`) | **Metadata Only** | Records `READS_ENV` with the **variable name only**; never reads `.env` or runtime environment values. |
|
|
725
|
+
| **Database Connection Strings** (`postgresql://user:pass@host:5432/prod`) | **`REDACTED`** | Preserves dialect and database name while sanitizing credentials to `postgresql://[REDACTED]@[REDACTED]/prod`. |
|
|
726
|
+
| **API Keys, Bearer Tokens, JWTs & Private Keys** (`sk-...`, `ghp_...`, `AKIA...`) | **`REDACTED`** | Replaced with `[REDACTED_SECRET]` or `[REDACTED_PRIVATE_KEY]` before indexing, search, or MCP output. |
|
|
727
|
+
| **Runtime HTTP Headers & SQL Literals** (`authorization`, `cookie`, `WHERE password = '...'`) | **`REDACTED`** | Sensitive runtime keys and SQL literals are scrubbed (`[REDACTED]` / `?`) during `ingest_runtime_traces`. |
|
|
728
|
+
|
|
729
|
+
Run `codegraph privacy .` at any time to audit the local database and verify that no sensitive files or unredacted secrets are stored.
|
|
730
|
+
|
|
731
|
+
---
|
|
732
|
+
|
|
733
|
+
## 12. MCP Tooling & Profiles (14 Default / 70 Full)
|
|
734
|
+
|
|
735
|
+
By default, `create_server()` exposes the **14-tool `agent` profile** so AI coding agents receive a focused, non-overlapping tool surface. All 70 tools are available under `--profile full`.
|
|
736
|
+
|
|
737
|
+
### Default `agent` Profile (14 High-Signal Tools)
|
|
738
|
+
|
|
739
|
+
| Category | Tool | Purpose |
|
|
740
|
+
| :--- | :--- | :--- |
|
|
741
|
+
| **Discovery (7)** | `find_symbol` | Locate a symbol definition by short, qualified, or canonical name (`symbol=...`). |
|
|
742
|
+
| | `search_code` | Literal or regex search across Python, JS/TS, HTML/Jinja, CSS, YAML/JSON, Markdown, and SQL. |
|
|
743
|
+
| | `find_references` | Find verified AST reference, import, and registration sites for a symbol. |
|
|
744
|
+
| | `find_callers` | Find functions, methods, or route handlers that call the target symbol (`CALLS`, `POSSIBLE_CALLS`). |
|
|
745
|
+
| | `find_callees` | Find functions, methods, or constructors called by the target symbol. |
|
|
746
|
+
| | `find_tests` | Find `pytest` / `unittest` test functions covering a symbol, route, DI provider, or event handler. |
|
|
747
|
+
| | `find_routes` | Discover FastAPI, Flask, Django, and Express HTTP routes with composed mount prefixes. |
|
|
748
|
+
| **Details & Context (5)** | `get_symbol` | Retrieve signature, decorators, docstring, line range, and methods for a symbol. |
|
|
749
|
+
| | `get_file` | Read bounded line ranges (`start_line`, `end_line`, `max_lines`) and AST symbol outline of a file. |
|
|
750
|
+
| | `get_context` | Compile a token-budgeted, task-aware context packet (`query`, `intent`, `max_tokens`). |
|
|
751
|
+
| | `get_architecture` | Summarize repository languages, layers, packages, entrypoints, routes, and database entities. |
|
|
752
|
+
| | `get_git_impact` | Compute blast-radius impact (`changed_files`, `affected_callers`, `affected_routes`, `tests`) for a Git diff. |
|
|
753
|
+
| **Graph Tracing (2)** | `trace_path` | Find the shortest verified execution path between `from_symbol` and `to_symbol`. |
|
|
754
|
+
| | `trace_flow` | Trace upstream callers and downstream callees around `symbol` up to `depth`. |
|
|
755
|
+
|
|
756
|
+
### All 6 Implemented MCP Profiles ([`src/codegraph/agent_capabilities.py`](src/codegraph/agent_capabilities.py))
|
|
757
|
+
|
|
758
|
+
| Profile | Tool Count | Description |
|
|
759
|
+
| :--- | :---: | :--- |
|
|
760
|
+
| **`agent`** *(default in `create_server`)* | **14** | High-signal discovery, bounded file inspection, context synthesis, and path tracing. |
|
|
761
|
+
| **`core`** | **13** | Lightweight symbol lookup, callers/callees, imports/dependents, routes, and architecture. |
|
|
762
|
+
| **`graph`** | **17** | Call-graph traversal, blast-radius impact (`analyze_impact`), and test discovery. |
|
|
763
|
+
| **`minimal`** | **21** | Core interrogation plus `get_context`, `search_code`, `read_file`, and `verify_evidence`. |
|
|
764
|
+
| **`developer`** | **34** | Interactive development with Git history (`get_file_history`, `get_recent_changes`) and retrieval planning. |
|
|
765
|
+
| **`full`** | **70** | Complete capability surface including **11 Database tools**, **3 Runtime tools**, and **6 Git Intelligence tools** (`get_git_state`, `compare_git`, `get_change_impact`, `check_context_freshness`, `trace_symbol_history`, `detect_semantic_conflicts`). |
|
|
766
|
+
|
|
767
|
+
---
|
|
768
|
+
|
|
769
|
+
## 13. Complete CLI Reference
|
|
770
|
+
|
|
771
|
+
Verified against [`src/codegraph/cli.py`](src/codegraph/cli.py):
|
|
772
|
+
|
|
773
|
+
```bash
|
|
774
|
+
# Agent Onboarding & Uninstall
|
|
775
|
+
codegraph install # Interactive agent detection & setup
|
|
776
|
+
codegraph install --yes --target auto --location local # Non-interactive local setup
|
|
777
|
+
codegraph install --print-config claude # Print MCP JSON + rules for an agent
|
|
778
|
+
codegraph install --dry-run # Preview planned file changes
|
|
779
|
+
codegraph uninstall --yes # Remove CodeGraph MCP agent integrations
|
|
780
|
+
|
|
781
|
+
# Git-Aware Repository Intelligence (v3.0.0)
|
|
782
|
+
codegraph git-state . # Track HEAD, working tree, and freshness (CLEAN/DIRTY/STALE)
|
|
783
|
+
codegraph git-diff HEAD~1 HEAD # Semantic AST diff across commits or branches
|
|
784
|
+
codegraph git-impact --tree # Deep downstream change impact with visual ASCII tree
|
|
785
|
+
codegraph git-conflicts main HEAD # Detect pre-merge semantic & contract conflicts
|
|
786
|
+
codegraph check-freshness "audit auth flow" # Validate if compiled context is VALID or STALE
|
|
787
|
+
codegraph symbol-history resolve_target # Trace deterministic symbol lifecycle across commits
|
|
788
|
+
|
|
789
|
+
# Zero-Friction Runtime Interceptor (v3.0.0)
|
|
790
|
+
codegraph run npm run dev # Wrap Node/Express/Next.js dev server
|
|
791
|
+
codegraph run uvicorn main:app --reload # Wrap FastAPI/ASGI dev server
|
|
792
|
+
codegraph run python manage.py runserver # Wrap Django dev server
|
|
793
|
+
codegraph run --sample-rate 0.5 npm test # Sample 50% of captured traces
|
|
794
|
+
|
|
795
|
+
# Repository Initialization & Indexing
|
|
796
|
+
codegraph init . # Initialize and index repository
|
|
797
|
+
codegraph index . --verbose # Incremental index with 16-phase telemetry
|
|
798
|
+
codegraph index . --json # Output structured JSON phase telemetry
|
|
799
|
+
codegraph uninit --dry-run # Preview removal of .codegraph.sqlite3
|
|
800
|
+
|
|
801
|
+
# Process Lifecycle & Upgrade Lock Safety
|
|
802
|
+
codegraph stop # Safely stop CodeGraph MCP server for current repo
|
|
803
|
+
codegraph stop --all # Stop all CodeGraph-owned MCP processes across repos
|
|
804
|
+
codegraph doctor --processes # Inspect active MCP processes & parent PIDs
|
|
805
|
+
|
|
806
|
+
# Health, Integrity & Freshness Diagnostics
|
|
807
|
+
codegraph status . # Show index freshness (sub-50ms Git fast path)
|
|
808
|
+
codegraph doctor . --database --processes # Verify SQLite integrity, FKs, FTS, and memory
|
|
809
|
+
codegraph privacy . # Verify zero sensitive files indexed
|
|
810
|
+
codegraph version # Print CodeGraph MCP version (3.0.0)
|
|
811
|
+
|
|
812
|
+
# Code, Graph, Routes & Context Interrogation
|
|
813
|
+
codegraph search "authenticate" -r . # Search indexed symbols and text chunks
|
|
814
|
+
codegraph symbols src/codegraph/cli.py -r . # List extracted symbols in a file
|
|
815
|
+
codegraph get-symbol Indexer -r . # Get AST details for a symbol
|
|
816
|
+
codegraph resolve-symbol resolve_Repository -r . # Ground symbol or return candidates
|
|
817
|
+
codegraph trace Indexer -d 2 -r . # Trace callers and callees up to depth 2
|
|
818
|
+
codegraph routes -r . --limit 25 --offset 0 # List routes with bounded pagination
|
|
819
|
+
codegraph architecture -r . # Summarize repository architecture
|
|
820
|
+
codegraph context "trace /api/v1/auth/login" -r . # Compile token-budgeted ContextPacket
|
|
821
|
+
|
|
822
|
+
# MCP Server Subcommands
|
|
823
|
+
codegraph serve . # Start stdio MCP server (14 default tools)
|
|
824
|
+
codegraph serve . --profile full # Start stdio MCP server with all 70 tools
|
|
825
|
+
codegraph serve . --transport sse --port 8765 # Start SSE HTTP server on port 8765
|
|
826
|
+
codegraph mcp serve . --transport sse # Alias for SSE MCP server
|
|
827
|
+
codegraph mcp stop # Stop active MCP processes
|
|
828
|
+
```
|
|
829
|
+
|
|
830
|
+
---
|
|
831
|
+
|
|
832
|
+
## 14. Documentation Map
|
|
833
|
+
|
|
834
|
+
- **Deep Agent Brain & 70-Tool Reference**: [`docs/agent-brain.md`](docs/agent-brain.md)
|
|
835
|
+
- **Compact Tool Capabilities Summary**: [`agent-rules/tool-capabilities-summary.md`](agent-rules/tool-capabilities-summary.md)
|
|
836
|
+
- **Detailed Multi-Tool Capability Comparison**: [`docs/tool-comparison.md`](docs/tool-comparison.md)
|
|
837
|
+
- **Antigravity Skill (`SKILL.md`)**: [`.agents/skills/codegraph/SKILL.md`](.agents/skills/codegraph/SKILL.md)
|
|
838
|
+
- **Agent Rule Packs (`Claude`, `Cursor`, `Antigravity`, `Codex`, `Gemini`, `Cline`)**: [`agent-rules/README.md`](agent-rules/README.md) & [`agent-rules/AGENTS.md`](agent-rules/AGENTS.md)
|
|
839
|
+
- **Engineering & Production Readiness**: [`docs/engineering/production-readiness.md`](docs/engineering/production-readiness.md)
|
|
840
|
+
- **Reproducible Scaling Benchmark Script**: [`benchmarks/run_v217_indexing_benchmark.py`](benchmarks/run_v217_indexing_benchmark.py)
|
|
841
|
+
- **Changelog**: [`CHANGELOG.md`](CHANGELOG.md)
|
|
842
|
+
|
|
843
|
+
---
|
|
844
|
+
|
|
845
|
+
## 15. Contributing & License
|
|
846
|
+
|
|
847
|
+
```bash
|
|
848
|
+
git clone https://github.com/raghurammrsd/CODE_GRAPH_MCP.git
|
|
849
|
+
cd CODE_GRAPH_MCP
|
|
850
|
+
python3 -m venv .venv
|
|
851
|
+
source .venv/bin/activate
|
|
852
|
+
pip install -e ".[dev,mcp,system]"
|
|
853
|
+
|
|
854
|
+
python3 -m ruff check .
|
|
855
|
+
python3 -m mypy src/
|
|
856
|
+
python3 -m pytest -q
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
Licensed under the [MIT License](LICENSE).
|