Skip to main content
Glama

compare_files

Compare two files or directories to identify differences and analyze changes between them.

Instructions

Compare two files or directories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
path1YesFirst path
path2YesSecond path

Implementation Reference

  • The handler implementation of the 'compare_files' tool, which takes two file paths, validates their existence, and performs a comparison.
    async function compareFilesImpl(input: {
      path1: string;
      path2: string;
    }): Promise<ToolResult> {
      try {
        const path1 = path.resolve(input.path1);
        const path2 = path.resolve(input.path2);
    
        const [stats1, stats2] = await Promise.all([
          fs.stat(path1).catch(() => null),
          fs.stat(path2).catch(() => null),
        ]);
    
        if (!stats1) {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'FILE_NOT_FOUND',
                  message: `First path not found: ${input.path1}`,
                }),
              },
            ],
          };
        }
    
        if (!stats2) {
          return {
            isError: true,
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  code: 'FILE_NOT_FOUND',
                  message: `Second path not found: ${input.path2}`,
                }),
              },
            ],
          };
        }
    
        const comparison = {
          path1,
          path2,
          sameType: stats1.isFile() === stats2.isFile(),
          sameSize: stats1.size === stats2.size,
          file1: {
            isFile: stats1.isFile(),
            size: stats1.size,
            sizeFormatted: formatBytes(stats1.size),
            modified: stats1.mtime.toISOString(),
          },
          file2: {
            isFile: stats2.isFile(),
            size: stats2.size,
            sizeFormatted: formatBytes(stats2.size),
            modified: stats2.mtime.toISOString(),
          },
          newerFile: stats1.mtime > stats2.mtime ? 'path1' : 'path2',
          sizeDifference: stats1.size - stats2.size,
          sizeDifferenceFormatted: formatBytes(Math.abs(stats1.size - stats2.size)),
        };
    
        return {
          content: [
            {
  • The registration of the 'compare_files' tool using the server.tool method, including parameter schema and calling the handler.
    // compare_files tool
    server.tool(
      'compare_files',
      'Compare two files or directories',
      {
        path1: z.string().describe('First path'),
        path2: z.string().describe('Second path'),
      },
      async (args) => {
        return await compareFilesImpl(args);
      }
    );
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. 'Compare' implies a read-only operation, but it doesn't specify what aspects are compared (content, metadata, structure), the output format, whether it's recursive for directories, error handling for missing files, or performance characteristics. This leaves significant gaps for agent decision-making.

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 with zero wasted words. It's front-loaded with the core functionality and appropriately sized for a simple comparison tool with only two parameters.

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?

For a comparison tool with no annotations and no output schema, the description is inadequate. It doesn't explain what 'compare' means in practice—whether it returns differences, similarity scores, or just boolean equality. With 2 parameters and behavioral uncertainty, more context about the comparison operation and expected outputs is needed.

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 parameter descriptions ('First path', 'Second path'), so the schema does the heavy lifting. The description adds no additional parameter semantics beyond what's in the schema, maintaining the baseline score for good schema coverage.

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 verb 'compare' and the resources 'two files or directories', making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'file_exists' or 'file_stat' that might also involve file examination, but the comparison function is distinct enough for basic understanding.

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. With siblings like 'file_exists' (checking existence), 'file_stat' (getting metadata), and 'find_by_content' (searching within files), there's no indication of when comparison is the appropriate choice or what specific comparison scenarios it handles.

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/mcp-tool-shop-org/mcp-file-forge'

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