Skip to main content
Glama

search_code

Search across GitHub repositories for specific code snippets using customizable queries, pagination, and sorting to streamline development workflows.

Instructions

Search for code across GitHub repositories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderNo
pageNo
per_pageNo
qYes

Implementation Reference

  • The core handler function that performs the GitHub API call to search for code using the /search/code endpoint.
    export async function searchCode(github_pat: string, params: z.infer<typeof SearchCodeSchema>) { return githubRequest(github_pat, buildUrl("https://api.github.com/search/code", params)); }
  • Zod schema defining the input parameters for the search_code tool (query q, pagination, sorting). This is aliased as SearchCodeSchema.
    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(), });
  • Schema exports for search_code, including the public SearchCodeSchema and internal _SearchCodeSchema with github_pat.
    export const SearchCodeSchema = SearchOptions; export const _SearchCodeSchema = SearchCodeSchema.extend({ github_pat: z.string().describe("GitHub Personal Access Token"), });
  • src/index.ts:144-147 (registration)
    Registration of the search_code tool in the MCP server's listTools response, including name, description, and input schema.
    name: "search_code", description: "Search for code across GitHub repositories", inputSchema: zodToJsonSchema(search.SearchCodeSchema), },
  • Dispatch handler in the main CallToolRequest that validates arguments using _SearchCodeSchema and invokes the searchCode function.
    case "search_code": { const argsWithPat = search._SearchCodeSchema.parse(params.arguments); const { github_pat, ...args } = argsWithPat; const results = await search.searchCode(github_pat, args); return { content: [{ type: "text", text: JSON.stringify(results, null, 2) }], }; }

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

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