Skip to main content
Glama

localnest_search_code

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

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.'
        );
      }
    );

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