handler() — mcp Function Reference
Architecture documentation for the handler() function in symbol-context.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD 8e9da006_7e8b_e75f_f70b_e874951820d2["handler()"] 4646463d_3032_7be4_79ae_2b8f22f309dd["setupHandlers()"] 4646463d_3032_7be4_79ae_2b8f22f309dd -->|calls| 8e9da006_7e8b_e75f_f70b_e874951820d2 ac037c5b_e159_85ae_5dd7_8b0efd91626f["asErrorResult()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| ac037c5b_e159_85ae_5dd7_8b0efd91626f b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb 3d249764_f3e8_1721_0f24_435b6a46d3b1["classifyApiError()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| 3d249764_f3e8_1721_0f24_435b6a46d3b1 ad473066_969b_8fc8_45fe_f01051030d72["findSymbol()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 f0435cd0_6489_6dfd_b2b4_5d96d9d44fe2["renderBriefSymbolContext()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| f0435cd0_6489_6dfd_b2b4_5d96d9d44fe2 bfdd214c_fac6_5f6d_06d3_1828e172d91d["renderSymbolContext()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| bfdd214c_fac6_5f6d_06d3_1828e172d91d 46063d5f_ce29_e424_cd46_c460531d27b6["asTextContentResult()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| 46063d5f_ce29_e424_cd46_c460531d27b6 style 8e9da006_7e8b_e75f_f70b_e874951820d2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/tools/symbol-context.ts lines 78–157
export const handler: HandlerFunction = async (client, args, defaultWorkdir) => {
// Extract symbol list: prefer `symbols` array, fall back to single `symbol`
let symbolList: string[];
const symbolsArg = args?.symbols;
const symbolArg = typeof args?.symbol === 'string' ? args.symbol.trim() : '';
if (Array.isArray(symbolsArg) && symbolsArg.length > 0) {
symbolList = symbolsArg
.filter((s): s is string => typeof s === 'string')
.map(s => s.trim())
.filter(s => s.length > 0)
.slice(0, MAX_BATCH_SYMBOLS);
} else if (symbolArg) {
symbolList = [symbolArg];
} else {
return asErrorResult({
type: 'validation_error',
message: 'Missing required "symbol" or "symbols" parameter.',
code: 'MISSING_SYMBOL',
recoverable: false,
suggestion: 'Provide the name of a function, class, or method to look up.',
});
}
const brief = !!args?.brief;
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 isBatch = symbolList.length > 1;
const useBrief = brief || isBatch;
const allRendered: string[] = [];
for (const sym of symbolList) {
const matches = findSymbol(graph, sym);
if (matches.length === 0) {
allRendered.push(
`## ${sym}\n\nNo symbol matching "${sym}" found in the code graph.`
);
continue;
}
if (useBrief) {
// Brief mode: compact output for each top match
const parts = matches.slice(0, 3).map(node => renderBriefSymbolContext(graph, node));
allRendered.push(parts.join('\n---\n\n'));
if (matches.length > 3) {
allRendered.push(`*... and ${matches.length - 3} more matches for "${sym}".*`);
}
} else {
// Full mode: detailed output (single symbol, not brief)
const parts = await Promise.all(
matches.slice(0, 3).map(node => renderSymbolContext(graph, node, directory))
);
allRendered.push(parts.join('\n---\n\n'));
if (matches.length > 3) {
allRendered.push(`*... and ${matches.length - 3} more matches. Use a more specific name to narrow results.*`);
}
}
}
return asTextContentResult(allRendered.join('\n\n---\n\n'));
};
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does handler() do?
handler() is a function in the mcp codebase.
What does handler() call?
handler() calls 7 function(s): asErrorResult, asTextContentResult, classifyApiError, findSymbol, renderBriefSymbolContext, renderSymbolContext, resolveOrFetchGraph.
What calls handler()?
handler() is called by 1 function(s): setupHandlers.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free