search_code
Search for code across GitHub repositories to find specific functions, patterns, or implementations within projects.
Instructions
Search for code across GitHub repositories
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | ||
| order | No | ||
| page | No | ||
| per_page | No |
Implementation Reference
- src/operations/search.ts:44-46 (handler)The core handler function that executes the GitHub API search/code endpoint using the provided parameters.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:31-34 (schema)Zod schema definitions for validating input parameters of the search_code tool. SearchCodeSchema aliases SearchOptions, and _SearchCodeSchema adds github_pat for internal use.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 listTools handler, 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 (registration)Dispatch case in the callToolRequest handler that parses arguments and invokes the searchCode handler 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) }], }; }