get_cost_basis
Retrieve the FIFO cost basis for a Magic: The Gathering card by providing card ID or set code and number, including foil finish.
Instructions
Get FIFO cost basis for a specific card+finish for the authenticated user. Pass either cardId or (setCode, setNumber). Requires IWMM_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cardId | No | ||
| setCode | No | ||
| setNumber | No | ||
| isFoil | No |
Implementation Reference
- src/tools/transactions.ts:91-97 (handler)The handler function for get_cost_basis tool. Calls the IWMM API's cost-basis endpoint with either a cardId or (setCode, setNumber) plus isFoil flag.
handler: (input: { cardId?: string; setCode?: string; setNumber?: string; isFoil: boolean }) => { const query = { isFoil: input.isFoil }; const path = input.cardId ? `/api/v1/transactions/cost-basis/${encodeURIComponent(input.cardId)}` : `/api/v1/transactions/cost-basis/${encodeURIComponent(input.setCode!)}/${encodeURIComponent(input.setNumber!)}`; return apiFetch({ path, query, authenticated: true }); }, - src/tools/transactions.ts:81-90 (schema)Input schema for get_cost_basis: accepts optional cardId, setCode, setNumber, and a default-false isFoil boolean. Uses .refine() to require either cardId or both setCode+setNumber.
inputSchema: z .object({ cardId: z.string().optional(), setCode: z.string().optional(), setNumber: z.string().optional(), isFoil: z.boolean().default(false), }) .refine((v) => !!v.cardId || (!!v.setCode && !!v.setNumber), { message: "Provide either cardId, or both setCode and setNumber.", }), - src/tools/index.ts:69-69 (registration)Registration of getCostBasisTool in the tools array, making it available as an MCP tool named 'get_cost_basis'.
getCostBasisTool, - src/tools/index.ts:17-18 (registration)Import of getCostBasisTool from the transactions module into the central tool registry.
getCostBasisTool, } from "./transactions.js"; - src/api-client.ts:26-67 (helper)The apiFetch helper used by the handler to make HTTP requests to the IWMM API with authentication.
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; }