Skip to main content
Glama
tatn

MCP Server Diff TypeScript

by tatn

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
NameRequiredDescriptionDefault
oldStringYesold string to compare
newStringYesnew string to compare

Implementation Reference

  • 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 }); }
  • 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"] } }
  • 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"] } } ] }; });
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tatn/mcp-server-diff-typescript'

If you have feedback or need assistance with the MCP directory API, please join our Discord server