buildIndexes() — mcp Function Reference
Architecture documentation for the buildIndexes() function in graph-cache.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD f20c71b7_2411_d98b_88ba_3ebc36bdd1f5["buildIndexes()"] 108c9ff4_bdb8_518a_9256_9ff4cd9d39a7["graph-cache.ts"] f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 -->|defined in| 108c9ff4_bdb8_518a_9256_9ff4cd9d39a7 8e2a6102_97e1_76b1_c08e_d7b87f095026["loadCacheFromDisk()"] 8e2a6102_97e1_76b1_c08e_d7b87f095026 -->|calls| f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 0c2dbb97_347e_7226_4d31_fbdcb85ac22b["resolveOrFetchGraph()"] 0c2dbb97_347e_7226_4d31_fbdcb85ac22b -->|calls| f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 5f051fd3_b5fd_05fe_3e0b_f20364a0b064["precacheForDirectory()"] 5f051fd3_b5fd_05fe_3e0b_f20364a0b064 -->|calls| f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 6108b80d_55ab_127a_5edd_034a115a2c42["buildGraph()"] 6108b80d_55ab_127a_5edd_034a115a2c42 -->|calls| f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 4e1e5a38_002c_8f16_1767_0260a7001d5e["set()"] f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 -->|calls| 4e1e5a38_002c_8f16_1767_0260a7001d5e 5b58088c_d9af_5bc6_19ab_1fff095079b9["has()"] f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 -->|calls| 5b58088c_d9af_5bc6_19ab_1fff095079b9 2ef71e67_fa6d_b33f_d005_85a400698718["get()"] f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 -->|calls| 2ef71e67_fa6d_b33f_d005_85a400698718 59a82797_f6a2_36aa_02bd_7b2f22d1bc50["normalizePath()"] f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 -->|calls| 59a82797_f6a2_36aa_02bd_7b2f22d1bc50 style f20c71b7_2411_d98b_88ba_3ebc36bdd1f5 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/cache/graph-cache.ts lines 74–250
export function buildIndexes(raw: SupermodelIR, cacheKey: string): IndexedGraph {
const nodes = raw.graph?.nodes || [];
const relationships = raw.graph?.relationships || [];
// Initialize indexes
const nodeById = new Map<string, CodeGraphNode>();
const labelIndex = new Map<string, string[]>();
const pathIndex = new Map<string, PathIndexEntry>();
const dirIndex = new Map<string, string[]>();
const nameIndex = new Map<string, string[]>();
const callAdj = new Map<string, AdjacencyList>();
const importAdj = new Map<string, AdjacencyList>();
const domainIndex = new Map<string, { memberIds: string[], relationships: CodeGraphRelationship[] }>();
// Build node indexes
for (const node of nodes) {
const id = node.id;
const props = node.properties || {};
const labels = node.labels || [];
// nodeById
nodeById.set(id, node);
// labelIndex
for (const label of labels) {
if (!labelIndex.has(label)) {
labelIndex.set(label, []);
}
labelIndex.get(label)!.push(id);
}
// nameIndex (lowercase for case-insensitive search)
const name = props.name as string | undefined;
if (name) {
const lowerName = name.toLowerCase();
if (!nameIndex.has(lowerName)) {
nameIndex.set(lowerName, []);
}
nameIndex.get(lowerName)!.push(id);
}
// pathIndex - track what's defined in each file
const filePath = props.filePath as string | undefined;
if (filePath) {
const normalized = normalizePath(filePath);
if (!pathIndex.has(normalized)) {
pathIndex.set(normalized, { fileId: '', classIds: [], functionIds: [], typeIds: [] });
}
const entry = pathIndex.get(normalized)!;
const primaryLabel = labels[0];
if (primaryLabel === 'File') {
entry.fileId = id;
} else if (primaryLabel === 'Class') {
entry.classIds.push(id);
} else if (primaryLabel === 'Function') {
entry.functionIds.push(id);
} else if (primaryLabel === 'Type') {
entry.typeIds.push(id);
}
}
// dirIndex - build directory tree
if (labels[0] === 'Directory') {
const dirPath = normalizePath(props.path as string || props.name as string || '');
if (!dirIndex.has(dirPath)) {
dirIndex.set(dirPath, []);
}
}
// Initialize adjacency lists for functions and files
if (labels[0] === 'Function') {
callAdj.set(id, { out: [], in: [] });
}
if (labels[0] === 'File' || labels[0] === 'LocalModule' || labels[0] === 'ExternalModule') {
importAdj.set(id, { out: [], in: [] });
}
// domainIndex
if (labels[0] === 'Domain' || labels[0] === 'Subdomain') {
domainIndex.set(name || id, { memberIds: [], relationships: [] });
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does buildIndexes() do?
buildIndexes() is a function in the mcp codebase, defined in src/cache/graph-cache.ts.
Where is buildIndexes() defined?
buildIndexes() is defined in src/cache/graph-cache.ts at line 74.
What does buildIndexes() call?
buildIndexes() calls 4 function(s): get, has, normalizePath, set.
What calls buildIndexes()?
buildIndexes() is called by 4 function(s): buildGraph, loadCacheFromDisk, precacheForDirectory, resolveOrFetchGraph.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free