Skip to main content
Glama
nahmanmate

Code Research MCP Server

by nahmanmate

search_github

Search GitHub repositories and code using queries, with filters for programming languages and result limits, to find programming resources and examples.

Instructions

Search GitHub for repositories and code

Input Schema

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

Implementation Reference

  • The core handler function that performs GitHub searches for repositories and code snippets using the GitHub Search API. Includes caching, language filtering, rate limit handling with token fallback, and formatted output.
    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, specifying query (required), optional language filter, and limit.
    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 ListToolsRequestSchema handler, 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']
      }
    },
  • src/index.ts:463-478 (registration)
    Registration of the search_github tool handler in the CallToolRequestSchema switch statement, which extracts arguments and calls the searchGitHub function.
    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
          }
        ]
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool searches GitHub but doesn't describe what the search returns (e.g., repository metadata, code snippets, or both), any rate limits, authentication needs, or error handling. For a search tool with no annotation coverage, this leaves significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with a single sentence ('Search GitHub for repositories and code'), front-loaded with the core purpose. There is zero wasted text, making it efficient and easy to parse, though this conciseness comes at the cost of missing contextual details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (searching a major platform with 3 parameters) and lack of annotations and output schema, the description is incomplete. It doesn't explain what the search returns, how results are structured, or any limitations, leaving the agent with insufficient context to use the tool effectively beyond basic parameter input.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter-specific information beyond what the input schema provides, which has 100% coverage with clear descriptions for query, language, and limit. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate with additional context like query syntax examples or language filtering details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Search GitHub') and the target resources ('repositories and code'), making the purpose immediately understandable. However, it doesn't differentiate this tool from its siblings (like search_npm or search_pypi) beyond specifying the GitHub platform, missing an opportunity to highlight GitHub-specific search capabilities versus other code search tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus the sibling tools (search_all, search_mdn, search_npm, search_pypi, search_stackoverflow). It doesn't mention alternatives, prerequisites, or specific contexts where GitHub search is preferred over other search tools, leaving the agent to infer usage based on the platform name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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