Skip to content

Commit a23c35a

Browse files
committed
feat(web): expose get_diff on MCP server
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
1 parent 48ad44d commit a23c35a

5 files changed

Lines changed: 58 additions & 0 deletions

File tree

docs/docs/features/mcp-server.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ Parameters:
388388
| `ref` | no | Commit SHA, branch or tag name to search on. If not provided, defaults to the default branch. |
389389
| `limit` | no | Maximum number of files to return (default: 100). |
390390

391+
### `get_diff`
392+
393+
Returns a structured diff between two refs in a repository using a two-dot comparison.
394+
395+
Parameters:
396+
| Name | Required | Description |
397+
|:----------|:---------|:--------------------------------------------------------------------------------------------------------------|
398+
| `repo` | yes | The fully-qualified repository name. |
399+
| `base` | yes | The base git ref (branch, tag, or commit SHA) to diff from. |
400+
| `head` | yes | The head git ref (branch, tag, or commit SHA) to diff to. |
401+
391402
### `find_symbol_definitions`
392403

393404
Finds where a symbol (function, class, variable, etc.) is defined in a repository.

packages/web/src/features/mcp/server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { getConfiguredLanguageModelsInfo } from "../chat/utils.server";
1313
import {
1414
findSymbolDefinitionsDefinition,
1515
findSymbolReferencesDefinition,
16+
getDiffDefinition,
1617
listCommitsDefinition,
1718
listReposDefinition,
1819
listTreeDefinition,
@@ -40,6 +41,7 @@ export async function createMcpServer(): Promise<McpServer> {
4041

4142
registerMcpTool(server, grepDefinition, toolContext);
4243
registerMcpTool(server, globDefinition, toolContext);
44+
registerMcpTool(server, getDiffDefinition, toolContext);
4345
registerMcpTool(server, listCommitsDefinition, toolContext);
4446
registerMcpTool(server, listReposDefinition, toolContext);
4547
registerMcpTool(server, readFileDefinition, toolContext);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { getDiff, GetDiffResult } from '@/features/git';
2+
import { getDiffRequestSchema } from '@/features/git/schemas';
3+
import { isServiceError } from '@/lib/utils';
4+
import description from './getDiff.txt';
5+
import { logger } from './logger';
6+
import { ToolDefinition } from './types';
7+
8+
export type GetDiffMetadata = GetDiffResult & {
9+
repo: string;
10+
base: string;
11+
head: string;
12+
};
13+
14+
export const getDiffDefinition: ToolDefinition<'get_diff', typeof getDiffRequestSchema.shape, GetDiffMetadata> = {
15+
name: 'get_diff',
16+
title: 'Get diff',
17+
isReadOnly: true,
18+
isIdempotent: true,
19+
description,
20+
inputSchema: getDiffRequestSchema,
21+
execute: async ({ repo, base, head }, _context) => {
22+
logger.debug('get_diff', { repo, base, head });
23+
24+
const response = await getDiff({ repo, base, head });
25+
26+
if (isServiceError(response)) {
27+
throw new Error(response.message);
28+
}
29+
30+
return {
31+
output: JSON.stringify(response),
32+
metadata: {
33+
...response,
34+
repo,
35+
base,
36+
head,
37+
},
38+
};
39+
},
40+
};
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Returns a structured git diff between two refs in a repository.
2+
3+
Use this tool when you need patch details (added, removed, and context lines) between a base and head revision.
4+
The output includes changed files and hunks with line ranges and diff body content.

packages/web/src/features/tools/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './listCommits';
33
export * from './listRepos';
44
export * from './grep';
55
export * from './glob';
6+
export * from './getDiff';
67
export * from './findSymbolReferences';
78
export * from './findSymbolDefinitions';
89
export * from './listTree';

0 commit comments

Comments
 (0)