get_card_by_id
Retrieve Magic: The Gathering card details in JSON format using its Scryfall ID (36-char UUID). Part of the Scryfall MCP Server for API interactions.
Instructions
Retrieve a card by its Scryfall ID (a 36-char UUID). Returns the card data in JSON.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The Scryfall UUID, e.g. 'c09c71fb-7acb-4ffb-a47b-8961a0cf4990' |
Implementation Reference
- index.ts:250-254 (handler)The core handler function that fetches the specific card from Scryfall API by its ID (UUID) and returns the processed response.async function handleGetCardById(id: string) { const url = `https://api.scryfall.com/cards/${encodeURIComponent(id)}`; const response = await fetch(url); return handleScryfallResponse(response); }
- index.ts:90-105 (schema)Defines the tool's metadata: name, description, and input schema (object with required 'id' string property).const GET_CARD_BY_ID_TOOL: Tool = { name: "get_card_by_id", description: "Retrieve a card by its Scryfall ID (a 36-char UUID). Returns the card data in JSON.", inputSchema: { type: "object", properties: { id: { type: "string", description: "The Scryfall UUID, e.g. 'c09c71fb-7acb-4ffb-a47b-8961a0cf4990'" } }, required: ["id"] } };
- index.ts:186-194 (registration)Registers the get_card_by_id tool in the array of available tools returned by listTools request.const SCRYFALL_TOOLS = [ SEARCH_CARDS_TOOL, GET_CARD_BY_ID_TOOL, GET_CARD_BY_NAME_TOOL, RANDOM_CARD_TOOL, GET_RULINGS_TOOL, GET_PRICES_BY_ID_TOOL, GET_PRICES_BY_NAME_TOOL ] as const;
- index.ts:378-381 (registration)Dispatches calls to the get_card_by_id tool handler within the CallToolRequestSchema handler.case "get_card_by_id": { const { id } = args as { id: string }; return await handleGetCardById(id); }
- index.ts:197-239 (helper)Shared helper function used by get_card_by_id (and other tools) to process Scryfall API responses, handling errors and formatting JSON output.async function handleScryfallResponse(response: Response) { if (!response.ok) { // Attempt to parse Scryfall error let errorObj: ScryfallError | null = null; try { errorObj = (await response.json()) as ScryfallError; } catch { // fall back to generic } if (errorObj && errorObj.object === "error") { return { content: [ { type: "text", text: `Scryfall error: ${errorObj.details} (code=${errorObj.code}, status=${errorObj.status})` } ], isError: true }; } else { return { content: [ { type: "text", text: `HTTP error ${response.status}: ${response.statusText}` } ], isError: true }; } } // If okay, parse JSON const data = await response.json(); return { content: [ { type: "text", text: JSON.stringify(data, null, 2) } ], isError: false }; }