get-unified-diff
Generate unified diff format to compare and analyze differences between two text strings for clear text comparison insights.
Instructions
Get the difference between two text articles in Unified diff format.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| newString | Yes | new string to compare | |
| oldString | Yes | old string to compare |
Implementation Reference
- src/index.ts:62-77 (handler)Handler for the 'get-unified-diff' tool: extracts oldString and newString arguments, validates them, calls generateUnifiedDiff helper, 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:38-51 (schema)Input schema definition for the 'get-unified-diff' tool, specifying oldString and newString as required string properties.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:35-52 (registration)Registration of the 'get-unified-diff' tool in the ListTools response, including name, description, and input schema.{ 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/diffGetter.ts:3-9 (helper)Helper function that generates the unified diff 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 }); }