get_rubygem_info
Fetch detailed metadata about a RubyGem from RubyGems.org API using the input gem name. Retrieve information such as dependencies, ownership, and package details for efficient Ruby development workflows.
Instructions
Get information about a RubyGem from the RubyGems.org API
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| $schema | No | ||
| additionalProperties | No | ||
| properties | No | ||
| required | No | ||
| type | No |
Implementation Reference
- src/tools/get_rubygem_info.ts:32-46 (handler)Core handler function that fetches RubyGem information from the RubyGems.org API, handles HTTP errors (including 404), parses JSON response, and validates with Zod schema.async function getRubyGemInfo(gemName: string): Promise<RubyGemInfo> { const response = await fetch( `https://rubygems.org/api/v1/gems/${gemName}.json` ); if (!response.ok) { if (response.status === 404) { throw new Error(`RubyGem '${gemName}' not found`); } throw new Error(`Failed to fetch RubyGem info: ${response.statusText}`); } const data = await response.json(); return RubyGemInfoSchema.parse(data); }
- src/tools/get_rubygem_info.ts:7-19 (schema)Zod schema defining the structure of RubyGem info returned by the API, used for response validation.const RubyGemInfoSchema = 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(), authors: z.string(), licenses: z.array(z.string()), metadata: z.record(z.string(), z.any()).optional(), });
- src/tools/get_rubygem_info.ts:24-29 (schema)Zod input schema for the tool, validating the required 'rubygem_name' parameter.const GetRubyGemInfoInputSchema = z.object({ rubygem_name: z .string() .min(1) .describe('Name of the RubyGem to fetch information for'), });
- src/tools/get_rubygem_info.ts:49-74 (registration)Export of the MCP tool object 'getRubyGemInfoTool' with name, description, converted JSON input schema, and wrapper handler that parses input, calls core handler, returns formatted text response or error.export const getRubyGemInfoTool: McpTool = { name: 'get_rubygem_info', description: 'Get information about a RubyGem from the RubyGems.org API', inputSchema: { type: 'object', properties: zodToJsonSchema(GetRubyGemInfoInputSchema), }, handler: async (args: Record<string, unknown> | undefined) => { const { rubygem_name } = GetRubyGemInfoInputSchema.parse(args || {}); try { const gemInfo = await getRubyGemInfo(rubygem_name); return { content: [ { type: 'text', text: JSON.stringify(gemInfo, null, 2), }, ], }; } catch (error: unknown) { // Return error context instead of throwing an error return createErrorResponse(error, 'Failed to fetch RubyGem info'); } }, };
- src/index.ts:20-27 (registration)Registration of getRubyGemInfoTool (first in list) in the server's tools array, used by ListToolsRequestHandler and CallToolRequestHandler.const tools: readonly McpTool[] = [ getRubyGemInfoTool, searchRubyGemsTool, getGemVersionsTool, getGemReverseDependenciesTool, getOwnerGemsTool, getGemOwnersTool, ] as const;