get_prices
Retrieve current market prices for Magic: The Gathering cards in USD, EUR, and MTGO tix to evaluate card values, calculate deck costs, and compare pricing across formats.
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
TableJSON 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 logic for retrieving prices from the database for a list of card names.
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)Zod schema defining the input validation for 'get_prices'.
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/server.ts:264-275 (registration)Tool registration in the MCP server for 'get_prices'.
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 }; } },