Home / Function/ searchSymbolHandler() — mcp Function Reference

searchSymbolHandler() — mcp Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81["searchSymbolHandler()"]
  05b504b7_268e_7c49_d109_73f7c3744be0["asErrorResult()"]
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 -->|calls| 05b504b7_268e_7c49_d109_73f7c3744be0
  1721f7fd_bb7b_c8c3_9b4b_5677293ae256["resolveOrFetchGraph()"]
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 -->|calls| 1721f7fd_bb7b_c8c3_9b4b_5677293ae256
  2d87a17c_e46f_9198_c263_81d7c3c3054e["findSymbol()"]
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 -->|calls| 2d87a17c_e46f_9198_c263_81d7c3c3054e
  67622b0f_6b47_8f68_bac5_409b3145d2f2["asTextContentResult()"]
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 -->|calls| 67622b0f_6b47_8f68_bac5_409b3145d2f2
  233a620a_de76_be53_26cd_6e06fbe25d41["renderBriefSymbolContext()"]
  0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 -->|calls| 233a620a_de76_be53_26cd_6e06fbe25d41
  style 0c9ec015_a9a0_5ced_2032_d9aa5a5efa81 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/tools/tool-variants.ts lines 49–83

const searchSymbolHandler: HandlerFunction = async (client, args, defaultWorkdir) => {
  const query = typeof args?.query === 'string' ? args.query.trim() : '';
  if (!query) {
    return asErrorResult({
      type: 'validation_error',
      message: 'Missing required "query" parameter.',
      code: 'MISSING_QUERY',
      recoverable: false,
      suggestion: 'Provide the name of a function, class, or method to search for.',
    });
  }

  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, query);
  if (matches.length === 0) {
    return asTextContentResult(`No symbol matching "${query}" found.`);
  }

  // Always brief — keep response small so model doesn't "wait for it"
  const parts = matches.slice(0, 3).map(node => renderBriefSymbolContext(graph, node));
  let result = parts.join('\n---\n\n');
  if (matches.length > 3) {
    result += `\n\n*... and ${matches.length - 3} more matches.*`;
  }
  return asTextContentResult(result);
};

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free