The frontend was trying to get function diffs by reading files directly from the filesystem using /api/comparison/diff, which failed with "Not Found" errors because:
- The file paths from the comparison were relative, not absolute
- The Next.js server couldn't access the files
- The frontend wasn't using the MCP server's
get_function_difftool
Created an MCP-based function diff API that proxies to the MCP server.
This route:
- Accepts
comparisonId,functionName, andincludeContent - Calls the MCP server's
get_function_difftool - Parses the MCP response into structured data
- Returns both parsed data and raw text
Usage:
POST /api/mcp/function-diff
{
"comparisonId": "uuid-here",
"functionName": "my_function",
"includeContent": true
}Added new method:
async getFunctionDiffFromMCP(
comparisonId: string,
functionName: string,
includeContent: boolean = true
): Promise<any>Added comparisonId field to ComparisonResult interface:
export interface ComparisonResult {
comparisonId?: string; // MCP comparison ID for getting function diffs
// ... rest of fields
}Modified loadFunctionDiff to:
- Check if
data.comparisonIdis available - If yes, use
diffService.getFunctionDiffFromMCP() - If no, fall back to file-based diff
- Convert MCP diff format to
FileDiffformat for display
Added helper function parseUnifiedDiffToLines() to convert unified diff format to line-by-line format.
- User clicks on a function node in the graph
FunctionGraphViewercallsloadFunctionDiff(node)- If
data.comparisonIdexists:- Calls
/api/mcp/function-diffwith comparison ID and function name - API route calls MCP server's
get_function_difftool - MCP server returns function diff with full content
- Response is converted to
FileDiffformat - Diff is displayed in modal
- Calls
- If no comparison ID:
- Falls back to file-based diff (old behavior)
Frontend → Next.js API Route → MCP Server
← Parsed Response ← JSON-RPC Response
MCP Request:
{
"jsonrpc": "2.0",
"id": 123,
"method": "tools/call",
"params": {
"name": "get_function_diff",
"arguments": {
"comparison_id": "uuid",
"function_name": "my_function",
"include_content": true
}
}
}MCP Response:
{
"jsonrpc": "2.0",
"id": 123,
"result": {
"content": [{
"type": "text",
"text": "Function: my_function\nChange Type: modified\n..."
}]
}
}The frontend needs to be updated to:
- Call the MCP server's
compare_locationstool when creating comparisons - Extract and store the comparison ID from the response
- Pass the comparison ID to the
ComparisonResult
Files to update:
- Where comparisons are initiated (likely in a comparison page or service)
- Need to create an API route that calls MCP's
compare_locations - Store the comparison ID in the result
Create nextjs-frontend/src/app/api/mcp/compare/route.ts:
POST /api/mcp/compare
{
"sourcePath": "/path/to/source",
"targetPath": "/path/to/target",
"recursive": true
}
Response:
{
"comparisonId": "uuid",
"summary": { ... },
"functions": [ ... ]
}Current flow (Rust backend):
Frontend → Rust API → Parser → Comparison Result
New flow (MCP server):
Frontend → Next.js API → MCP Server → Comparison Result (with ID)
→ Store ID
→ Use ID for function diffs
- ✅ No file access issues - MCP server already has the comparison data
- ✅ Complete function content - No truncation (1MB limit)
- ✅ Consistent data - Same source for comparison and diffs
- ✅ Better performance - No need to re-parse files
- ✅ Unified diff format - Proper diff with context
# 1. Create a comparison
curl -s -X POST http://127.0.0.1:8011/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "compare_locations",
"arguments": {
"source_path": "/home/matteius/isp-was-better/driver",
"target_path": "/home/matteius/isp-latest/driver"
}
}
}' | jq -r '.result.content[0].text'
# Note the comparison ID from the output
# 2. Test the Next.js API route
curl -X POST http://localhost:3000/api/mcp/function-diff \
-H "Content-Type: application/json" \
-d '{
"comparisonId": "YOUR_COMPARISON_ID",
"functionName": "vic_framedone_irq_function",
"includeContent": true
}' | jq .Make sure these are set in .env.local:
MCP_SERVER_URL=http://127.0.0.1:8011- Create
/api/mcp/compareroute to initiate comparisons via MCP - Update comparison pages to use MCP for comparisons
- Ensure comparison ID is passed through to graph viewer
- Test end-to-end flow
- Remove old file-based diff code once MCP integration is complete
- ✅ MCP function diff API created
- ✅ DiffService updated with MCP method
- ✅ FunctionGraphViewer updated to use MCP diffs
- ✅ ComparisonResult interface updated
- ⏳ Need to create MCP compare API
- ⏳ Need to update comparison initiation code
- ⏳ Need to test end-to-end flow