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"]
            }
          }
        ]
      };
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the output format ('Unified diff format') but lacks details on error handling, performance characteristics, or any constraints (e.g., input size limits). For a tool with no annotations, this leaves significant gaps in understanding how it behaves beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's function without unnecessary words. It is front-loaded with the core purpose and includes the output format, making it easy to understand quickly. Every part of the sentence contributes essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (comparing two strings) and no output schema, the description is adequate but incomplete. It covers the basic purpose and output format but lacks details on behavioral aspects like error cases or performance. Without annotations, it should do more to compensate, but it meets the minimum viable threshold for a simple diff tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, with clear descriptions for both parameters ('old string to compare' and 'new string to compare'). The description adds minimal value beyond the schema by implying the parameters are text articles, but it doesn't provide additional context like format expectations or examples. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get the difference between two text articles in Unified diff format.' It specifies the verb ('Get'), resource ('difference'), and output format ('Unified diff format'), making the function unambiguous. However, since there are no sibling tools, it doesn't need to differentiate from alternatives, so it doesn't reach the highest score of 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It states what the tool does but offers no context about scenarios where it's appropriate, prerequisites, or limitations. With no sibling tools, it could implicitly suggest this is the only diff tool, but explicit usage guidelines are missing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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