Skip to main content
Glama
TheAlchemist6

CodeCompass MCP

search_repository

Search across GitHub repositories using patterns, text, functions, or classes with advanced filters for case sensitivity, file types, and excluded paths. Includes code context in results for precise development analysis.

Instructions

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

Input Schema

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

Implementation Reference

  • Main handler function for the 'search_repository' tool. Extracts arguments, fetches repository info, calls GitHubService.searchInRepository, formats and returns response.
    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); }
  • Core search logic in GitHubService: searches key files line-by-line for the query (case-insensitive), collects matches with optional context.
    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(), }; }
  • Input schema and metadata definition for the 'search_repository' tool, including parameters like url, query, search_type, and various search options.
    { 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-261 (registration)
    Tool registration/dispatch in the switch statement of the CallToolRequestSchema handler, routing calls to the specific handler function.
    case 'search_repository': result = await handleSearchRepository(args);

Other Tools

Related 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