Skip to main content
Glama
TheAlchemist6

CodeCompass MCP

search_repository

Search across GitHub repositories for patterns, text, functions, or classes using advanced filtering options to find specific code elements.

Instructions

Search for patterns, text, functions, or classes across the entire repository with advanced filtering options.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesGitHub repository URL
queryYesSearch query (supports regex patterns)
search_typeNoType of search to performtext
optionsNo

Implementation Reference

  • The main handler function for the 'search_repository' MCP tool. Extracts parameters from args, fetches repository info, performs the search via GitHubService, creates standardized response, and formats for MCP protocol.
    async function handleSearchRepository(args: any) {
      try {
        const { url, query, search_type = 'text', options = {} } = args;
        
        // Get repository content and perform search
        const repositoryInfo = await githubService.getRepositoryInfo(url);
        const searchResults = await githubService.searchInRepository(url, query, {
          type: search_type,
          ...options,
        });
    
        const response = createResponse(searchResults);
        return formatToolResponse(response);
      } catch (error) {
        const response = createResponse(null, error, { tool: 'search_repository', url: args.url, query: args.query });
        return formatToolResponse(response);
      }
    }
  • Tool schema definition including name, description, and input validation schema for 'search_repository'.
    {
      name: 'search_repository',
      description: 'Search for patterns, text, functions, or classes across the entire repository with advanced filtering options.',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'GitHub repository URL',
          },
          query: {
            type: 'string',
            description: 'Search query (supports regex patterns)',
          },
          search_type: {
            type: 'string',
            enum: ['text', 'regex', 'function', 'class', 'variable', 'import'],
            description: 'Type of search to perform',
            default: 'text',
          },
          options: {
            type: 'object',
            properties: {
              case_sensitive: {
                type: 'boolean',
                description: 'Case sensitive search',
                default: false,
              },
              file_extensions: {
                type: 'array',
                items: { type: 'string' },
                description: 'File extensions to search in',
              },
              exclude_paths: {
                type: 'array',
                items: { type: 'string' },
                description: 'Paths to exclude from search',
                default: ['node_modules', 'dist', 'build', '.git'],
              },
              max_results: {
                type: 'number',
                description: 'Maximum number of results',
                default: 100,
              },
              include_context: {
                type: 'boolean',
                description: 'Include surrounding code context',
                default: true,
              },
            },
          },
        },
        required: ['url', 'query'],
      },
    },
  • src/index.ts:260-262 (registration)
    Tool registration in the MCP CallToolRequestSchema request handler switch statement, dispatching to the specific handler function.
    case 'search_repository':
      result = await handleSearchRepository(args);
      break;
  • Core search implementation in GitHubService class. Retrieves key files from repository, performs case-insensitive line-by-line substring search for the query, collects matches with optional context, and returns structured results.
    async searchInRepository(url: string, query: string, options: any = {}): Promise<any> {
      const keyFiles = await this.getKeyFiles(url);
      const searchResults = [];
      
      for (const [filePath, content] of Object.entries(keyFiles)) {
        const lines = content.split('\n');
        let lineNumber = 0;
        
        for (const line of lines) {
          lineNumber++;
          if (line.toLowerCase().includes(query.toLowerCase())) {
            searchResults.push({
              file: filePath,
              line: lineNumber,
              content: line.trim(),
              context: options.include_context ? lines.slice(Math.max(0, lineNumber - 3), lineNumber + 3) : [],
              type: 'exact',
            });
          }
        }
      }
      
      return {
        query,
        results: searchResults,
        totalMatches: searchResults.length,
        filesSearched: Object.keys(keyFiles).length,
        searchTime: Date.now(),
      };
    }
Behavior2/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 mentions 'advanced filtering options' but doesn't specify what happens during execution - whether it's read-only, if it requires authentication, rate limits, pagination behavior, or what the output format looks like. For a search tool with complex parameters, this leaves significant behavioral gaps.

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?

The description is a single, efficient sentence that clearly states the core purpose. It's appropriately sized and front-loaded with the main function. There's no wasted verbiage, though it could potentially benefit from slightly more detail given the tool's complexity.

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

Completeness2/5

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

For a search tool with 4 parameters (including a complex nested object), no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how results are structured, or provide behavioral context about execution. The single sentence description leaves too many questions unanswered for effective agent use.

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?

The description mentions 'advanced filtering options' which aligns with the 'options' parameter in the schema, but doesn't add meaningful semantics beyond what the 75% schema coverage already provides. The schema descriptions are quite detailed for most parameters, so the description adds minimal value. With good schema coverage, baseline 3 is appropriate.

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 tool searches across an entire repository for patterns, text, functions, or classes with advanced filtering. It specifies the verb 'search' and resource 'repository' but doesn't explicitly differentiate from sibling tools like 'analyze_codebase' or 'explain_code' which might have overlapping search capabilities.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'analyze_codebase', 'explain_code', and 'get_file_content' that might involve searching, there's no indication of when this specific search tool is preferred or what distinguishes it from other tools that could retrieve repository information.

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/TheAlchemist6/codecompass-mcp'

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