Skip to main content
Glama

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
NameRequiredDescriptionDefault
qNo

Implementation Reference

  • 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; }
  • 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; } );
  • 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;
  • 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),

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/latte-chan/scryfall-connector'

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