Skip to main content
Glama

semantic_navigate

Navigate codebases by semantic meaning instead of directory structure. Groups related files into labeled clusters using spectral clustering on embeddings to understand code organization.

Instructions

Browse the codebase by MEANING, not directory structure. Uses spectral clustering on Ollama embeddings to group semantically related files into labeled clusters. Inspired by Gabriella Gonzalez's semantic navigator. Requires Ollama running with an embedding model and a chat model for labeling.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_depthNoMaximum nesting depth of clusters. Default: 3.
max_clustersNoMaximum sub-clusters per level. Default: 20.

Implementation Reference

  • The main handler function for the `semantic_navigate` tool, which orchestrates file walking, analysis, embedding, clustering, and tree rendering.
    export async function semanticNavigate(options: SemanticNavigateOptions): Promise<string> {
      const maxClusters = options.maxClusters ?? 20;
      const maxDepth = options.maxDepth ?? 3;
    
      const entries = await walkDirectory({ rootDir: options.rootDir, depthLimit: 0 });
      const fileEntries = entries.filter((e) => !e.isDirectory && isNavigableSourceCandidate(e.path));
    
      if (fileEntries.length === 0) return "No supported source files found in the project.";
    
      const files: FileInfo[] = [];
      for (const entry of fileEntries) {
        try {
          const content = await readFile(entry.path, "utf-8");
          let header = extractHeader(content);
          let symbolPreview: string[] = [];
          try {
            const analysis = await analyzeFile(entry.path);
            if (analysis.header) header = analysis.header;
            symbolPreview = flattenSymbols(analysis.symbols)
              .slice(0, 3)
              .map((s) => `${s.name}@${formatLineRange(s.line, s.endLine)}`);
          } catch {
          }
          files.push({
            relativePath: entry.relativePath,
            header,
            content: content.substring(0, 500),
            symbolPreview,
          });
        } catch {
        }
      }
    
      if (files.length === 0) return "Could not read any source files.";
    
      let embeddableFiles: FileInfo[] = files;
      let vectors: number[][] = [];
      let skippedForEmbedding = 0;
      try {
        const embedded = await embedFilesWithFallback(files);
        embeddableFiles = embedded.files;
        vectors = embedded.vectors;
        skippedForEmbedding = embedded.skipped;
      } catch (err) {
        return `Ollama not available for embeddings: ${err instanceof Error ? err.message : String(err)}\nMake sure Ollama is running or signed in (ollama signin) with model ${EMBED_MODEL}.`;
      }
    
      if (embeddableFiles.length === 0) return "No embeddable source files found in the project.";
    
      if (embeddableFiles.length <= MAX_FILES_PER_LEAF) {
        let fileLabels: string[];
        try {
          const prompt = `For each file below, produce a 3-7 word description. Return ONLY a JSON array of strings.\n\n${embeddableFiles.map((f) => `${f.relativePath}: ${f.header}`).join("\n")}`;
          const response = await chatCompletion(prompt);
          const match = response.match(/\[[\s\S]*\]/);
          fileLabels = match ? JSON.parse(match[0]) : embeddableFiles.map((f) => f.header);
        } catch {
          fileLabels = embeddableFiles.map((f) => f.header);
        }
    
        const summary = skippedForEmbedding > 0
          ? `Semantic Navigator: ${embeddableFiles.length} files (${skippedForEmbedding} skipped due embedding limits)\n`
          : `Semantic Navigator: ${embeddableFiles.length} files\n`;
        const lines = [summary];
        for (let i = 0; i < embeddableFiles.length; i++) {
          const symbols = embeddableFiles[i].symbolPreview.length > 0 ? ` | symbols: ${embeddableFiles[i].symbolPreview.join(", ")}` : "";
          lines.push(`  ${embeddableFiles[i].relativePath} - ${fileLabels[i] || embeddableFiles[i].header}${symbols}`);
        }
        return lines.join("\n");
      }
    
      const tree = await buildHierarchy(embeddableFiles, vectors, maxClusters, 0, maxDepth);
      tree.label = "Project";
    
      const summary = skippedForEmbedding > 0
        ? `Semantic Navigator: ${embeddableFiles.length} files organized by meaning (${skippedForEmbedding} skipped due embedding limits)`
        : `Semantic Navigator: ${embeddableFiles.length} files organized by meaning`;
    
      return `${summary}\n\n${renderClusterTree(tree)}`;
    }
  • Input schema for the `semantic_navigate` tool.
    export interface SemanticNavigateOptions {
      rootDir: string;
      maxDepth?: number;
      maxClusters?: number;
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It successfully discloses the algorithm (spectral clustering on Ollama embeddings), output structure (labeled clusters), and critical external dependency (requires Ollama with specific models). Lacks explicit read-only safety declaration or error handling details, but covers the essential behavioral traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Four well-structured sentences: value proposition, technical mechanism, attribution, and requirements. Each earns its place, though the Gabriella Gonzalez reference adds conceptual rather than operational value. No redundancy or wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Strong coverage for a complex ML-based tool: explains the 'why' (meaning over structure), 'how' (spectral clustering), and prerequisites (Ollama). Absence of output schema is partially mitigated by describing 'labeled clusters', though specific return format details would strengthen it further.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so parameters are fully documented in the schema. The description adds no parameter-specific guidance, but with complete schema documentation, baseline 3 is appropriate—the schema carries the weight.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Excellent specificity: 'Browse the codebase by MEANING' establishes the verb and resource, while 'not directory structure' explicitly contrasts with structural navigation. The spectral clustering mechanism further clarifies the semantic approach, clearly distinguishing it from keyword search or file-tree traversal.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides implicit context ('by MEANING, not directory structure') suggesting when to use it, but fails to explicitly contrast with semantic siblings like 'semantic_code_search' or 'semantic_identifier_search'. No explicit 'when not to use' guidance or prerequisites beyond Ollama runtime.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/ForLoopCodes/contextplus'

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