search_github_examples
Find Onyx programming code examples on GitHub by topic to help developers learn from real implementations.
Instructions
Search Onyx code examples from GitHub repositories by topic
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic | Yes | Topic to search for | |
| limit | No | Maximum number of examples |
Implementation Reference
- src/core/search-engine.js:89-133 (handler)Core handler implementation: Searches pre-crawled GitHub Onyx code examples organized by topic from 'github/examples-by-topic.json'. Matches topics fuzzily and returns relevant code snippets.
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 (registration)Tool registration in TOOL_DEFINITIONS array, including name, description, and input schema for MCP integration.
{ 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:205-209 (handler)MCP wrapper handler: Delegates to SearchEngine, adds tool-specific message, and formats response with global context.
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/mcp-shared.js:628-629 (handler)Dispatcher switch case in executeTool method that invokes the tool wrapper handler.
case 'search_github_examples': return await this.searchGitHubExamples(args.topic, args.limit); - src/core/mcp-shared.js:58-65 (schema)JSON schema defining input parameters: topic (required string), limit (optional number, default 5).
inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Topic to search for' }, limit: { type: 'number', description: 'Maximum number of examples', default: 5 } }, required: ['topic'] }