Skip to main content
Glama

search_code

Search for specific code across GitHub repositories using queries, filters, and pagination to locate relevant code snippets efficiently.

Instructions

Search for code across GitHub repositories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderNo
pageNo
per_pageNo
qYes

Implementation Reference

  • The handler function for the 'search_code' tool. It constructs the GitHub API URL for code search using the provided parameters and makes the request using githubRequest.
    export async function searchCode(params: z.infer<typeof SearchCodeSchema>) {
      return githubRequest(buildUrl("https://api.github.com/search/code", params));
    }
  • Zod schema definition for the input parameters of the 'search_code' tool. SearchCodeSchema aliases SearchOptions, which defines the query 'q', optional sorting order, page, and per_page.
    export const SearchOptions = z.object({
      q: z.string(),
      order: z.enum(["asc", "desc"]).optional(),
      page: z.number().min(1).optional(),
      per_page: z.number().min(1).max(100).optional(),
    });
    
    export const SearchUsersOptions = SearchOptions.extend({
      sort: z.enum(["followers", "repositories", "joined"]).optional(),
    });
    
    export const SearchIssuesOptions = SearchOptions.extend({
      sort: z.enum([
        "comments",
        "reactions",
        "reactions-+1",
        "reactions--1",
        "reactions-smile",
        "reactions-thinking_face",
        "reactions-heart",
        "reactions-tada",
        "interactions",
        "created",
        "updated",
      ]).optional(),
    });
    
    export const SearchCodeSchema = SearchOptions;
  • index.ts:136-139 (registration)
    Registration of the 'search_code' tool in the MCP server's listTools response, including name, description, and JSON schema derived from SearchCodeSchema.
      name: "search_code",
      description: "Search for code across GitHub repositories",
      inputSchema: zodToJsonSchema(search.SearchCodeSchema),
    },
  • index.ts:417-423 (registration)
    Dispatch handler in the CallToolRequestSchema switch case that parses arguments using SearchCodeSchema and calls the searchCode function, returning the results.
    case "search_code": {
      const args = search.SearchCodeSchema.parse(request.params.arguments);
      const results = await search.searchCode(args);
      return {
        content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
      };
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but provides minimal information. It mentions searching across repositories but doesn't describe what the search returns, pagination behavior, rate limits, authentication requirements, or whether this is a read-only operation. The agent must infer these critical behavioral aspects.

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 at just 6 words, front-loading the essential information with zero wasted words. Every word contributes directly to conveying the tool's purpose.

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?

For a search tool with 4 parameters, 0% schema description coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain what the search returns, how results are structured, or provide any context about the search scope beyond 'across GitHub repositories.' The agent lacks sufficient information to use this tool effectively.

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

Parameters2/5

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

With 0% schema description coverage and 4 parameters (1 required), the description provides no information about any parameters. It doesn't mention the required 'q' query parameter or optional pagination parameters, leaving the agent to rely solely on the schema without semantic context about what constitutes a valid search query or how pagination works.

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 for code') and resource ('across GitHub repositories'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling search tools like 'search_issues' or 'search_repositories' beyond specifying the search target is 'code' rather than issues or repositories.

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 alternatives. It doesn't mention when to prefer searching code over searching issues/repositories, nor does it specify any prerequisites or constraints for using this search functionality.

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

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/tuanle96/mcp-github'

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