Skip to main content
Glama

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
NameRequiredDescriptionDefault
orderNo
pageNo
per_pageNo
qYes

Implementation Reference

  • 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)); }
  • 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) }], }; }

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

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