Skip to main content
Glama
transparentlyok

MCP Context Manager

search_code

Search for code patterns using regex across files, returning ranked results with minimal context for efficient code navigation and retrieval.

Instructions

⭐ PREFERRED OVER Grep: Search for code patterns with regex support. Returns ranked results with minimal context. Better than Grep because it ranks by relevance and provides AI-optimized output. Use for pattern matching and text search.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesText or regex pattern to search for
filePatternNoOptional: glob pattern to filter files (e.g., "**/*.ts")
maxResultsNoMaximum number of results to return. Default: 10

Implementation Reference

  • The implementation of the `searchCode` method in `Retriever` class, which delegates to `CodeSearchEngine.searchCodePatterns` after filtering files.
    async searchCode(
      pattern: string,
      filePattern?: string,
      maxResults: number = 10
    ): Promise<SearchResult[]> {
      let files = this.indexer.getAllFiles();
    
      // Filter by file pattern if provided
      if (filePattern) {
        files = files.filter(f => this.matchGlob(f.path, filePattern));
      }
    
      // Use advanced pattern search with ranking
      const results = CodeSearchEngine.searchCodePatterns(pattern, files, maxResults);
    
      // Convert to SearchResult format
      return results.map(r => ({
        filePath: r.filePath,
        line: r.line,
        matchedText: r.matchedText,
        context: r.context,
  • src/index.ts:253-275 (registration)
    The registration of the `search_code` MCP tool in the server implementation.
    {
      name: 'search_code',
      description: '⭐ PREFERRED OVER Grep: Search for code patterns with regex support. Returns ranked results with minimal context. Better than Grep because it ranks by relevance and provides AI-optimized output. Use for pattern matching and text search.',
      inputSchema: {
        type: 'object',
        properties: {
          pattern: {
            type: 'string',
            description: 'Text or regex pattern to search for',
          },
          filePattern: {
            type: 'string',
            description: 'Optional: glob pattern to filter files (e.g., "**/*.ts")',
          },
          maxResults: {
            type: 'number',
            description: 'Maximum number of results to return. Default: 10',
          },
        },
        required: ['pattern'],
      },
    },
    {
  • The tool call handler switch case for `search_code` in the MCP server.
    case 'search_code': {
      const a = args as any;
      const pattern: string = a.pattern || a.query || a.search || a.text;
      const filePattern: string | undefined = a.filePattern || a.glob || a.fileGlob;
      const maxResults: number = a.maxResults || a.limit || a.max || 10;
      if (!pattern) {
        return {
          content: [{ type: 'text', text: 'Error: pattern is required. Provide a text or regex pattern to search for.' }],
          isError: true,
        };
      }
      const results = await retriever.searchCode(
        pattern,
        filePattern,
        maxResults
      );
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results, null, 2),
          },
  • The core search engine function `searchCodePatterns` that performs the actual pattern matching logic.
    static searchCodePatterns(
      pattern: string,
      files: FileIndex[],
      maxResults: number = 20
    ): Array<{
      filePath: string;
      line: number;
      matchedText: string;
      context: string;
      score: number;
    }> {
      const results: Array<{
        filePath: string;
        line: number;
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it's a search operation (implied read-only), returns ranked results with minimal context, and supports regex. However, it doesn't mention potential limitations like performance, file size constraints, or authentication needs, leaving some gaps for a tool with no annotations.

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?

The description is highly concise and well-structured: three sentences with zero waste. The first sentence states purpose and key features, the second compares to Grep, and the third specifies use cases. Every sentence earns its place by adding distinct value.

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?

Given no annotations and no output schema, the description does a good job covering core functionality and usage context. However, it lacks details on return format (beyond 'ranked results with minimal context') and doesn't address potential errors or edge cases. For a search tool with 3 parameters, it's mostly complete but could benefit from more behavioral context.

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 description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain regex syntax, glob pattern details, or result ranking criteria. Baseline 3 is appropriate when the schema does the heavy lifting.

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 clearly states the tool's purpose with specific verbs ('search for code patterns with regex support') and resources ('code patterns'), and explicitly distinguishes it from the sibling tool 'Grep' by highlighting advantages like ranking by relevance and AI-optimized output. This makes it easy to understand what the tool does and how it differs from alternatives.

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?

The description provides explicit guidance on when to use this tool versus alternatives: it states '⭐ PREFERRED OVER Grep' and explains why ('Better than Grep because it ranks by relevance and provides AI-optimized output'), and specifies use cases ('Use for pattern matching and text search'). This gives clear context for selection among sibling tools.

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/transparentlyok/mcp-context-manager'

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