Skip to main content
Glama

search_entities

Search for functions, classes, modules, or variables in codebases by name with fuzzy matching to locate specific code entities quickly.

Instructions

Search for functions, classes, modules, or variables by name. Supports fuzzy matching.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectNoProject name or path
queryYesSearch query (case-insensitive, partial match)
typeNoFilter by entity type

Implementation Reference

  • The tool "search_entities" is defined and implemented within index.ts. It processes the project graph analysis to find nodes matching the query, filters them by type, and returns a detailed response including incoming and outgoing relationships.
    server.tool(
      "search_entities",
      "Search for functions, classes, modules, or variables by name. Supports fuzzy matching.",
      {
        project: z.string().optional().describe("Project name or path"),
        query: z.string().describe("Search query (case-insensitive, partial match)"),
        type: z.enum(["all", "module", "class", "function", "variable"]).optional().describe("Filter by entity type"),
      },
      async ({ project, query, type }) => {
        const loaded = loadAnalysis(project);
        if (!loaded) {
          return { content: [{ type: "text" as const, text: "No analysis data found. Run 'CodeAtlas: Analyze Project' first." }] };
        }
    
        let nodes = loaded.analysis.graph.nodes;
        if (type && type !== "all") {
          nodes = nodes.filter((n) => n.type === type);
        }
    
        const q = query.toLowerCase();
        const matches = nodes.filter((n) => n.label.toLowerCase().includes(q));
    
        // For each match, find its relationships
        const links = loaded.analysis.graph.links;
        const nodeMap = new Map(loaded.analysis.graph.nodes.map((n) => [n.id, n.label]));
    
        const result = {
          query,
          matchCount: matches.length,
          results: matches.slice(0, 50).map((n) => {
            const incomingLinks = links
              .filter((l) => l.target === n.id)
              .map((l) => ({ from: nodeMap.get(l.source) || l.source, type: l.type }));
            const outgoingLinks = links
              .filter((l) => l.source === n.id)
              .map((l) => ({ to: nodeMap.get(l.target) || l.target, type: l.type }));
    
            return {
              name: n.label,
              type: n.type,
              filePath: n.filePath || null,
              line: n.line || null,
              incomingRelationships: incomingLinks,
              outgoingRelationships: outgoingLinks,
            };
          }),
        };
    
        return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] };
      }

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