get_prices
Retrieve current market prices for Magic: The Gathering cards in USD, USD foil, EUR, and MTGO tickets via Scryfall. Ideal for checking card values, deck costs, or price comparisons.
Instructions
Look up current market prices for one or more Magic cards. Returns USD, USD Foil, EUR, and MTGO tix prices from Scryfall. Use this when a user asks about card prices, deck costs, or wants to compare card values.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| names | Yes | Card names to look up prices for (1-50) |
Implementation Reference
- src/tools/get-prices.ts:31-71 (handler)The main handler for the get_prices tool. Iterates over card names from input, queries the database with exact match first then fuzzy LIKE fallback, and returns price data (USD, USD Foil, EUR, EUR Foil, MTGO tix) for each card.
export function handler(db: Database.Database, params: GetPricesParams): GetPricesResult { const cards: CardPriceEntry[] = []; for (const name of params.names) { // 1. Exact match (case-insensitive) let card = db.prepare( 'SELECT * FROM cards WHERE LOWER(name) = LOWER(?)' ).get(name) as CardRow | undefined; // 2. Fuzzy fallback via LIKE if (!card) { card = db.prepare( 'SELECT * FROM cards WHERE LOWER(name) LIKE LOWER(?)' ).get(`%${name}%`) as CardRow | undefined; } if (!card) { cards.push({ name, found: false, price_usd: null, price_usd_foil: null, price_eur: null, price_eur_foil: null, price_tix: null, }); } else { cards.push({ name: card.name, found: true, price_usd: card.price_usd, price_usd_foil: card.price_usd_foil, price_eur: card.price_eur, price_eur_foil: card.price_eur_foil, price_tix: card.price_tix, }); } } return { cards }; } - src/tools/get-prices.ts:7-9 (schema)Input schema: accepts an array of 1-50 card name strings (validated with Zod).
export const GetPricesInput = z.object({ names: z.array(z.string()).min(1).max(50).describe('Card names to look up prices for (1-50)'), }); - src/tools/get-prices.ts:25-27 (schema)Output type: result containing an array of CardPriceEntry objects, each with found status and price fields.
export interface GetPricesResult { cards: CardPriceEntry[]; } - src/tools/get-prices.ts:15-23 (schema)Individual card price entry type with five price fields (USD, USD Foil, EUR, EUR Foil, MTGO tix).
export interface CardPriceEntry { name: string; found: boolean; price_usd: number | null; price_usd_foil: number | null; price_eur: number | null; price_eur_foil: number | null; price_tix: number | null; } - src/server.ts:253-265 (registration)Registers the 'get_prices' MCP tool on the server with its description, input schema, and handler invocation.
server.tool( 'get_prices', 'Look up current market prices for one or more Magic cards. Returns USD, USD Foil, EUR, and MTGO tix prices from Scryfall. Use this when a user asks about card prices, deck costs, or wants to compare card values.', GetPricesInput.shape, async (params) => { try { const result = getPricesHandler(db, params); return { content: [{ type: 'text' as const, text: formatGetPrices(result) }] }; } catch (err) { return { content: [{ type: 'text' as const, text: `Error getting prices: ${err instanceof Error ? err.message : String(err)}` }], isError: true }; } }, );