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
  cfff71c5_842d_825f_a41f_4e4cbd45a930["generateIdempotencyKey()"]
  4bef1572_5a60_651d_3247_2779d2e6bd57["api-helpers.ts"]
  cfff71c5_842d_825f_a41f_4e4cbd45a930 -->|defined in| 4bef1572_5a60_651d_3247_2779d2e6bd57
  0c2dbb97_347e_7226_4d31_fbdcb85ac22b["resolveOrFetchGraph()"]
  0c2dbb97_347e_7226_4d31_fbdcb85ac22b -->|calls| cfff71c5_842d_825f_a41f_4e4cbd45a930
  5f051fd3_b5fd_05fe_3e0b_f20364a0b064["precacheForDirectory()"]
  5f051fd3_b5fd_05fe_3e0b_f20364a0b064 -->|calls| cfff71c5_842d_825f_a41f_4e4cbd45a930
  style cfff71c5_842d_825f_a41f_4e4cbd45a930 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}`;
}

Subdomains

Frequently Asked Questions

What does generateIdempotencyKey() do?
generateIdempotencyKey() is a function in the mcp codebase, defined in src/utils/api-helpers.ts.
Where is generateIdempotencyKey() defined?
generateIdempotencyKey() is defined in src/utils/api-helpers.ts at line 18.
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