Home / Function/ handler() — mcp Function Reference

handler() — mcp Function Reference

Architecture documentation for the handler() function in find-connections.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  d01a6f75_522a_03cd_b386_1c1c752e4564["handler()"]
  ac037c5b_e159_85ae_5dd7_8b0efd91626f["asErrorResult()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| ac037c5b_e159_85ae_5dd7_8b0efd91626f
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  3d249764_f3e8_1721_0f24_435b6a46d3b1["classifyApiError()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| 3d249764_f3e8_1721_0f24_435b6a46d3b1
  e52142a6_0c74_4839_4c84_43a05472b3ad["collectDomainMembers()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| e52142a6_0c74_4839_4c84_43a05472b3ad
  46063d5f_ce29_e424_cd46_c460531d27b6["asTextContentResult()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| 46063d5f_ce29_e424_cd46_c460531d27b6
  55bde18a_7860_173e_f211_5874970475e3["get()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| 55bde18a_7860_173e_f211_5874970475e3
  c652ed9f_2901_0635_2a5b_fc305e9cd6c1["has()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| c652ed9f_2901_0635_2a5b_fc305e9cd6c1
  d16dc47a_bbc0_2745_401a_8a4d3b67257e["normalizePath()"]
  d01a6f75_522a_03cd_b386_1c1c752e4564 -->|calls| d16dc47a_bbc0_2745_401a_8a4d3b67257e
  style d01a6f75_522a_03cd_b386_1c1c752e4564 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/tools/find-connections.ts lines 72–166

export const handler: HandlerFunction = async (client, args, defaultWorkdir) => {
  const domainA = typeof args?.domain_a === 'string' ? args.domain_a.trim() : '';
  const domainB = typeof args?.domain_b === 'string' ? args.domain_b.trim() : '';

  if (!domainA || !domainB) {
    return asErrorResult({
      type: 'validation_error',
      message: 'Missing required "domain_a" and/or "domain_b" parameters.',
      code: 'MISSING_DOMAIN',
      recoverable: false,
      suggestion: 'Provide two domain or subdomain names to find connections between.',
    });
  }

  const rawDir = args?.directory as string | undefined;
  const directory = (rawDir && rawDir.trim()) || defaultWorkdir || process.cwd();

  if (!directory || typeof directory !== 'string') {
    return asErrorResult({
      type: 'validation_error',
      message: 'No directory provided and no default workdir configured.',
      code: 'MISSING_DIRECTORY',
      recoverable: false,
      suggestion: 'Provide a directory parameter or start the MCP server with a workdir argument.',
    });
  }

  let graph: IndexedGraph;
  try {
    graph = await resolveOrFetchGraph(client, directory);
  } catch (error: any) {
    return asErrorResult(classifyApiError(error));
  }

  const aNodes = collectDomainMembers(graph, domainA);
  const bNodes = collectDomainMembers(graph, domainB);

  if (aNodes.size === 0) {
    return asTextContentResult(`No functions found in domain/subdomain matching "${domainA}".`);
  }
  if (bNodes.size === 0) {
    return asTextContentResult(`No functions found in domain/subdomain matching "${domainB}".`);
  }

  // Find call edges between domain A and domain B in both directions
  const bridges: string[] = [];

  for (const aId of aNodes) {
    const adj = graph.callAdj.get(aId);
    if (!adj) continue;

    // A calls B (downstream)
    for (const targetId of adj.out) {
      if (!bNodes.has(targetId)) continue;
      const srcNode = graph.nodeById.get(aId);
      const tgtNode = graph.nodeById.get(targetId);
      const srcName = srcNode?.properties?.name as string || '(unknown)';
      const tgtName = tgtNode?.properties?.name as string || '(unknown)';
      const srcFile = normalizePath(srcNode?.properties?.filePath as string || '');
      const tgtFile = normalizePath(tgtNode?.properties?.filePath as string || '');
      bridges.push(
        `\`${srcName}\` (${domainA}) calls \`${tgtName}\` (${domainB}) — ${srcFile} → ${tgtFile}`
      );
    }
  }

  for (const bId of bNodes) {
    const adj = graph.callAdj.get(bId);
    if (!adj) continue;

    // B calls A (reverse direction)
    for (const targetId of adj.out) {
      if (!aNodes.has(targetId)) continue;
      const srcNode = graph.nodeById.get(bId);
      const tgtNode = graph.nodeById.get(targetId);
      const srcName = srcNode?.properties?.name as string || '(unknown)';
      const tgtName = tgtNode?.properties?.name as string || '(unknown)';
      const srcFile = normalizePath(srcNode?.properties?.filePath as string || '');
      const tgtFile = normalizePath(tgtNode?.properties?.filePath as string || '');
      bridges.push(
        `\`${srcName}\` (${domainB}) calls \`${tgtName}\` (${domainA}) — ${srcFile} → ${tgtFile}`
      );
    }
  }

  if (bridges.length === 0) {
    return asTextContentResult(
      `No direct call connections found between "${domainA}" and "${domainB}".`
    );
  }

  return asTextContentResult(
    `Connections between ${domainA} and ${domainB}:\n\n${bridges.join('\n')}`
  );
};

Domain

Subdomains

Frequently Asked Questions

What does handler() do?
handler() is a function in the mcp codebase.
What does handler() call?
handler() calls 8 function(s): asErrorResult, asTextContentResult, classifyApiError, collectDomainMembers, get, has, normalizePath, resolveOrFetchGraph.

Analyze Your Own Codebase

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

Try Supermodel Free