Skip to main content
Glama

Search Codebase via Local Hybrid Lexical Index

search_codebase
Read-onlyIdempotent

Locate functions, classes, and architectural concepts in local repositories via offline hybrid keyword and semantic ranking of code snippets and file locations.

Instructions

Executes private local hybrid search combining BM25 keyword matching and TF-IDF semantic scoring across repository code, distinguishing from 'query_memory_store' and 'build_project_context' by indexing source code identifiers and docstrings rather than querying agent episodic memory or generating context trees.

Parameters:

  • query: Free-text search phrase, function name, class identifier, or concept description to search across the codebase.

  • project_root: Directory path of the repository to index and search; defaults to current working directory.

  • top_k: Maximum count of ranked results to return (integer between 1 and 20; defaults to 5).

Behavior:

  • Mutability: Strictly read-only; queries local files without altering code or persisting external indices on disk.

  • Idempotency: Deterministic; identical queries against the same codebase state produce identical rankings.

  • Privacy & Network: 100% offline local CPU execution; zero remote embedding APIs, cloud billing, or network egress.

  • Performance & Resources: Sub-millisecond query latency (<15ms) across 1,000 files with <35MB RAM footprint; thread-safe.

  • Auth: Zero authentication, API keys, or cloud credentials required.

  • Return Structure: Emits ranked Markdown list with file paths, matching line ranges, relevance scores, and code snippet extracts.

  • Error Handling: Returns clean empty-match notice with suggested query terms if no relevant tokens or symbols match.

Usage Guidelines:

  • When to use: Quickly locate functions, classes, definitions, or architectural concepts in a repository using natural language or symbol names at zero cost.

  • When NOT to use: Do not use for querying persistent agent semantic memory or causal decision graphs (use 'query_memory_store' instead); do not use for building full hierarchical context trees (use 'build_project_context' instead).

Returns: Ranked list of matching code snippets with file paths, line ranges, relevance scores, and matched symbol definitions.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "query": "<query>"
    },
    "name": "search_codebase"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryYesSearch term or natural language description of the code to locate.
top_kNoMaximum number of ranked results to return (default: 5).
project_rootNoRoot directory of the repository to search (default: current directory)..

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv7.3.2
  2. Removedv7.0.1
  3. Addedv7.0.0

TDQS

A4.6/5.0
Behavior4/5

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

The description contributes substantial non-annotation context: zero auth, 100% offline CPU execution with no network egress or billing, sub-15ms latency and RAM footprint, thread-safety, and explicit empty-match error behavior. Some of it merely restates structured hints ("strictly read-only", "deterministic", "offline" echo readOnlyHint, idempotentHint, and openWorldHint=false), which earns no extra credit, but the performance, auth, and failure-mode disclosures are genuinely additive.

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?

It is front-loaded and organized into Purpose, Parameters, Behavior, and Usage blocks, so an agent can scan quickly. It is longer than necessary, though — the trailing "Returns:" line duplicates the "Return Structure" behavior bullet word for word in substance.

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

Completeness5/5

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

For a three-parameter search tool, everything an agent needs to call it correctly is present: scope, defaults, result limits, safety profile, failure behavior, and sibling routing. Return format is covered even though an output schema exists, so there is no gap.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning: `query` accepts natural language, function names, class identifiers, or concept descriptions; `project_root` is explained as the directory that gets indexed, not just searched; and `top_k` is bounded to 1-20, which the schema does not state.

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?

The description opens with a precise verb+resource ("Executes private local hybrid search combining BM25 keyword matching and TF-IDF semantic scoring across repository code") and immediately states how it differs from 'query_memory_store' and 'build_project_context' by indexing source identifiers rather than memory or context trees. An agent can distinguish it from all 19 siblings without opening a schema.

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

Usage Guidelines5/5

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

It has dedicated "When to use" and "When NOT to use" sections, and each exclusion names the correct replacement sibling with the condition that selects it. Nothing about routing is left to inference.

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