get_card_price_history
Retrieve 30-day price history for a specific card printing, including normal and foil variants, with older data retained on a weekly/monthly cadence.
Instructions
Get the 30-day price history for a card printing (normal + foil). Older data is retained on a weekly/monthly cadence beyond 30 days.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| setCode | Yes | Set code (e.g. 'lea'). | |
| setNumber | Yes | Collector number within the set (e.g. '161'). String, not int - some sets use suffixes like '12a'. |
Implementation Reference
- src/tools/get-card.ts:33-42 (handler)The handler function for 'get_card_price_history'. It takes setCode and setNumber as input, and makes a GET request to /api/v1/cards/{setCode}/{setNumber}/price-history to retrieve price history data (30-day history, with older data retained weekly/monthly).
export const getCardPriceHistoryTool = { name: "get_card_price_history", description: "Get the 30-day price history for a card printing (normal + foil). Older data is retained on a weekly/monthly cadence beyond 30 days.", inputSchema: z.object(getCardInputSchema), handler: async (input: { setCode: string; setNumber: string }) => apiFetch({ path: `/api/v1/cards/${encodeURIComponent(input.setCode)}/${encodeURIComponent(input.setNumber)}/price-history`, }), }; - src/tools/get-card.ts:4-7 (schema)The input schema shared by all get-card tools. Defines two required string fields: setCode (e.g. 'lea') and setNumber (e.g. '161' or '12a' with suffix).
export const getCardInputSchema = { setCode: z.string().describe("Set code (e.g. 'lea')."), setNumber: z.string().describe("Collector number within the set (e.g. '161'). String, not int - some sets use suffixes like '12a'."), }; - src/tools/index.ts:48-93 (registration)The tools array registration. getCardPriceHistoryTool is included at index 53 (read-only, no auth required) and also indexed by name in the toolsByName map.
export const tools: ToolDefinition[] = [ // Read-only (no auth) searchCardsTool, getCardTool, getCardPricesTool, getCardPriceHistoryTool, searchSetsTool, getSetTool, listSetCardsTool, getSealedProductsTool, // Inventory (auth) listInventoryTool, getInventoryQuantitiesTool, addInventoryTool, updateInventoryTool, removeInventoryTool, // Transactions (auth) listTransactionsTool, recordTransactionTool, updateTransactionTool, deleteTransactionTool, getCostBasisTool, // Portfolio (auth; most are Premium-gated) getPortfolioSummaryTool, getPortfolioHistoryTool, getCardPerformanceTool, getCashFlowTool, getRealizedGainsTool, getPortfolioBreakdownTool, refreshPortfolioTool, // Price alerts (auth) listAlertsTool, createAlertTool, updateAlertTool, deleteAlertTool, // Notifications (auth) listNotificationsTool, getUnreadCountTool, markNotificationReadTool, markAllNotificationsReadTool, ]; export const toolsByName: Record<string, ToolDefinition> = Object.fromEntries( tools.map((t) => [t.name, t]), ); - src/api-client.ts:26-67 (helper)The apiFetch helper used by the handler to make HTTP requests. Constructs a URL, adds headers (including optional Bearer auth), and parses JSON responses. Errors (non-OK statuses) throw ApiError with optional rate limit info.
export async function apiFetch<T = unknown>(req: ApiRequest): Promise<T> { const url = new URL(req.path, config.baseUrl); if (req.query) { for (const [k, v] of Object.entries(req.query)) { if (v !== undefined && v !== null && v !== "") { url.searchParams.set(k, String(v)); } } } const headers: Record<string, string> = { Accept: "application/json", "User-Agent": "iwantmymtg-mcp/0.0.1", }; if (req.authenticated) { const { requireApiKey } = await import("./config.js"); headers["Authorization"] = `Bearer ${requireApiKey()}`; } if (req.body !== undefined) { headers["Content-Type"] = "application/json"; } const res = await fetch(url, { method: req.method ?? "GET", headers, body: req.body !== undefined ? JSON.stringify(req.body) : undefined, }); if (!res.ok) { const text = await res.text(); throw new ApiError(res.status, text, { limit: res.headers.get("X-RateLimit-Limit") ?? undefined, remaining: res.headers.get("X-RateLimit-Remaining") ?? undefined, reset: res.headers.get("X-RateLimit-Reset") ?? undefined, }); } if (res.status === 204) return undefined as T; return (await res.json()) as T; }