Skip to main content
Glama
cablate

Simple Document Processing MCP Server

text_diff

Compare two text files to identify differences and generate a detailed diff report for document analysis and version tracking.

Instructions

Compare two text files and show differences

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file1PathYesPath to the first text file
file2PathYesPath to the second text file
outputDirYesDirectory where diff result should be saved

Implementation Reference

  • Implements the text_diff tool: reads two UTF-8 text files, computes line-level differences using the 'diff' library, formats the diff output, and saves it to a new file in the specified output directory.
    export async function compareTexts(
      file1Path: string,
      file2Path: string,
      outputDir: string
    ) {
      try {
        console.error(`Starting text comparison...`);
        console.error(`File 1: ${file1Path}`);
        console.error(`File 2: ${file2Path}`);
        console.error(`Output directory: ${outputDir}`);
    
        // 確保輸出目錄存在
        try {
          await fs.access(outputDir);
          console.error(`Output directory exists: ${outputDir}`);
        } catch {
          console.error(`Creating output directory: ${outputDir}`);
          await fs.mkdir(outputDir, { recursive: true });
          console.error(`Created output directory: ${outputDir}`);
        }
    
        const uniqueId = generateUniqueId();
        const text1 = await fs.readFile(file1Path, "utf-8");
        const text2 = await fs.readFile(file2Path, "utf-8");
    
        const diff = diffLines(text1, text2);
        const diffResult = diff
          .map((part) => {
            const prefix = part.added ? "+ " : part.removed ? "- " : "  ";
            return prefix + part.value;
          })
          .join("");
    
        const outputPath = path.join(outputDir, `diff_${uniqueId}.txt`);
        await fs.writeFile(outputPath, diffResult);
        console.error(`Written diff result to ${outputPath}`);
    
        return {
          success: true,
          data: `Successfully compared texts: ${outputPath}`,
        };
      } catch (error) {
        console.error(`Error in compareTexts:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : "Unknown error",
        };
      }
    }
  • Defines the Tool object for 'text_diff' including name, description, and input schema specifying two file paths and output directory.
    export const TEXT_DIFF_TOOL: Tool = {
      name: "text_diff",
      description: "Compare two text files and show differences",
      inputSchema: {
        type: "object",
        properties: {
          file1Path: {
            type: "string",
            description: "Path to the first text file",
          },
          file2Path: {
            type: "string",
            description: "Path to the second text file",
          },
          outputDir: {
            type: "string",
            description: "Directory where diff result should be saved",
          },
        },
        required: ["file1Path", "file2Path", "outputDir"],
      },
    };
  • src/index.ts:283-300 (registration)
    In the central CallToolRequestSchema handler, dispatches 'text_diff' calls to the compareTexts function, handles the result, and formats the response.
    if (name === "text_diff") {
      const { file1Path, file2Path, outputDir } = args as {
        file1Path: string;
        file2Path: string;
        outputDir: string;
      };
      const result = await compareTexts(file1Path, file2Path, outputDir);
      if (!result.success) {
        return {
          content: [{ type: "text", text: `Error: ${result.error}` }],
          isError: true,
        };
      }
      return {
        content: [{ type: "text", text: fileOperationResponse(result.data) }],
        isError: false,
      };
    }
  • src/index.ts:47-49 (registration)
    Registers the list of all tools (including text_diff via imported tools array) for the ListToolsRequestSchema.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools,
    }));
  • Aggregates and exports the array of all Tool objects, including TEXT_DIFF_TOOL, which is used by the server for listing available tools.
    export const tools = [DOCUMENT_READER_TOOL, PDF_MERGE_TOOL, PDF_SPLIT_TOOL, DOCX_TO_PDF_TOOL, DOCX_TO_HTML_TOOL, HTML_CLEAN_TOOL, HTML_TO_TEXT_TOOL, HTML_TO_MARKDOWN_TOOL, HTML_EXTRACT_RESOURCES_TOOL, HTML_FORMAT_TOOL, TEXT_DIFF_TOOL, TEXT_SPLIT_TOOL, TEXT_FORMAT_TOOL, TEXT_ENCODING_CONVERT_TOOL, EXCEL_READ_TOOL, FORMAT_CONVERTER_TOOL];
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool compares and shows differences, implying a read-only operation, but doesn't clarify if it modifies files, requires specific permissions, handles errors, or details the output format (e.g., saved file type). This leaves significant gaps for a tool with file operations.

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 extremely concise and front-loaded, using a single sentence that directly states the tool's function without any wasted words. Every part of the sentence ('compare two text files and show differences') contributes essential information, making it efficient and easy to parse.

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

Completeness2/5

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

Given the tool's complexity (file comparison with three parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'show differences' entails (e.g., output format, error handling), leaving the agent uncertain about behavioral outcomes. This is inadequate for a tool that interacts with file systems.

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?

Schema description coverage is 100%, with clear descriptions for all three parameters (file paths and output directory). The description adds no additional parameter semantics beyond what the schema provides, such as file format constraints or output specifics. This meets the baseline score since the schema adequately documents parameters.

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 with a specific verb ('compare') and resource ('two text files'), and indicates the output ('show differences'). It distinguishes itself from siblings like text_formatter or text_splitter by focusing on comparison rather than transformation or segmentation. However, it doesn't explicitly differentiate from all siblings (e.g., format_convert might also involve comparisons), keeping it from a perfect score.

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 doesn't mention prerequisites (e.g., file existence), exclusions (e.g., non-text files), or comparisons to siblings like text_formatter for formatting differences. The agent must infer usage solely from the purpose, which is insufficient for optimal tool selection.

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/cablate/mcp-doc-forge'

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