feat(web): expose get_diff on MCP server#1142
Conversation
Add a new get_diff MCP tool backed by the existing git diff API so agents can request structured diffs between refs. Document the tool in MCP docs with parameters aligned to the public API spec. Made-with: Cursor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
This comment has been minimized.
This comment has been minimized.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
WalkthroughAdds a new MCP tool Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant MCP as MCP Server
participant Tool as get_diff Tool
participant DiffSvc as Diff Service
Client->>MCP: Request get_diff(repo, base, head)
MCP->>Tool: invoke handler with params
Tool->>DiffSvc: getDiff(repo, base, head)
DiffSvc-->>Tool: diff result / error
alt success
Tool-->>MCP: return JSON output + metadata
MCP-->>Client: 200 + diff payload
else service error
Tool-->>MCP: throw Error(response.message)
MCP-->>Client: 5xx error
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Document the new MCP get_diff capability under Unreleased using the repository changelog format and PR link. Made-with: Cursor
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/web/src/features/tools/getDiff.ts (1)
21-39: Consider size limits for large diffs.
JSON.stringify(response)returns the full diff with no truncation or size cap. For largebase..headranges this could produce very large outputs that exceed MCP client limits or consume excessive tokens. Consider adding a max file/hunk cap or a size guard, similar to thelimitparameters on other tools (grep,glob,list_commits).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/web/src/features/tools/getDiff.ts` around lines 21 - 39, The execute handler currently returns the full diff (JSON.stringify(response)) which can be arbitrarily large; update the execute implementation in getDiff.ts (the execute function that calls getDiff and uses isServiceError) to enforce a size/entry cap: either pass a new limit parameter into getDiff (e.g., file/hunk limit) or truncate the response before stringifying (e.g., keep first N files/hunks and set a truncated=true flag), and include metadata that indicates truncation along with repo/base/head; ensure you still throw on isServiceError(response) and preserve the existing metadata merge but replace output with the capped/truncated JSON to avoid oversized payloads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/web/src/features/tools/getDiff.ts`:
- Around line 21-39: The execute handler currently returns the full diff
(JSON.stringify(response)) which can be arbitrarily large; update the execute
implementation in getDiff.ts (the execute function that calls getDiff and uses
isServiceError) to enforce a size/entry cap: either pass a new limit parameter
into getDiff (e.g., file/hunk limit) or truncate the response before
stringifying (e.g., keep first N files/hunks and set a truncated=true flag), and
include metadata that indicates truncation along with repo/base/head; ensure you
still throw on isServiceError(response) and preserve the existing metadata merge
but replace output with the capped/truncated JSON to avoid oversized payloads.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 53057228-4605-4cf8-8dea-8558c9bc0381
📒 Files selected for processing (5)
docs/docs/features/mcp-server.mdxpackages/web/src/features/mcp/server.tspackages/web/src/features/tools/getDiff.tspackages/web/src/features/tools/getDiff.txtpackages/web/src/features/tools/index.ts
Register get_diff in the Ask agent toolset and render its output in the details panel so chat workflows can compare refs directly. Made-with: Cursor
Fixes SOU-968
Summary
get_diffMCP tool that returns structured git diff data betweenbaseandheadget_diffin the Sourcebot MCP server toolsetget_diffin MCP docs with parameters aligned to the public API diff schemaTest plan
yarn workspace @sourcebot/web lintget_diffwithrepo,base,headget_diffformain~1..mainand verify non-empty diff outputget_diffoutput forHEAD~5..HEADwithgit difffile set and statsMade with Cursor
Summary by CodeRabbit