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
  329942b6_776c_c220_56a7_6ce4c9dda7e3["traceCallsHandler()"]
  ac037c5b_e159_85ae_5dd7_8b0efd91626f["asErrorResult()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| ac037c5b_e159_85ae_5dd7_8b0efd91626f
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  ad473066_969b_8fc8_45fe_f01051030d72["findSymbol()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72
  46063d5f_ce29_e424_cd46_c460531d27b6["asTextContentResult()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| 46063d5f_ce29_e424_cd46_c460531d27b6
  55bde18a_7860_173e_f211_5874970475e3["get()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| 55bde18a_7860_173e_f211_5874970475e3
  d16dc47a_bbc0_2745_401a_8a4d3b67257e["normalizePath()"]
  329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| d16dc47a_bbc0_2745_401a_8a4d3b67257e
  style 329942b6_776c_c220_56a7_6ce4c9dda7e3 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