Skip to main content
Glama
paladini

devutils-mcp-server

text_diff

Compare two text strings to identify line-by-line differences, showing additions with '+' and deletions with '-'.

Instructions

Compare two strings and show a simple line-by-line diff. Lines prefixed with '+' are additions, '-' are deletions, ' ' are unchanged.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
text1YesFirst text (original)
text2YesSecond text (modified)

Implementation Reference

  • The implementation of the text_diff tool, including its schema definition and the logic to compare two texts and produce a line-by-line diff.
    server.tool(
      "text_diff",
      "Compare two strings and show a simple line-by-line diff. Lines prefixed with '+' are additions, '-' are deletions, ' ' are unchanged.",
      {
        text1: z.string().describe("First text (original)"),
        text2: z.string().describe("Second text (modified)"),
      },
      async ({ text1, text2 }) => {
        const lines1 = text1.split("\n");
        const lines2 = text2.split("\n");
        const maxLen = Math.max(lines1.length, lines2.length);
        const diffLines: string[] = [];
    
        for (let i = 0; i < maxLen; i++) {
          const l1 = i < lines1.length ? lines1[i] : undefined;
          const l2 = i < lines2.length ? lines2[i] : undefined;
    
          if (l1 === l2) {
            diffLines.push(`  ${l1}`);
          } else {
            if (l1 !== undefined) diffLines.push(`- ${l1}`);
            if (l2 !== undefined) diffLines.push(`+ ${l2}`);
          }
        }
    
        const summary = {
          lines_in_original: lines1.length,
          lines_in_modified: lines2.length,
          additions: diffLines.filter((l) => l.startsWith("+ ")).length,
          deletions: diffLines.filter((l) => l.startsWith("- ")).length,
          unchanged: diffLines.filter((l) => l.startsWith("  ")).length,
        };
    
        const output = `${JSON.stringify(summary, null, 2)}\n\n--- Diff ---\n${diffLines.join("\n")}`;
    
        return { content: [{ type: "text" as const, text: output }] };
      }
    );

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/paladini/devutils-mcp-server'

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