Home / Function/ generateIdempotencyKey() — mcp Function Reference

generateIdempotencyKey() — mcp Function Reference

Architecture documentation for the generateIdempotencyKey() function in api-helpers.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  2bb2b0ae_2fea_7264_08ce_133bb9b7810c["generateIdempotencyKey()"]
  1721f7fd_bb7b_c8c3_9b4b_5677293ae256["resolveOrFetchGraph()"]
  1721f7fd_bb7b_c8c3_9b4b_5677293ae256 -->|calls| 2bb2b0ae_2fea_7264_08ce_133bb9b7810c
  9003922a_3c12_9d09_182b_1d8c2e1893be["precacheForDirectory()"]
  9003922a_3c12_9d09_182b_1d8c2e1893be -->|calls| 2bb2b0ae_2fea_7264_08ce_133bb9b7810c
  style 2bb2b0ae_2fea_7264_08ce_133bb9b7810c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/utils/api-helpers.ts lines 18–54

export function generateIdempotencyKey(directory: string, graphType = 'supermodel'): string {
  const repoName = basename(directory);
  const absolutePath = resolve(directory);

  // Always include path hash to prevent collisions
  const pathHash = createHash('sha1').update(absolutePath).digest('hex').substring(0, 7);

  let hash: string;
  let statusHash = '';

  try {
    // Get git commit hash
    hash = execSync('git rev-parse --short HEAD', {
      cwd: directory,
      encoding: 'utf-8',
    }).trim();

    // Include working tree status in hash to detect uncommitted changes
    const statusOutput = execSync('git status --porcelain', {
      cwd: directory,
      encoding: 'utf-8',
    }).toString();

    if (statusOutput) {
      // Create hash of status output
      statusHash = '-' + createHash('sha1')
        .update(statusOutput)
        .digest('hex')
        .substring(0, 7);
    }
  } catch {
    // Fallback for non-git directories: use path hash as main identifier
    hash = pathHash;
  }

  return `${repoName}-${pathHash}:${graphType}:${hash}${statusHash}`;
}

Domain

Subdomains

Frequently Asked Questions

What does generateIdempotencyKey() do?
generateIdempotencyKey() is a function in the mcp codebase.
What calls generateIdempotencyKey()?
generateIdempotencyKey() is called by 2 function(s): precacheForDirectory, resolveOrFetchGraph.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free