Skip to main content
Glama
6

MCP Server RubyGems

by 6

search_rubygems

Find RubyGems by searching gem names and descriptions using a query string. Customize results with a limit parameter up to 30. Example queries include 'authentication' or 'aws sdk'.

Instructions

Search for RubyGems matching a query string. The search matches against gem names and descriptions. Returns up to 10 results by default (customizable with limit parameter), ordered by relevance. Example queries: "authentication", "rails middleware", "aws sdk"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
$schemaNo
additionalPropertiesNo
propertiesNo
requiredNo
typeNo

Implementation Reference

  • Core handler function that executes the tool logic: fetches search results from RubyGems API, validates with Zod schema, applies limit, and returns results.
    async function searchRubyGems(
      query: string,
      limit?: number
    ): Promise<RubyGemSearchResult[]> {
      const response = await fetch(
        `https://rubygems.org/api/v1/search.json?query=${encodeURIComponent(query)}`
      );
    
      if (!response.ok) {
        throw new Error(`Failed to search RubyGems: ${response.statusText}`);
      }
    
      const data = await response.json();
      const results = z.array(RubyGemSearchResultSchema).parse(data);
    
      // Apply limit if provided
      if (limit && limit > 0) {
        return results.slice(0, limit);
      }
    
      return results;
    }
  • Input schema for the search_rubygems tool using Zod, defining query and optional limit parameters.
    const SearchRubyGemsInputSchema = z.object({
      query: z.string().min(1).describe('Search query for finding RubyGems'),
      limit: z
        .number()
        .int()
        .positive()
        .max(30)
        .optional()
        .describe('Maximum number of results to return (default: 10, max: 30)'),
    });
  • Schema for individual RubyGem search results used for response validation.
    const RubyGemSearchResultSchema = z.object({
      name: z.string(),
      version: z.string(),
      downloads: z.number(),
      info: z.string(),
      homepage_uri: z.string().nullable(),
      source_code_uri: z.string().nullable(),
      documentation_uri: z.string().nullable(),
      bug_tracker_uri: z.string().nullable(),
    });
  • Exports the McpTool object for search_rubygems, including name, description, inputSchema, and wrapper handler that parses args, calls core function, formats response or error.
    export const searchRubyGemsTool: McpTool = {
      name: 'search_rubygems',
      description:
        'Search for RubyGems matching a query string. The search matches against gem names and descriptions. Returns up to 10 results by default (customizable with limit parameter), ordered by relevance. Example queries: "authentication", "rails middleware", "aws sdk"',
      inputSchema: {
        type: 'object',
        properties: zodToJsonSchema(SearchRubyGemsInputSchema),
      },
      handler: async (args: Record<string, unknown> | undefined) => {
        const { query, limit } = SearchRubyGemsInputSchema.parse(args || {});
        const resultLimit = limit || 10; // Default to 10 if not specified
    
        try {
          const results = await searchRubyGems(query, resultLimit);
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(results, null, 2),
              },
            ],
          };
        } catch (error: unknown) {
          // Return error context instead of throwing an error
          return createErrorResponse(error, 'Failed to search RubyGems');
        }
      },
    };
  • src/index.ts:20-27 (registration)
    Registers searchRubyGemsTool in the server's tools array for use in MCP server.
    const tools: readonly McpTool[] = [
      getRubyGemInfoTool,
      searchRubyGemsTool,
      getGemVersionsTool,
      getGemReverseDependenciesTool,
      getOwnerGemsTool,
      getGemOwnersTool,
    ] as const;

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

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/6/mcp-server-rubygems'

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