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
| Name | Required | Description | Default |
|---|---|---|---|
| order | No | ||
| page | No | ||
| per_page | No | ||
| q | Yes |
Implementation Reference
- src/operations/search.ts:44-46 (handler)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)); }
- src/operations/search.ts:4-9 (schema)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(), });
- src/operations/search.ts:31-34 (schema)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), },
- src/index.ts:455-462 (handler)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) }], }; }