search_github_examples
Find Onyx code examples by topic from GitHub repositories using AI-powered search. Specify a topic and optional limit to retrieve relevant examples for programming tasks.
Instructions
Search Onyx code examples from GitHub repositories by topic
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of examples | |
| topic | Yes | Topic to search for |
Implementation Reference
- src/core/mcp-shared.js:205-208 (handler)MCP tool handler that executes the search_github_examples logic by delegating to SearchEngine and formatting the response for MCP.async searchGitHubExamples(topic, limit = 5) { const results = await this.searchEngine.searchGitHubExamples(topic, limit); const toolMessage = `Searching GitHub repositories for Onyx code examples related to: "${topic}"`; return this.formatResponse(JSON.stringify(results, null, 2), toolMessage);
- src/core/search-engine.js:89-133 (helper)Core helper function implementing the GitHub examples search logic using cached data from 'github/examples-by-topic.json'.async searchGitHubExamples(topic, limit = 5) { const examplesByTopic = await this.loadData('examplesByTopic'); if (!examplesByTopic) { return { error: 'GitHub examples not available. Run GitHub crawler first.' }; } const availableTopics = Object.keys(examplesByTopic); // Find matching topics (exact match or contains) const matchingTopics = availableTopics.filter(t => t.toLowerCase().includes(topic.toLowerCase()) || topic.toLowerCase().includes(t.toLowerCase()) ); if (matchingTopics.length === 0) { return { query: topic, availableTopics: availableTopics.sort(), examples: [], message: `No examples found for topic "${topic}". Try one of the available topics.` }; } const examples = []; for (const matchingTopic of matchingTopics) { const topicExamples = examplesByTopic[matchingTopic] || []; examples.push(...topicExamples.slice(0, Math.ceil(limit / matchingTopics.length))); } return { query: topic, matchingTopics, examples: examples.slice(0, limit).map(example => ({ file: example.path, repository: example.repository, url: example.url, code: example.code.length > 1000 ? example.code.substring(0, 1000) + '\n... (truncated)' : example.code, fullCodeLength: example.code.length })), totalAvailable: examples.length, availableTopics: availableTopics.sort() }; }
- src/core/mcp-shared.js:55-66 (schema)Schema definition for the search_github_examples tool, including input parameters and description.{ name: 'search_github_examples', description: 'Search Onyx code examples from GitHub repositories by topic', inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Topic to search for' }, limit: { type: 'number', description: 'Maximum number of examples', default: 5 } }, required: ['topic'] } },
- src/core/mcp-shared.js:628-629 (registration)Registration of the tool handler in the MCP tool dispatcher switch statement.case 'search_github_examples': return await this.searchGitHubExamples(args.topic, args.limit);