search_code
Search for code within GitHub repositories using specific queries, filters, and pagination for precise results.
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 main handler function for the 'search_code' tool, which calls the GitHub search code API using utility functions.export async function searchCode(params: z.infer<typeof SearchCodeSchema>) { return githubRequest(buildUrl("https://api.github.com/search/code", params)); }
- operations/search.ts:4-9 (schema)Input schema definition (SearchOptions), which is aliased as SearchCodeSchema for the tool.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(), });
- operations/search.ts:31-31 (schema)Alias for the SearchOptions schema used in tool registration and validation.export const SearchCodeSchema = SearchOptions;
- index.ts:138-142 (registration)Registration of the 'search_code' tool in the MCP server's tool list.{ name: "search_code", description: "Search for code across GitHub repositories", inputSchema: zodToJsonSchema(search.SearchCodeSchema), },
- index.ts:284-289 (handler)Dispatch handler in the main CallToolRequestHandler that invokes the searchCode function.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) }], };