File size: 4,467 Bytes
036a2db
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# DiffContext Web Service β€” Complete Setup Guide

## What you just built

```
diffcontext-service/
β”œβ”€β”€ backend/
β”‚   └── main.py          ← FastAPI REST API server
β”œβ”€β”€ frontend/
β”‚   └── index.html       ← Web UI (open in browser, no server needed)
β”œβ”€β”€ mcp/
β”‚   └── mcp_server.py    ← MCP server for Claude Desktop / Cursor
└── README.md            ← This file
```

---

## Option A β€” Web UI (easiest, for beginners)

### Step 1: Install dependencies
```bash
pip install fastapi uvicorn python-multipart aiofiles
```

### Step 2: Start the API server
```bash
cd /path/to/Diffcontext
uvicorn diffcontext-service.backend.main:app --reload --port 8000
```

### Step 3: Open the web UI
Just open `diffcontext-service/frontend/index.html` in your browser.
(Double-click it, or drag it into Chrome/Firefox.)

### Step 4: Use it
1. Zip your Python project folder
2. Upload the zip on the "Upload Project" tab
3. Pick a function from the list
4. Click "Analyse Blast Radius"
5. See what breaks!

---

## Option B β€” REST API (for developers)

Once the server is running at `http://localhost:8000`:

```python
import requests

# 1. Upload your project
with open("myproject.zip", "rb") as f:
    r = requests.post("http://localhost:8000/upload", files={"file": f})
repo_id = r.json()["repo_id"]

# 2. List all functions
r = requests.get(f"http://localhost:8000/symbols?repo_id={repo_id}")
print(r.json()["symbols"][:5])

# 3. Get blast radius
r = requests.post("http://localhost:8000/blast", json={
    "repo_id": repo_id,
    "symbol": "./src/auth.py:validate_jwt"
})
print(r.json())

# 4. Get LLM context to paste into Claude
r = requests.post("http://localhost:8000/compile", json={
    "repo_id": repo_id,
    "symbol": "./src/auth.py:validate_jwt",
    "max_tokens": 8000
})
print(r.json()["context_text"])
```

### Or use curl:
```bash
# Upload
curl -X POST http://localhost:8000/upload -F "file=@myproject.zip"

# Blast radius
curl -X POST http://localhost:8000/blast \
  -H "Content-Type: application/json" \
  -d '{"repo_id": "abc123", "symbol": "./main.py:my_function"}'

# Paste code directly (no upload)
curl -X POST http://localhost:8000/inline \
  -H "Content-Type: application/json" \
  -d '{
    "files": {"main.py": "def greet(name):\n  msg = build_message(name)\n  print(msg)\n\ndef build_message(name):\n  return f\"Hello {name}\""},
    "symbol": "./main.py:greet"
  }'
```

Interactive docs: http://localhost:8000/docs

---

## Option C β€” MCP Server (Claude Desktop / Cursor)

This lets Claude Desktop call DiffContext automatically β€” no copy-paste needed.

### Step 1: Install MCP
```bash
pip install mcp
```

### Step 2: Find the full path to mcp_server.py
```bash
# Mac/Linux
realpath diffcontext-service/mcp/mcp_server.py

# Windows
cd diffcontext-service\mcp && echo %CD%\mcp_server.py
```

### Step 3: Add to Claude Desktop config

**Mac:** `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`

```json
{
  "mcpServers": {
    "diffcontext": {
      "command": "python",
      "args": ["/FULL/PATH/TO/diffcontext-service/mcp/mcp_server.py"]
    }
  }
}
```

### Step 4: Restart Claude Desktop

### Step 5: Use it in Claude Desktop
```
"List all functions in /Users/me/myproject"

"What is the blast radius of ./src/auth.py:validate_jwt 
 in /Users/me/myproject?"

"I'm about to change create_user in /Users/me/myproject.
 Compile context so I can understand the impact."
```

Claude will call DiffContext automatically and show you the results.

---

## Troubleshooting

| Problem | Fix |
|---------|-----|
| `Connection refused` on localhost:8000 | Run the uvicorn command first |
| `No Python files found` | Make sure your zip contains .py files |
| Symbol not found | Use format `./filename.py:function_name` (no parentheses) |
| MCP not working | Check the full path in claude_desktop_config.json |
| `ModuleNotFoundError: mcp` | Run `pip install mcp` |

---

## API response format

```json
{
  "symbol": "./service.py:onboard_user",
  "direct_callers": ["./api.py:handle_signup"],
  "direct_callees": ["./service.py:create_user", "./service.py:create_order"],
  "blast_radius_count": 5,
  "blast_radius_by_file": {
    "./api.py": ["handle_signup", "process_request"],
    "./tests/test_service.py": ["test_onboard"]
  },
  "all_affected": ["./api.py:handle_signup", ...],
  "total_symbols_in_repo": 47
}
```