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
| Name | Required | Description | Default |
|---|---|---|---|
| order | No | ||
| page | No | ||
| per_page | No | ||
| q | Yes |
Implementation Reference
- operations/search.ts:35-37 (handler)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)); }
- operations/search.ts:4-31 (schema)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) }], }; }