Skip to main content
Glama

search-repos

Find GitHub repositories by search query, with options to sort by stars, forks, help-wanted issues, or update date and limit results.

Instructions

Search for GitHub repositories

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
sortNoSort order
limitNoMaximum number of results to return

Implementation Reference

  • The main execution logic for the 'search-repos' tool, using Octokit to query GitHub's search API and format results.
    const searchRepos = async (args: SearchReposArgs) => {
      const { query, sort = "stars", limit = 5 } = args;
      
      try {
        const response = await octokit.rest.search.repos({
          q: query,
          sort,
          per_page: limit,
        });
        
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                response.data.items.map(repo => ({
                  name: repo.full_name,
                  description: repo.description,
                  stars: repo.stargazers_count,
                  url: repo.html_url,
                  language: repo.language,
                  forks: repo.forks_count,
                })),
                null,
                2
              ),
            },
          ],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
        return {
          content: [
            {
              type: "text",
              text: `Error searching repositories: ${errorMessage}`,
            },
          ],
        };
      }
    };
  • Input schema definition for the 'search-repos' tool, used for listing and validation.
    "search-repos": {
      name: "search-repos",
      description: "Search for GitHub repositories",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query",
          },
          sort: {
            type: "string",
            enum: ["stars", "forks", "help-wanted-issues", "updated"],
            description: "Sort order",
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return",
          }
        },
        required: ["query"],
      },
    },
  • src/handlers.ts:18-32 (registration)
    MCP server request handlers for listing tools (using 'tools' object) and calling tools (using 'toolHandlers' map).
        // tools
        server.setRequestHandler(ListToolsRequestSchema, async () => ({
            tools: Object.values(tools)
        }));
        server.setRequestHandler(CallToolRequestSchema, async (request) => {
            type ToolHandlerKey = keyof typeof toolHandlers;
            const { name, arguments: params } = request.params ?? {};
            const handler = toolHandlers[name as ToolHandlerKey];
    
            if (!handler) throw new Error("tool not found");
    
            type HandlerParams = Parameters<typeof handler>;
            return handler(params as any);
        })
    }
  • src/tools.ts:322-327 (registration)
    Export of the toolHandlers object mapping tool names to their handler functions, imported and used in handlers.ts.
    export const toolHandlers = {
      "search-repos": searchRepos,
      "get-repo-info": getRepoInfo,
      "list-issues": listIssues,
      "create-issue": createIssue,
    };
  • TypeScript type definition for the input arguments of the searchRepos handler.
    type SearchReposArgs = {
      query: string;
      sort?: "stars" | "forks" | "help-wanted-issues" | "updated";
      limit?: number;
    };

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

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