add_inventory
Add Magic: The Gathering cards to your inventory batchwise. Specify card ID, quantity, and whether foil to track your collection.
Instructions
Add one or more cards to the authenticated user's inventory. Accepts a batch - pass a single-item array for one card. This is a real write. Use update_inventory to change quantities, remove_inventory to delete a row. Requires IWMM_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| items | Yes |
Implementation Reference
- src/tools/inventory.ts:26-33 (handler)The addInventoryTool definition containing the name, description, inputSchema, and the handler function that sends a POST request to /api/v1/inventory with the items array.
export const addInventoryTool = { name: "add_inventory", description: "Add one or more cards to the authenticated user's inventory. Accepts a batch - pass a single-item array for one card. This is a real write. Use update_inventory to change quantities, remove_inventory to delete a row. Requires IWMM_API_KEY.", inputSchema: z.object({ items: z.array(inventoryItem).min(1) }), handler: (input: { items: z.infer<typeof inventoryItem>[] }) => apiFetch({ path: "/api/v1/inventory", method: "POST", body: input.items, authenticated: true }), }; - src/tools/inventory.ts:4-8 (schema)Zod schema for an inventory item, used as the element type in addInventoryTool's inputSchema (z.array(inventoryItem)).
const inventoryItem = z.object({ cardId: z.string().uuid().describe("Internal IWMM card UUID. Get from search_cards or get_card."), quantity: z.number().int().min(0).describe("Total quantity for this card+finish. 0 removes the row."), isFoil: z.boolean().describe("Whether this is the foil variant. Foil and non-foil are tracked as separate rows."), }); - src/tools/index.ts:61-61 (registration)Registration of addInventoryTool in the tools array, which is exported and used by the MCP server to list and dispatch tool calls.
addInventoryTool, - src/tools/index.ts:90-92 (registration)Lookup map from tool name to tool definition, used by the server's CallToolRequestSchema handler to dispatch add_inventory calls.
export const toolsByName: Record<string, ToolDefinition> = Object.fromEntries( tools.map((t) => [t.name, t]), ); - src/api-client.ts:26-67 (helper)The apiFetch helper function used by the addInventoryTool handler to make the authenticated POST request to /api/v1/inventory.
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; }