Home / Function/ resolveOrFetchGraph() — mcp Function Reference

resolveOrFetchGraph() — mcp Function Reference

Architecture documentation for the resolveOrFetchGraph() function in graph-cache.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"]
  fdc0fb6f_bf66_23e1_e32e_b17145da77c5["handler()"]
  fdc0fb6f_bf66_23e1_e32e_b17145da77c5 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  d01a6f75_522a_03cd_b386_1c1c752e4564["handler()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  a98010dc_5359_1091_7b2a_e4dcbe99164c["handler()"]
  a98010dc_5359_1091_7b2a_e4dcbe99164c -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  8e9da006_7e8b_e75f_f70b_e874951820d2["handler()"]
  8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  9efb304e_755f_f15e_7c58_cd704e785584["searchSymbolHandler()"]
  9efb304e_755f_f15e_7c58_cd704e785584 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  29f8c2af_0da8_6d3f_ba3e_184920a85d20["findDefinitionHandler()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  329942b6_776c_c220_56a7_6ce4c9dda7e3["traceCallsHandler()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  76db10df_f560_1331_9608_6a46d322e405["annotateHandler()"]
  76db10df_f560_1331_9608_6a46d322e405 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  b0309b0d_ce6c_f9db_7d04_57a3e85e30fc["detectRepo()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| b0309b0d_ce6c_f9db_7d04_57a3e85e30fc
  70a922d5_c50e_1a3c_392a_6e3254c9dff1["generateIdempotencyKey()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 70a922d5_c50e_1a3c_392a_6e3254c9dff1
  55bde18a_7860_173e_f211_5874970475e3["get()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 55bde18a_7860_173e_f211_5874970475e3
  7676d97e_3407_e9fb_36e4_f3398b574ec2["error()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 7676d97e_3407_e9fb_36e4_f3398b574ec2
  52a097f2_598d_df67_e422_55b20a202d95["zipRepository()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 52a097f2_598d_df67_e422_55b20a202d95
  2f679171_fd3f_3cd5_48b2_587cc9ec01fd["buildIndexes()"]
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 2f679171_fd3f_3cd5_48b2_587cc9ec01fd
  style b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/cache/graph-cache.ts lines 582–633

export async function resolveOrFetchGraph(
  client: ClientContext,
  directory: string
): Promise<IndexedGraph> {
  // 1. Pre-computed cache
  const precomputed = detectRepo(directory, _repoMap);
  if (precomputed) return precomputed;

  // 2. LRU cache
  const idempotencyKey = generateIdempotencyKey(directory);
  const cached = graphCache.get(idempotencyKey);
  if (cached) return cached;

  // 3. Fast-fail when API fallback is disabled (e.g. SWE-bench)
  if (_noApiFallback) {
    throw {
      response: null,
      request: null,
      message: 'No pre-computed graph available for this repository. Use grep, find, and file reading to explore the codebase instead.',
      code: 'NO_CACHE',
    };
  }

  // 4. API fallback
  console.error('[Supermodel] Generating codebase graph (this may take a few minutes)...');
  const zipResult = await zipRepository(directory);
  let progressInterval: NodeJS.Timeout | null = null;
  let elapsed = 0;
  progressInterval = setInterval(() => {
    elapsed += 15;
    console.error(`[Supermodel] Analysis in progress... (${elapsed}s elapsed)`);
  }, 15000);

  try {
    const fileBuffer = await fs.readFile(zipResult.path);
    const fileBlob = new Blob([fileBuffer], { type: 'application/zip' });

    const response = await client.graphs.generateSupermodelGraph(
      fileBlob as any,
      { idempotencyKey }
    );

    const graph = buildIndexes(response, idempotencyKey);
    graphCache.set(idempotencyKey, graph);

    console.error('[Supermodel] Analysis complete.');
    return graph;
  } finally {
    if (progressInterval) clearInterval(progressInterval);
    await zipResult.cleanup();
  }
}

Domain

Subdomains

Frequently Asked Questions

What does resolveOrFetchGraph() do?
resolveOrFetchGraph() is a function in the mcp codebase.
What does resolveOrFetchGraph() call?
resolveOrFetchGraph() calls 7 function(s): buildIndexes, detectRepo, error, generateIdempotencyKey, get, set, zipRepository.
What calls resolveOrFetchGraph()?
resolveOrFetchGraph() is called by 8 function(s): annotateHandler, findDefinitionHandler, handler, handler, handler, handler, searchSymbolHandler, traceCallsHandler.

Analyze Your Own Codebase

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

Try Supermodel Free