Skip to content

Commit fd95efe

Browse files
sakrutclaude
andcommitted
docs: update README with context command, MCP server, and AI integration guide
Document the new features added in tasks 16-19: context CLI subcommand, Claude Code slash commands, auto-context workflow, and MCP server mode with configuration examples for VS Code, Cursor, and other MCP clients. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 1a38915 commit fd95efe

File tree

1 file changed

+131
-1
lines changed

1 file changed

+131
-1
lines changed

README.md

Lines changed: 131 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ A Roslyn-based static analysis tool for .NET codebases that builds semantic code
1414
- **Natural Language Search** - Query your codebase by intent using cosine similarity on embeddings
1515
- **Drift Detection** - Compare analysis snapshots to detect complexity regressions, new duplicates, and architectural scattering
1616
- **SQLite Storage** - All analysis results persisted to a local SQLite database for querying
17+
- **MCP Server** - Model Context Protocol server for IDE and AI agent integration (VS Code, Cursor, Windsurf)
18+
- **Claude Code Integration** - Slash commands and auto-context for AI-assisted development
1719

1820
## Installation
1921

@@ -75,6 +77,36 @@ ai-code-graph export --format json --concept "validation"
7577
ai-code-graph drift --vs baseline.db --format detail
7678
```
7779

80+
### Method Context (Single-Call Summary)
81+
82+
```bash
83+
# Get compact context for a method: complexity, callers, callees, cluster, duplicates
84+
ai-code-graph context "MyClass.MyMethod"
85+
86+
# Use a specific database
87+
ai-code-graph context "Validate" --db ./ai-code-graph/graph.db
88+
```
89+
90+
Output example:
91+
```
92+
Method: MyApp.Services.UserService.ValidateUser(string)
93+
File: src/Services/UserService.cs:42
94+
Complexity: CC=12 LOC=35 Nesting=3
95+
Callers (3): AuthController.Login, RegistrationService.Register, AdminService.ResetPassword
96+
Callees (2): UserRepository.FindByEmail, PasswordHasher.Verify
97+
Cluster: "user-validation" (5 members, cohesion: 0.82)
98+
Duplicates: AccountService.CheckCredentials (score: 0.91)
99+
```
100+
101+
### MCP Server Mode
102+
103+
```bash
104+
# Start the MCP server (JSON-RPC over stdio)
105+
ai-code-graph mcp --db ./ai-code-graph/graph.db
106+
```
107+
108+
This launches a Model Context Protocol server exposing the code graph as tools for AI agents and IDEs. See [AI Integration](#ai-integration) for configuration details.
109+
78110
### Output Formats
79111

80112
Most commands support `--format` with options: `table` (default), `json`, or `csv` (where applicable).
@@ -88,7 +120,9 @@ By default, the database is stored at `./ai-code-graph/graph.db`. Use `--db <pat
88120
```
89121
ai-code-graph/
90122
├── AiCodeGraph.Cli/ # CLI tool (global tool entry point)
91-
│ └── Program.cs # Command definitions and handlers
123+
│ ├── Program.cs # Command definitions and handlers
124+
│ └── Mcp/ # MCP server (JSON-RPC stdio)
125+
│ └── McpServer.cs # Protocol handler and tool implementations
92126
├── AiCodeGraph.Core/ # Core analysis library
93127
│ ├── Models/ # Data models (CodeGraph, LoadedWorkspace)
94128
│ ├── CallGraph/ # Call graph builder
@@ -101,6 +135,11 @@ ai-code-graph/
101135
│ ├── WorkspaceLoader.cs # Roslyn MSBuild workspace loader
102136
│ └── CodeModelExtractor.cs # Syntax/semantic model extraction
103137
├── AiCodeGraph.Tests/ # Unit and integration tests
138+
├── .claude/commands/ # Claude Code slash commands
139+
│ ├── context.md # /context <method> - method context
140+
│ ├── hotspots.md # /hotspots - complexity hotspots
141+
│ ├── duplicates.md # /duplicates - code clones
142+
│ └── drift.md # /drift - architectural drift
104143
├── tests/fixtures/ # Test fixture solutions
105144
└── .github/workflows/ # CI pipeline
106145
```
@@ -143,6 +182,97 @@ The test suite includes:
143182
- Drift detection tests with file-based databases
144183
- Integration tests that exercise the full pipeline (when MSBuild is available)
145184

185+
## AI Integration
186+
187+
AI Code Graph can be used as a context source for AI coding assistants. It provides architectural awareness — complexity, call relationships, duplicates, and clusters — so AI agents make better-informed edits.
188+
189+
### Claude Code
190+
191+
AI Code Graph ships with Claude Code slash commands in `.claude/commands/`. After analyzing your solution, use these commands inside Claude Code:
192+
193+
| Command | Description |
194+
|---------|-------------|
195+
| `/context <method>` | Get full method context (complexity, callers, callees, cluster, duplicates) before editing |
196+
| `/hotspots` | Show top complexity hotspots as refactoring candidates |
197+
| `/duplicates` | Show detected code clones grouped by type |
198+
| `/drift` | Run drift detection against a saved baseline |
199+
200+
**Setup:**
201+
202+
1. Analyze your solution: `ai-code-graph analyze YourSolution.sln`
203+
2. The slash commands read from `./ai-code-graph/graph.db` by default
204+
3. Use `/context MethodName` before modifying any method to understand its role
205+
206+
**Auto-context (CLAUDE.md):** The project's `CLAUDE.md` instructs Claude Code to automatically run `ai-code-graph context` before modifying methods when the graph database exists. This gives the agent architectural awareness without manual intervention.
207+
208+
### MCP Server (for IDEs and Other AI Agents)
209+
210+
The `mcp` subcommand runs a JSON-RPC stdio server implementing the [Model Context Protocol](https://modelcontextprotocol.io/). This lets VS Code, Cursor, Windsurf, and any MCP-compatible client query the code graph.
211+
212+
**Exposed tools:**
213+
214+
| Tool | Parameters | Description |
215+
|------|-----------|-------------|
216+
| `get_context` | `method` (required) | Compact method summary: complexity, callers, callees, cluster, duplicates |
217+
| `get_hotspots` | `top`, `threshold` (optional) | Top N methods by cognitive complexity |
218+
| `search_code` | `query` (required), `top` (optional) | Natural language code search via embeddings |
219+
| `get_duplicates` | `method`, `threshold`, `top` (optional) | Code clone pairs, optionally filtered to a method |
220+
221+
**Configuration for Claude Code / Cursor (.mcp.json):**
222+
223+
```json
224+
{
225+
"mcpServers": {
226+
"ai-code-graph": {
227+
"type": "stdio",
228+
"command": "ai-code-graph",
229+
"args": ["mcp", "--db", "./ai-code-graph/graph.db"]
230+
}
231+
}
232+
}
233+
```
234+
235+
**Configuration for VS Code (settings.json):**
236+
237+
```json
238+
{
239+
"mcp.servers": {
240+
"ai-code-graph": {
241+
"command": "ai-code-graph",
242+
"args": ["mcp", "--db", "./ai-code-graph/graph.db"]
243+
}
244+
}
245+
}
246+
```
247+
248+
**Usage from any MCP client:**
249+
250+
Once configured, the AI agent can call tools like:
251+
```json
252+
{"tool": "get_context", "arguments": {"method": "UserService.CreateUser"}}
253+
{"tool": "get_hotspots", "arguments": {"top": 10, "threshold": 15}}
254+
{"tool": "search_code", "arguments": {"query": "validate user input"}}
255+
{"tool": "get_duplicates", "arguments": {"threshold": 0.8}}
256+
```
257+
258+
### Standalone CLI for Scripting
259+
260+
All features are available as CLI commands for use in CI pipelines, pre-commit hooks, or custom scripts:
261+
262+
```bash
263+
# Analyze and save baseline in CI
264+
ai-code-graph analyze MySolution.sln --save-baseline
265+
266+
# Fail CI if complexity regresses
267+
ai-code-graph drift --vs baseline.db --format json | jq '.regressions | length'
268+
269+
# Generate hotspot report
270+
ai-code-graph hotspots --top 50 --format csv > hotspots.csv
271+
272+
# Check for new duplicates
273+
ai-code-graph duplicates --threshold 0.9 --format json
274+
```
275+
146276
## License
147277

148278
MIT

0 commit comments

Comments
 (0)