Home / Function/ traceCallsHandler() — mcp Function Reference

traceCallsHandler() — mcp Function Reference

Architecture documentation for the traceCallsHandler() function in tool-variants.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  21066345_5e12_0bc2_9825_2a3d68bcb1b7["traceCallsHandler()"]
  05b504b7_268e_7c49_d109_73f7c3744be0["asErrorResult()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| 05b504b7_268e_7c49_d109_73f7c3744be0
  1721f7fd_bb7b_c8c3_9b4b_5677293ae256["resolveOrFetchGraph()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| 1721f7fd_bb7b_c8c3_9b4b_5677293ae256
  2d87a17c_e46f_9198_c263_81d7c3c3054e["findSymbol()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| 2d87a17c_e46f_9198_c263_81d7c3c3054e
  67622b0f_6b47_8f68_bac5_409b3145d2f2["asTextContentResult()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| 67622b0f_6b47_8f68_bac5_409b3145d2f2
  d6ed9355_f977_306b_b0ef_d7220fdefe68["get()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| d6ed9355_f977_306b_b0ef_d7220fdefe68
  6666a1f2_0912_ade3_4b0e_42190c41cd97["normalizePath()"]
  21066345_5e12_0bc2_9825_2a3d68bcb1b7 -->|calls| 6666a1f2_0912_ade3_4b0e_42190c41cd97
  style 21066345_5e12_0bc2_9825_2a3d68bcb1b7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/tools/tool-variants.ts lines 176–236

const traceCallsHandler: HandlerFunction = async (client, args, defaultWorkdir) => {
  const name = typeof args?.name === 'string' ? args.name.trim() : '';
  if (!name) {
    return asErrorResult({
      type: 'validation_error',
      message: 'Missing required "name" parameter.',
      code: 'MISSING_NAME',
      recoverable: false,
    });
  }

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

  let graph: IndexedGraph;
  try {
    graph = await resolveOrFetchGraph(client, directory);
  } catch (error: any) {
    return asErrorResult({ type: 'internal_error', message: error.message, code: 'GRAPH_ERROR', recoverable: false });
  }

  const matches = findSymbol(graph, name);
  if (matches.length === 0) {
    return asTextContentResult(`No symbol matching "${name}" found.`);
  }

  const node = matches[0];
  const sym = node.properties?.name as string || '(unknown)';
  const adj = graph.callAdj.get(node.id);
  const lines: string[] = [`## ${sym}`];

  if (adj && adj.in.length > 0) {
    lines.push(`\n**Called by (${adj.in.length}):**`);
    adj.in
      .map(id => graph.nodeById.get(id))
      .filter((n): n is CodeGraphNode => !!n)
      .slice(0, MAX_SYMBOL_CALLERS)
      .forEach(n => {
        const cName = n.properties?.name as string || '?';
        const cFile = normalizePath(n.properties?.filePath as string || '');
        const cLine = n.properties?.startLine as number || 0;
        lines.push(`- \`${cName}\` — ${cFile}:${cLine}`);
      });
  }

  if (adj && adj.out.length > 0) {
    lines.push(`\n**Calls (${adj.out.length}):**`);
    adj.out
      .map(id => graph.nodeById.get(id))
      .filter((n): n is CodeGraphNode => !!n)
      .slice(0, MAX_SYMBOL_CALLEES)
      .forEach(n => {
        const cName = n.properties?.name as string || '?';
        const cFile = normalizePath(n.properties?.filePath as string || '');
        const cLine = n.properties?.startLine as number || 0;
        lines.push(`- \`${cName}\` — ${cFile}:${cLine}`);
      });
  }

  return asTextContentResult(lines.join('\n'));
};

Domain

Subdomains

Frequently Asked Questions

What does traceCallsHandler() do?
traceCallsHandler() is a function in the mcp codebase.
What does traceCallsHandler() call?
traceCallsHandler() calls 6 function(s): asErrorResult, asTextContentResult, findSymbol, get, normalizePath, resolveOrFetchGraph.

Analyze Your Own Codebase

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

Try Supermodel Free