search_all_sources
Search across all crawled content including documentation, GitHub repositories, and URLs. Find relevant results by specifying sources and limiting output.
Instructions
Search all crawled content (docs, GitHub, URLs)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results | |
| query | Yes | Search query | |
| sources | No | Sources to search in |
Implementation Reference
- src/core/mcp-shared.js:263-267 (handler)The handler function for the 'search_all_sources' tool. It performs the search using the SearchEngine and formats the MCP response with global context.async searchAllSources(query, sources = ['docs', 'github'], limit = 10) { const results = await this.searchEngine.searchAll(query, sources, limit); const toolMessage = `Searching across multiple sources (${sources.join(', ')}) for: "${query}"`; return this.formatResponse(JSON.stringify(results, null, 2), toolMessage); }
- src/core/mcp-shared.js:101-118 (schema)Tool definition including name, description, and input schema for 'search_all_sources' used for registration and validation.{ name: 'search_all_sources', description: 'Search all crawled content (docs, GitHub, URLs)', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, sources: { type: 'array', items: { type: 'string', enum: ['docs', 'github'] }, description: 'Sources to search in', default: ['docs', 'github'] }, limit: { type: 'number', description: 'Maximum number of results', default: 10 } }, required: ['query'] } },
- src/core/mcp-shared.js:641-642 (registration)Dispatcher switch case that registers and routes execution to the searchAllSources handler.case 'search_all_sources': return await this.searchAllSources(args.query, args.sources, args.limit);
- src/core/search-engine.js:192-239 (helper)Core helper function implementing the multi-source search logic called by the tool handler. Orchestrates searches in docs and github, combines and ranks results.async searchAll(query, sources = ['docs', 'github'], limit = 10) { const results = { query, sources: sources, totalResults: 0, resultsBySources: {} }; const perSourceLimit = Math.ceil(limit / sources.length); if (sources.includes('docs')) { results.resultsBySources.docs = await this.searchDocs(query, perSourceLimit); if (!results.resultsBySources.docs.error) { results.totalResults += results.resultsBySources.docs.totalFound || 0; } } if (sources.includes('github')) { // Search GitHub files directly const githubFiles = await this.loadData('githubFiles'); if (githubFiles) { const githubResults = this.searchGitHubFiles(githubFiles, query, perSourceLimit); results.resultsBySources.github = githubResults; results.totalResults += githubResults.totalFound || 0; } } // Combine and rank all results const allResults = []; Object.values(results.resultsBySources).forEach(sourceResults => { if (sourceResults.results && !sourceResults.error) { sourceResults.results.forEach(result => { allResults.push({ ...result, source: sourceResults.source }); }); } }); // Sort by score (higher is better) allResults.sort((a, b) => (b.score || 0) - (a.score || 0)); results.combinedResults = allResults.slice(0, limit); return results; }
- src/core/search-engine.js:242-287 (helper)Helper method for searching GitHub files, used in searchAll. Computes relevance scores and extracts snippets.searchGitHubFiles(files, query, limit) { const queryLower = query.toLowerCase(); const results = []; for (const file of files) { let score = 0; const pathMatch = file.path.toLowerCase().includes(queryLower); const repoMatch = file.repository.toLowerCase().includes(queryLower); const codeMatch = file.code && file.code.toLowerCase().includes(queryLower); const contentMatch = file.content && file.content.toLowerCase().includes(queryLower); // Higher scores for different types of matches if (pathMatch) score += 5; if (repoMatch) score += 3; if (codeMatch || contentMatch) score += 1; // Boost score for important file types if (file.fileType === 'readme') score += 10; if (file.fileType === 'package-config') score += 8; if (file.fileType === 'project-config') score += 6; if (file.fileType === 'documentation') score += 7; if (file.fileType === 'web-content') score += 5; if (file.fileType === 'web-index') score += 6; if (file.fileType === 'example' && file.path.toLowerCase().endsWith('.html')) score += 4; if (score > 0) { const content = file.content || file.code || ''; results.push({ file: file.path, repository: file.repository, url: file.url, score: score, fileType: file.fileType || 'unknown', codeSnippet: this.getSnippet(content, queryLower, 300) }); } } results.sort((a, b) => b.score - a.score); return { source: 'github', totalFound: results.length, results: results.slice(0, limit) }; }