findSymbol() — mcp Function Reference
Architecture documentation for the findSymbol() function in symbol-context.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD ad473066_969b_8fc8_45fe_f01051030d72["findSymbol()"] fdc0fb6f_bf66_23e1_e32e_b17145da77c5["handler()"] fdc0fb6f_bf66_23e1_e32e_b17145da77c5 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 8e9da006_7e8b_e75f_f70b_e874951820d2["handler()"] 8e9da006_7e8b_e75f_f70b_e874951820d2 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 9efb304e_755f_f15e_7c58_cd704e785584["searchSymbolHandler()"] 9efb304e_755f_f15e_7c58_cd704e785584 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 29f8c2af_0da8_6d3f_ba3e_184920a85d20["findDefinitionHandler()"] 29f8c2af_0da8_6d3f_ba3e_184920a85d20 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 329942b6_776c_c220_56a7_6ce4c9dda7e3["traceCallsHandler()"] 329942b6_776c_c220_56a7_6ce4c9dda7e3 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 76db10df_f560_1331_9608_6a46d322e405["annotateHandler()"] 76db10df_f560_1331_9608_6a46d322e405 -->|calls| ad473066_969b_8fc8_45fe_f01051030d72 55bde18a_7860_173e_f211_5874970475e3["get()"] ad473066_969b_8fc8_45fe_f01051030d72 -->|calls| 55bde18a_7860_173e_f211_5874970475e3 421d698d_52de_d4ee_ecb4_2ba8e2944350["isCodeSymbol()"] ad473066_969b_8fc8_45fe_f01051030d72 -->|calls| 421d698d_52de_d4ee_ecb4_2ba8e2944350 49a89c8e_8dc3_6de5_6ff0_1662ee08c876["symbolPriority()"] ad473066_969b_8fc8_45fe_f01051030d72 -->|calls| 49a89c8e_8dc3_6de5_6ff0_1662ee08c876 7abbe5d6_99f4_fcf5_0790_2b6478c43254["callerCount()"] ad473066_969b_8fc8_45fe_f01051030d72 -->|calls| 7abbe5d6_99f4_fcf5_0790_2b6478c43254 c652ed9f_2901_0635_2a5b_fc305e9cd6c1["has()"] ad473066_969b_8fc8_45fe_f01051030d72 -->|calls| c652ed9f_2901_0635_2a5b_fc305e9cd6c1 style ad473066_969b_8fc8_45fe_f01051030d72 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/tools/symbol-context.ts lines 161–241
export function findSymbol(graph: IndexedGraph, query: string): CodeGraphNode[] {
const lowerQuery = query.toLowerCase();
// Handle "ClassName.method" syntax
let className: string | null = null;
let methodName: string | null = null;
if (query.includes('.')) {
const parts = query.split('.');
className = parts[0];
methodName = parts.slice(1).join('.');
}
// Strategy 1: Exact name match
const exactIds = graph.nameIndex.get(lowerQuery) || [];
if (exactIds.length > 0) {
return exactIds
.map(id => graph.nodeById.get(id)!)
.filter(n => n && isCodeSymbol(n))
.sort((a, b) => {
const pDiff = symbolPriority(a) - symbolPriority(b);
if (pDiff !== 0) return pDiff;
return callerCount(graph, b) - callerCount(graph, a);
});
}
// Strategy 2: ClassName.method match
if (className && methodName) {
const methodIds = graph.nameIndex.get(methodName.toLowerCase()) || [];
const classIds = graph.nameIndex.get(className.toLowerCase()) || [];
const classFilePaths = new Set(
classIds.map(id => graph.nodeById.get(id)?.properties?.filePath as string).filter(Boolean)
);
const matched = methodIds
.map(id => graph.nodeById.get(id)!)
.filter(n => {
if (!n || !isCodeSymbol(n)) return false;
const fp = n.properties?.filePath as string;
return fp && classFilePaths.has(fp);
});
if (matched.length > 0) {
return matched.sort((a, b) => {
const pDiff = symbolPriority(a) - symbolPriority(b);
if (pDiff !== 0) return pDiff;
return callerCount(graph, b) - callerCount(graph, a);
});
}
}
// Strategy 3: Substring match (for partial names)
if (lowerQuery.length < 2) {
return [];
}
const substringMatches: CodeGraphNode[] = [];
for (const [name, ids] of graph.nameIndex) {
if (name.includes(lowerQuery)) {
for (const id of ids) {
const node = graph.nodeById.get(id);
if (node && isCodeSymbol(node)) {
substringMatches.push(node);
}
}
}
}
// Sort by relevance: exact prefix > contains, then symbol priority, then caller count
substringMatches.sort((a, b) => {
const aName = (a.properties?.name as string || '').toLowerCase();
const bName = (b.properties?.name as string || '').toLowerCase();
const aPrefix = aName.startsWith(lowerQuery) ? 0 : 1;
const bPrefix = bName.startsWith(lowerQuery) ? 0 : 1;
if (aPrefix !== bPrefix) return aPrefix - bPrefix;
const pDiff = symbolPriority(a) - symbolPriority(b);
if (pDiff !== 0) return pDiff;
return callerCount(graph, b) - callerCount(graph, a);
});
return substringMatches.slice(0, 10);
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does findSymbol() do?
findSymbol() is a function in the mcp codebase.
What does findSymbol() call?
findSymbol() calls 5 function(s): callerCount, get, has, isCodeSymbol, symbolPriority.
What calls findSymbol()?
findSymbol() is called by 6 function(s): annotateHandler, findDefinitionHandler, handler, handler, searchSymbolHandler, traceCallsHandler.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free