get_file_entities
Extract all defined entities like classes, functions, and variables from a specific code file to analyze its structure and contents.
Instructions
Get all entities (classes, functions, variables) defined in a specific file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | No | Project name or path | |
| filePath | Yes | File path (partial match, e.g. 'User.php' or 'src/models') |
Implementation Reference
- index.ts:317-357 (handler)The handler logic for the 'get_file_entities' MCP tool, which searches for file matches in the analysis graph, groups entities by file, and formats them into a result object.
async ({ project, filePath }) => { const loaded = loadAnalysis(project); if (!loaded) { return { content: [{ type: "text" as const, text: "No analysis data found. Run 'CodeAtlas: Analyze Project' first." }] }; } const q = filePath.toLowerCase().replace(/\\/g, "/"); const matches = loaded.analysis.graph.nodes.filter((n) => { const fp = (n.filePath || n.id).toLowerCase().replace(/\\/g, "/"); return fp.includes(q); }); const links = loaded.analysis.graph.links; const nodeMap = new Map(loaded.analysis.graph.nodes.map((n) => [n.id, n.label])); // Group by file const byFile = new Map<string, typeof matches>(); for (const n of matches) { const fp = n.filePath || "unknown"; if (!byFile.has(fp)) byFile.set(fp, []); byFile.get(fp)!.push(n); } const result = { query: filePath, filesFound: byFile.size, files: Array.from(byFile.entries()).map(([fp, entities]) => ({ filePath: fp, entities: entities.map((e) => ({ name: e.label, type: e.type, line: e.line || null, dependencies: links .filter((l) => l.source === e.id) .map((l) => ({ to: nodeMap.get(l.target) || l.target, type: l.type })), })), })), }; return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } - index.ts:310-316 (registration)Registration of the 'get_file_entities' MCP tool with its schema definition.
server.tool( "get_file_entities", "Get all entities (classes, functions, variables) defined in a specific file.", { project: z.string().optional().describe("Project name or path"), filePath: z.string().describe("File path (partial match, e.g. 'User.php' or 'src/models')"), },