search_documentation
Search cached documentation for GitHub repositories to find relevant information using specific queries.
Instructions
Search within cached documentation for a repository
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| owner | Yes | Repository owner/organization | |
| repo | Yes | Repository name | |
| query | Yes | Search query within the documentation |
Implementation Reference
- src/server.ts:78-99 (registration)Registers the 'search_documentation' tool in the ListTools handler, including name, description, and input schema.{ name: 'search_documentation', description: 'Search within cached documentation for a repository', inputSchema: { type: 'object', properties: { owner: { type: 'string', description: 'Repository owner/organization', }, repo: { type: 'string', description: 'Repository name', }, query: { type: 'string', description: 'Search query within the documentation', }, }, required: ['owner', 'repo', 'query'], }, },
- src/server.ts:167-181 (handler)MCP CallTool handler for 'search_documentation': validates input arguments, invokes CodeWikiClient.searchDocumentation, and returns JSON-formatted results.case 'search_documentation': { const { owner, repo, query } = args as any; if (!owner || !repo || !query) { throw new Error('Owner, repo, and query are required'); } const results = await codeWikiClient.searchDocumentation(owner, repo, query); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; }
- src/codewiki-client.ts:102-155 (handler)Core implementation of search logic: retrieves documentation (from cache or fetches), performs keyword search across sections and subsections, computes relevance scores, sorts results, and returns top 10 matches.async searchDocumentation(owner: string, repo: string, query: string): Promise<{ repository: RepositoryInfo; results: Array<{ section: string; content: string; relevance: number }>; query: string; }> { const docs = await this.getRepositoryDocs(owner, repo); const results: Array<{ section: string; content: string; relevance: number }> = []; // Simple text search through sections for (const section of docs.sections) { const content = `${section.title} ${section.content}`.toLowerCase(); const queryLower = query.toLowerCase(); if (content.includes(queryLower)) { // Calculate simple relevance score const titleMatches = section.title.toLowerCase().includes(queryLower) ? 2 : 0; const contentMatches = (section.content.toLowerCase().match(new RegExp(queryLower, 'g')) || []).length; const relevance = titleMatches + contentMatches; results.push({ section: section.title, content: section.content.substring(0, 500) + (section.content.length > 500 ? '...' : ''), relevance, }); } // Search subsections if (section.subsections) { for (const subsection of section.subsections) { const subContent = `${subsection.title} ${subsection.content}`.toLowerCase(); if (subContent.includes(queryLower)) { const titleMatches = subsection.title.toLowerCase().includes(queryLower) ? 2 : 0; const contentMatches = (subsection.content.toLowerCase().match(new RegExp(queryLower, 'g')) || []).length; const relevance = titleMatches + contentMatches; results.push({ section: `${section.title} > ${subsection.title}`, content: subsection.content.substring(0, 500) + (subsection.content.length > 500 ? '...' : ''), relevance, }); } } } } // Sort by relevance results.sort((a, b) => b.relevance - a.relevance); return { repository: docs.repository, results: results.slice(0, 10), // Return top 10 results query, }; }