random_card
Fetch a random Magic: The Gathering card from Scryfall's database, with optional search filters 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)Executes the random_card tool by calling Scryfall.getRandomCard with optional query 'q' and returns the result formatted as MCP ToolResult 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:219-229 (registration)Registers the 'random_card' tool with the MCP server, specifying description, input schema, and handler function.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/mcp-server.ts:217-217 (schema)Defines the Zod input schema for the random_card tool: optional 'q' string for filtering the random card.const randomCardParamsShape = { q: z.string().optional() } as const;
- src/scryfall.ts:104-104 (helper)Helper method in Scryfall class that performs the API call to /cards/random endpoint with optional query parameter.getRandomCard: (q?: string) => getJson("/cards/random", q ? { q } : undefined),