get-unified-diff
Generate unified diff output to compare text changes between old and new string versions for analysis.
Instructions
Get the difference between two text articles in Unified diff format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| oldString | Yes | old string to compare | |
| newString | Yes | new string to compare |
Implementation Reference
- src/diffGetter.ts:3-9 (handler)The core function that computes the unified diff between two strings using the 'diff' library's diffLines and createPatch functions.export function generateUnifiedDiff(oldString: string, newString: string, oldHeader: string = '', newHeader: string = '', fileName: string = ''): string { const diff = diffLines(oldString, newString); if (diff.length === 1 && !diff[0].added && !diff[0].removed) { return ''; // No change detected } return createPatch(fileName, oldString, newString, oldHeader, newHeader, { context: 3 }); }
- src/index.ts:35-52 (schema)Defines the tool name, description, and input schema for get-unified-diff.{ name: "get-unified-diff", description: "Get the difference between two text articles in Unified diff format.", inputSchema: { type: "object", properties: { oldString: { type: "string", description: "old string to compare" }, newString: { type: "string", description: "new string to compare" } }, required: ["oldString", "newString"] } }
- src/index.ts:62-77 (handler)MCP CallTool request handler that extracts arguments, validates inputs, calls generateUnifiedDiff, and returns the diff result as text content.case "get-unified-diff": { const oldString = String(request.params.arguments?.oldString); const newString = String(request.params.arguments?.newString); if (!oldString || !newString) { throw new Error("oldString and newString are required"); } const diffResult = generateUnifiedDiff(oldString, newString, "", "", ""); return { content: [{ type: "text", text: diffResult }] }; }
- src/index.ts:32-55 (registration)Registers the get-unified-diff tool by defining it in the ListTools response.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "get-unified-diff", description: "Get the difference between two text articles in Unified diff format.", inputSchema: { type: "object", properties: { oldString: { type: "string", description: "old string to compare" }, newString: { type: "string", description: "new string to compare" } }, required: ["oldString", "newString"] } } ] }; });