Skip to main content
Glama

search_github

Search GitHub repositories and code by query, filtering by programming language, and set result limits to find relevant coding resources efficiently.

Instructions

Search GitHub for repositories and code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNoFilter by programming language
limitNoMaximum number of results per category (default: 5)
queryYesSearch query

Implementation Reference

  • Core implementation of the search_github tool. Searches GitHub for repositories and code using the GitHub API, supports language filtering, caching with node-cache, rate limit handling with token fallback, and formats results into repositories and code sections.
    private async searchGitHub(query: string, language?: string, limit: number = 5): Promise<string> { const cacheKey = `github:${query}:${language}:${limit}`; const cached = cache.get<string>(cacheKey); if (cached) return cached; try { // Build search query with language filter if specified const q = language ? `${query} language:${language}` : query; // If GitHub token is invalid, fall back to unauthenticated requests const makeRequest = async (endpoint: string, params: any) => { try { const response = await this.githubInstance.get(endpoint, { params }); return response; } catch (error) { if (axios.isAxiosError(error) && error.response?.status === 401) { // Retry without auth token const response = await this.axiosInstance.get(`https://api.github.com${endpoint}`, { params, headers: { 'Accept': 'application/vnd.github.v3+json', 'User-Agent': 'CodeResearchBot/1.0' } }); return response; } throw error; } }; const [reposResponse, codeResponse] = await Promise.all([ makeRequest('/search/repositories', { q, sort: 'stars', order: 'desc', per_page: limit }), makeRequest('/search/code', { q, sort: 'indexed', order: 'desc', per_page: limit }) ]); let result = '=== Top Repositories ===\n'; result += reposResponse.data.items.map((repo: any, i: number) => `${i + 1}. ${repo.full_name} (⭐ ${repo.stargazers_count})\n` + ` ${repo.description || 'No description'}\n` + ` ${repo.html_url}\n` ).join('\n'); result += '\n=== Relevant Code ===\n'; result += codeResponse.data.items.map((item: any, i: number) => `${i + 1}. ${item.name} (${item.repository.full_name})\n` + ` Path: ${item.path}\n` + ` ${item.html_url}\n` ).join('\n'); cache.set(cacheKey, result); return result; } catch (error) { throw new McpError( ErrorCode.InternalError, `GitHub API error: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
  • Input schema definition for the search_github tool, defining parameters query (required), optional language filter, and limit with bounds.
    inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, language: { type: 'string', description: 'Filter by programming language' }, limit: { type: 'number', description: 'Maximum number of results per category (default: 5)', minimum: 1, maximum: 10 } }, required: ['query'] }
  • src/index.ts:354-377 (registration)
    Registration of the search_github tool in the MCP server's tool list, including name, description, and input schema.
    { name: 'search_github', description: 'Search GitHub for repositories and code', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, language: { type: 'string', description: 'Filter by programming language' }, limit: { type: 'number', description: 'Maximum number of results per category (default: 5)', minimum: 1, maximum: 10 } }, required: ['query'] } },
  • Dispatch handler in the CallToolRequestSchema that extracts arguments and invokes the searchGitHub function for the search_github tool.
    case 'search_github': { const { query, language, limit } = request.params.arguments as { query: string; language?: string; limit?: number; }; const results = await this.searchGitHub(query, language, limit); return { content: [ { type: 'text', text: results } ] }; }

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/nahmanmate/code-research-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server