Skip to main content
Glama

Search Code

localnest_search_code
Read-onlyIdempotent

Search text across project files to find exact matches or patterns, returning lines with optional surrounding context for code analysis.

Instructions

Search text across files under a project/root and return matching lines. Best for exact symbol names, imports, or known identifiers. Use use_regex=true for patterns (e.g. "async\s+function\s+get\w+"). Use context_lines to include surrounding lines with each match.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
project_pathNo
all_rootsNo
globNo*
max_resultsNo
case_sensitiveNo
context_linesNo
use_regexNo
response_formatNojson

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataYes
metaNo

Implementation Reference

  • The tool 'localnest_search_code' is registered in 'src/mcp/tools/retrieval.js'. It wraps the 'search.searchCode' method, passing the input parameters to it, and provides a fallback response if no results are found.
    registerJsonTool(
      'localnest_search_code',
      {
        title: 'Search Code',
        description: 'Search text across files under a project/root and return matching lines. Best for exact symbol names, imports, or known identifiers. Use use_regex=true for patterns (e.g. "async\\s+function\\s+get\\w+"). Use context_lines to include surrounding lines with each match.',
        inputSchema: {
          query: z.string().min(1),
          project_path: z.string().optional(),
          all_roots: z.boolean().default(false),
          glob: z.string().default('*'),
          max_results: z.number().int().min(1).max(1000).default(defaultMaxResults),
          case_sensitive: z.boolean().default(false),
          context_lines: z.number().int().min(0).max(10).default(0),
          use_regex: z.boolean().default(false)
        },
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false
        }
      },
      async ({ query, project_path, all_roots, glob, max_results, case_sensitive, context_lines, use_regex }) => {
        const results = search.searchCode({
          query,
          projectPath: project_path,
          allRoots: all_roots,
          glob,
          maxResults: max_results,
          caseSensitive: case_sensitive,
          contextLines: context_lines,
          useRegex: use_regex
        });
        if (results.length > 0) return results;
    
        return withSearchMissResponse(
          results,
          buildSearchMeta({
            tool: 'localnest_search_code',
            query,
            project_path,
            all_roots,
            glob,
            max_results,
            case_sensitive,
            context_lines,
            use_regex
          }),
          'No code matches found in the current scope.',
          [
            'Verify the scope and try a broader query or synonyms.',
            'If you need pattern matching, retry with use_regex=true.'
          ],
          'Retry localnest_search_code with a broader query or use_regex=true, or switch to localnest_search_hybrid for concept lookup.'
        );
      }
    );
Behavior4/5

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

Annotations already declare readOnlyHint=true and idempotentHint=true, so the description doesn't need to cover safety. It adds value by clarifying the return format ('return matching lines') and explaining the contextual behavior of matches ('include surrounding lines'), which annotations don't cover.

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

Conciseness5/5

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

Three sentences, zero waste. Front-loaded with core functionality ('Search text...'), followed immediately by usage guidance ('Best for...'), then parameter-specific tips. Every sentence earns its place with high information density.

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

Completeness3/5

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

Given 9 parameters and 0% schema coverage, the description leaves significant gaps (project_path vs all_roots scoping, glob patterns, response_format implications). While the output schema exists (reducing the need for return value description), the lack of documentation for boolean flags like all_roots and case_sensitive leaves the agent guessing about scoping behavior.

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?

With 0% schema description coverage, the description must carry full parameter documentation. It compensates partially by providing concrete examples for use_regex (regex pattern example) and explaining context_lines, but leaves 7 parameters (project_path, all_roots, glob, max_results, case_sensitive, response_format) completely undocumented with no hints about their interaction or purpose.

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

Purpose4/5

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

The description clearly states the core action ('Search text across files... and return matching lines') with specific verb and resource. The phrase 'Best for exact symbol names, imports, or known identifiers' effectively distinguishes it from semantic or symbol-based siblings like localnest_search_hybrid or localnest_get_symbol, though it could explicitly name those alternatives.

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

Usage Guidelines4/5

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

Provides clear guidance on when to use specific parameters ('Use use_regex=true for patterns', 'Use context_lines to include surrounding lines') and identifies the tool's sweet spot ('Best for exact symbol names'). However, it stops short of explicitly stating when NOT to use this vs. siblings like localnest_find_usages.

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/wmt-mobile/localnest'

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