Home / Function/ findDefinitionHandler() — mcp Function Reference

findDefinitionHandler() — mcp Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  29f8c2af_0da8_6d3f_ba3e_184920a85d20["findDefinitionHandler()"]
  ac037c5b_e159_85ae_5dd7_8b0efd91626f["asErrorResult()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| ac037c5b_e159_85ae_5dd7_8b0efd91626f
  b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb
  ad473066_969b_8fc8_45fe_f01051030d72["findSymbol()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72
  46063d5f_ce29_e424_cd46_c460531d27b6["asTextContentResult()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| 46063d5f_ce29_e424_cd46_c460531d27b6
  d16dc47a_bbc0_2745_401a_8a4d3b67257e["normalizePath()"]
  29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| d16dc47a_bbc0_2745_401a_8a4d3b67257e
  style 29f8c2af_0da8_6d3f_ba3e_184920a85d20 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/tools/tool-variants.ts lines 113–150

const findDefinitionHandler: 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.`);
  }

  // Ultra-compact: just location lines
  const lines = matches.slice(0, 5).map(node => {
    const sym = node.properties?.name as string || '(unknown)';
    const fp = normalizePath(node.properties?.filePath as string || '');
    const start = node.properties?.startLine as number || 0;
    const end = node.properties?.endLine as number || 0;
    const kind = node.labels?.[0]?.toLowerCase() || 'symbol';
    return `${sym} (${kind}) — ${fp}:${start}-${end}`;
  });

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

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free