random_card
Fetch a random Magic: The Gathering card from Scryfall API, with optional search query filtering to narrow results.
Instructions
Fetch a random card, optionally filtered by a 'q' search query.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No |
Implementation Reference
- src/mcp-server.ts:225-228 (handler)The handler function for the 'random_card' tool. It takes an optional query 'q', fetches a random card from Scryfall, and returns the JSON data as text content.async ({ q }: { q?: string }): Promise<ToolResult> => { const data: unknown = await Scryfall.getRandomCard(q); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] } as any; }
- src/mcp-server.ts:217-217 (schema)Input schema for the 'random_card' tool, defining an optional 'q' string parameter.const randomCardParamsShape = { q: z.string().optional() } as const;
- src/mcp-server.ts:219-229 (registration)Registers the 'random_card' tool with the MCP server, including name, description, input schema reference, and inline handler.server.registerTool( "random_card", { description: "Fetch a random card, optionally filtered by a 'q' search query.", inputSchema: randomCardParamsShape }, async ({ q }: { q?: string }): Promise<ToolResult> => { const data: unknown = await Scryfall.getRandomCard(q); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] } as any; } );
- src/scryfall.ts:104-104 (helper)The Scryfall.getRandomCard utility function invoked by the tool handler, which calls the Scryfall /cards/random API endpoint.getRandomCard: (q?: string) => getJson("/cards/random", q ? { q } : undefined),