Spaces:
Running
Running
File size: 8,515 Bytes
a2c1a36 |
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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# MCP HTTP Server Testing Guide
This guide shows how to test your MCP HTTP server on both Windows and Linux systems.
## Prerequisites
- MCP server running on `http://localhost:8001/mcp`
- Bearer token: `local-dev-token` (for local development)
## πͺ Windows Testing (PowerShell)
### Test 1: Initialize Connection
```powershell
# Set up headers
$headers = @{
"Authorization" = "Bearer local-dev-token"
"Content-Type" = "application/json"
"Accept" = "application/json, text/event-stream"
}
# Create initialize request body
$body = @{
jsonrpc = "2.0"
id = 1
method = "initialize"
params = @{
protocolVersion = "2024-11-05"
capabilities = @{}
clientInfo = @{
name = "test-client"
version = "1.0.0"
}
}
} | ConvertTo-Json -Depth 10
# Send request
Invoke-RestMethod -Uri "http://localhost:8001/mcp" -Method POST -Headers $headers -Body $body
```
### Test 2: List Available Tools
```powershell
# Reuse headers from above
$toolsBody = @{
jsonrpc = "2.0"
id = 2
method = "tools/list"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:8001/mcp" -Method POST -Headers $headers -Body $toolsBody
```
### Test 3: Call a Tool (List Notes)
```powershell
$toolCallBody = @{
jsonrpc = "2.0"
id = 3
method = "tools/call"
params = @{
name = "list_notes"
arguments = @{}
}
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Uri "http://localhost:8001/mcp" -Method POST -Headers $headers -Body $toolCallBody
```
### Test 4: Server Status Check
```powershell
# Check if MCP server is running (should return connection info or error)
try {
Invoke-RestMethod -Uri "http://localhost:8001/mcp" -Method GET
Write-Host "β
MCP server is running on port 8001"
} catch {
Write-Host "β MCP server not responding on port 8001"
}
# Alternative: Check FastAPI health endpoint (different server on port 8000)
Invoke-RestMethod -Uri "http://localhost:8000/health" -Method GET
```
## π§ Linux Testing (curl + bash)
### Test 1: Initialize Connection
```bash
# Initialize connection
curl -X POST http://localhost:8001/mcp \
-H "Authorization: Bearer local-dev-token" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}'
```
### Test 2: List Available Tools
```bash
curl -X POST http://localhost:8001/mcp \
-H "Authorization: Bearer local-dev-token" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}'
```
### Test 3: Call a Tool (List Notes)
```bash
curl -X POST http://localhost:8001/mcp \
-H "Authorization: Bearer local-dev-token" \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "list_notes",
"arguments": {}
}
}'
```
### Test 4: Server Status Check
```bash
# Check if MCP server is running
curl -f http://localhost:8001/mcp && echo "β
MCP server running" || echo "β MCP server not responding"
# Alternative: Check FastAPI health endpoint (different server on port 8000)
curl http://localhost:8000/health
```
## π Python Testing Script
### Cross-Platform Python Test
```python
#!/usr/bin/env python3
"""Cross-platform MCP HTTP server test."""
import json
import requests
def test_mcp_server(base_url="http://localhost:8001"):
"""Test MCP server functionality."""
headers = {
"Authorization": "Bearer local-dev-token",
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream"
}
mcp_url = f"{base_url}/mcp"
# Test 1: Initialize
print("π Testing initialize...")
init_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}
response = requests.post(mcp_url, json=init_request, headers=headers)
print(f"Status: {response.status_code}")
print(f"Response: {response.json()}")
# Test 2: List tools
print("\nπ οΈ Testing tools/list...")
tools_request = {
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}
response = requests.post(mcp_url, json=tools_request, headers=headers)
print(f"Status: {response.status_code}")
if response.status_code == 200:
result = response.json()
if "result" in result and "tools" in result["result"]:
tools = result["result"]["tools"]
print(f"Found {len(tools)} tools:")
for tool in tools:
print(f" - {tool['name']}: {tool.get('description', 'No description')}")
if __name__ == "__main__":
test_mcp_server()
```
## π Expected Responses
### Successful Initialize Response
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"protocolVersion": "2024-11-05",
"capabilities": {
"experimental": {},
"prompts": {"listChanged": true},
"resources": {"subscribe": false, "listChanged": true},
"tools": {"listChanged": true}
},
"serverInfo": {
"name": "obsidian-docs-viewer",
"version": "2.13.1"
}
}
}
```
### Available Tools Response
```json
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"tools": [
{
"name": "list_notes",
"description": "List notes in the vault (optionally scoped to a folder)."
},
{
"name": "read_note",
"description": "Read a Markdown note with metadata and body."
},
{
"name": "write_note",
"description": "Create or update a note."
},
{
"name": "delete_note",
"description": "Delete a note and remove it from the index."
},
{
"name": "search_notes",
"description": "Search notes using full-text search with BM25 ranking."
},
{
"name": "get_backlinks",
"description": "List notes that reference the target note."
},
{
"name": "get_tags",
"description": "List tags and associated note counts."
}
]
}
}
```
## π¨ Common Errors and Solutions
### Error: "Missing session ID"
```json
{"jsonrpc":"2.0","id":"server-error","error":{"code":-32600,"message":"Bad Request: Missing session ID"}}
```
**Solution**: This is expected for tools/list and tools/call without proper session management. The initialize method should work.
### Error: "Authorization header required"
```json
{"jsonrpc":"2.0","id":"server-error","error":{"code":-32600,"message":"Authorization header required"}}
```
**Solution**: Make sure you include the Authorization header with Bearer token.
### Error: Connection refused
**Solution**:
1. Check if MCP server is running: `netstat -ano | findstr :8001` (Windows) or `lsof -i :8001` (Linux)
2. Start the server: `python -m src.mcp.server` with `MCP_TRANSPORT=http` and `MCP_PORT=8001`
## π§ Troubleshooting
### Check Server Status
**Windows:**
```powershell
netstat -ano | findstr :8001
```
**Linux:**
```bash
lsof -i :8001
# or
netstat -tlnp | grep :8001
```
### Start MCP Server
**Windows:**
```powershell
cd backend
$env:MCP_TRANSPORT="http"
$env:MCP_PORT="8001"
$env:LOCAL_USER_ID="local-dev"
python -m src.mcp.server
```
**Linux:**
```bash
cd backend
export MCP_TRANSPORT=http
export MCP_PORT=8001
export LOCAL_USER_ID=local-dev
python -m src.mcp.server
```
## π― Testing Checklist
- [ ] Server starts without errors
- [ ] Health endpoint responds: `GET /health`
- [ ] Initialize method works: Returns server info
- [ ] Tools list method works: Returns available tools
- [ ] Bearer token authentication works
- [ ] User isolation works (different tokens = different vaults)
## π Next Steps
1. **For Cursor Integration**: Use STDIO transport in `mcp.json`
2. **For HF Spaces**: Deploy with HTTP transport and JWT authentication
3. **For Production**: Set proper `JWT_SECRET_KEY` and use real JWT tokens
|