Skip to main content
Glama

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
NameRequiredDescriptionDefault
projectNoProject name or path
filePathYesFile path (partial match, e.g. 'User.php' or 'src/models')

Implementation Reference

  • 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')"),
      },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/giauphan/codeatlas-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server