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(), }; }

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