Skip to main content
Glama

compareHashes

Compare two cryptographic hashes in constant time to verify data integrity and detect tampering without timing attacks.

Instructions

Compare two hashes in constant time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hash1YesFirst hash to compare
hash2YesSecond hash to compare

Implementation Reference

  • The handler function that implements the core logic of the 'compareHashes' tool, converting hashes to buffers, checking lengths, and performing constant-time comparison using Buffer.compare to prevent timing attacks.
    handler: async ({ hash1, hash2 }: { hash1: string; hash2: string }) => {
      try {
        // Convert strings to buffers for constant-time comparison
        const buf1 = Buffer.from(hash1);
        const buf2 = Buffer.from(hash2);
    
        // Ensure same length to prevent timing attacks
        if (buf1.length !== buf2.length) {
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                match: false,
                reason: 'Length mismatch'
              }, null, 2)
            }]
          };
        }
    
        // Constant-time comparison
        const match = Buffer.compare(buf1, buf2) === 0;
    
        return {
          content: [{
            type: 'text',
            text: JSON.stringify({
              match,
              hash1Length: buf1.length,
              hash2Length: buf2.length
            }, null, 2)
          }]
        };
      } catch (error) {
        throw new Error(`Hash comparison failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • The input schema defining the required 'hash1' and 'hash2' string parameters for the 'compareHashes' tool.
    inputSchema: {
      type: 'object',
      properties: {
        hash1: {
          type: 'string',
          description: 'First hash to compare'
        },
        hash2: {
          type: 'string',
          description: 'Second hash to compare'
        }
      },
      required: ['hash1', 'hash2']
    },
  • The complete tool definition object for 'compareHashes' exported as part of securityTools, which includes name, description, inputSchema, and handler.
    compareHashes: {
      name: 'compareHashes',
      description: 'Compare two hashes in constant time',
      inputSchema: {
        type: 'object',
        properties: {
          hash1: {
            type: 'string',
            description: 'First hash to compare'
          },
          hash2: {
            type: 'string',
            description: 'Second hash to compare'
          }
        },
        required: ['hash1', 'hash2']
      },
      handler: async ({ hash1, hash2 }: { hash1: string; hash2: string }) => {
        try {
          // Convert strings to buffers for constant-time comparison
          const buf1 = Buffer.from(hash1);
          const buf2 = Buffer.from(hash2);
    
          // Ensure same length to prevent timing attacks
          if (buf1.length !== buf2.length) {
            return {
              content: [{
                type: 'text',
                text: JSON.stringify({
                  match: false,
                  reason: 'Length mismatch'
                }, null, 2)
              }]
            };
          }
    
          // Constant-time comparison
          const match = Buffer.compare(buf1, buf2) === 0;
    
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({
                match,
                hash1Length: buf1.length,
                hash2Length: buf2.length
              }, null, 2)
            }]
          };
        } catch (error) {
          throw new Error(`Hash comparison failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    }
  • src/index.ts:28-35 (registration)
    Registration of the 'compareHashes' tool (via securityTools) into the central allTools object used by the MCP server for tool listing and execution.
    const allTools: ToolKit = {
      ...systemTools,
      ...networkTools,
      ...geoTools,
      ...generatorTools,
      ...dateTimeTools,
      ...securityTools
    };
Behavior3/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 adds valuable context about 'constant time' execution (a security feature to prevent timing attacks), but doesn't disclose other important behaviors like error handling, input validation, or what constitutes a valid hash format. The description doesn't contradict any annotations since none exist.

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 purpose and includes the important 'constant time' qualification. Every word earns its place in this minimal but complete statement.

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 (hash comparison with security implications), no annotations, and no output schema, the description is adequate but has clear gaps. It mentions the constant-time behavior but doesn't explain the comparison result format, error conditions, or hash format requirements. For a security-sensitive operation, more context would be helpful.

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 both parameters clearly documented in the schema. The description doesn't add any parameter-specific information beyond what the schema already provides (both are hashes to compare). The baseline score of 3 is appropriate when the schema does the heavy lifting for parameter documentation.

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

Purpose5/5

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

The description 'Compare two hashes in constant time' clearly states the specific action (compare), the resource (hashes), and a key behavioral characteristic (constant time). It distinguishes from sibling tools like 'hashData' which creates hashes rather than comparing them.

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 use cases like security verification, data integrity checks, or when not to use it (e.g., for non-hash comparisons). No explicit alternatives or context for selection are provided.

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/cyanheads/toolkit-mcp-server'

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