Home / File/ api-helpers.ts — mcp Source File

api-helpers.ts — mcp Source File

Architecture documentation for api-helpers.ts, a typescript file in the mcp codebase. 5 imports, 3 dependents.

File typescript UtilityLibrary Zipper 5 imports 3 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  4bef1572_5a60_651d_3247_2779d2e6bd57["api-helpers.ts"]
  5c6acde2_5ba8_604f_70ae_120f7b72feaa["types.ts"]
  4bef1572_5a60_651d_3247_2779d2e6bd57 --> 5c6acde2_5ba8_604f_70ae_120f7b72feaa
  d17a98b6_dcea_33cf_f0ff_1917dc2ba557["StructuredError"]
  4bef1572_5a60_651d_3247_2779d2e6bd57 --> d17a98b6_dcea_33cf_f0ff_1917dc2ba557
  a3686edc_9a68_383f_a650_fcb10e778279["child_process"]
  4bef1572_5a60_651d_3247_2779d2e6bd57 --> a3686edc_9a68_383f_a650_fcb10e778279
  b45e6fad_5556_b868_9218_a5f18595c9e0["crypto"]
  4bef1572_5a60_651d_3247_2779d2e6bd57 --> b45e6fad_5556_b868_9218_a5f18595c9e0
  326b2a40_61be_c67e_3a48_e7ce3411f260["path"]
  4bef1572_5a60_651d_3247_2779d2e6bd57 --> 326b2a40_61be_c67e_3a48_e7ce3411f260
  108c9ff4_bdb8_518a_9256_9ff4cd9d39a7["graph-cache.ts"]
  108c9ff4_bdb8_518a_9256_9ff4cd9d39a7 --> 4bef1572_5a60_651d_3247_2779d2e6bd57
  242ec636_ba33_547c_5cb6_5f619c73d099["overview.ts"]
  242ec636_ba33_547c_5cb6_5f619c73d099 --> 4bef1572_5a60_651d_3247_2779d2e6bd57
  ca77ccf4_30df_6b5c_22dc_f7ba42fd0765["symbol-context.ts"]
  ca77ccf4_30df_6b5c_22dc_f7ba42fd0765 --> 4bef1572_5a60_651d_3247_2779d2e6bd57
  style 4bef1572_5a60_651d_3247_2779d2e6bd57 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Shared utilities for API operations across graph tools.
 * Extracted to eliminate code duplication between graph-tools.ts and create-supermodel-graph.ts.
 */

import { execSync } from 'child_process';
import { createHash } from 'crypto';
import { basename, resolve } from 'path';
import { StructuredError } from '../types';

const REPORT_REPO = 'https://github.com/supermodeltools/mcp.git';
const REPORT_SUGGESTION = 'This may be a bug in the MCP server. You can help by opening an issue at https://github.com/supermodeltools/mcp/issues with the error details, or fork the repo and open a PR with a fix.';

/**
 * Generate an idempotency key in format {repo}-{pathHash}:{graphType}:{hash}
 * Includes path hash to prevent collisions between same-named repos
 */
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}`;
}

/**
 * Classify an API error into a structured error response.
 * Extracts HTTP status, network conditions, and timeout signals
 * to produce an agent-actionable error with recovery guidance.
 */
// ... (134 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does api-helpers.ts do?
api-helpers.ts is a source file in the mcp codebase, written in typescript. It belongs to the UtilityLibrary domain, Zipper subdomain.
What functions are defined in api-helpers.ts?
api-helpers.ts defines 2 function(s): classifyApiError, generateIdempotencyKey.
What does api-helpers.ts depend on?
api-helpers.ts imports 5 module(s): StructuredError, child_process, crypto, path, types.ts.
What files import api-helpers.ts?
api-helpers.ts is imported by 3 file(s): graph-cache.ts, overview.ts, symbol-context.ts.
Where is api-helpers.ts in the architecture?
api-helpers.ts is located at src/utils/api-helpers.ts (domain: UtilityLibrary, subdomain: Zipper, directory: src/utils).

Analyze Your Own Codebase

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

Try Supermodel Free