create_price_alert
Set up price alerts for Magic: The Gathering cards to be notified when a card's price rises or falls by a specified percentage.
Instructions
Create a price alert for a card. Supply increasePct, decreasePct, or both (Premium). At least one threshold is required. Requires IWMM_API_KEY.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cardId | Yes | Internal IWMM card UUID. | |
| increasePct | No | Trigger when price increases by at least this percent. | |
| decreasePct | No | Trigger when price decreases by at least this percent. |
Implementation Reference
- src/tools/alerts.ts:15-28 (handler)The createAlertTool object defines the 'create_price_alert' tool with name, description, inputSchema (Zod validation with cardId, increasePct, decreasePct), and a handler that POSTs to '/api/v1/price-alerts' via apiFetch.
export const createAlertTool = { name: "create_price_alert", description: "Create a price alert for a card. Supply increasePct, decreasePct, or both (Premium). At least one threshold is required. Requires IWMM_API_KEY.", inputSchema: z .object({ cardId: z.string().uuid().describe("Internal IWMM card UUID."), increasePct: z.number().min(0.01).optional().describe("Trigger when price increases by at least this percent."), decreasePct: z.number().min(0.01).optional().describe("Trigger when price decreases by at least this percent."), }) .refine(thresholdRefinement, { message: "Provide at least one of increasePct or decreasePct." }), handler: (input: { cardId: string; increasePct?: number; decreasePct?: number }) => apiFetch({ path: "/api/v1/price-alerts", method: "POST", body: input, authenticated: true }), }; - src/tools/alerts.ts:19-25 (schema)Input schema for create_price_alert using Zod: cardId (UUID string), optional increasePct (number >= 0.01), optional decreasePct (number >= 0.01), with a refinement requiring at least one threshold.
inputSchema: z .object({ cardId: z.string().uuid().describe("Internal IWMM card UUID."), increasePct: z.number().min(0.01).optional().describe("Trigger when price increases by at least this percent."), decreasePct: z.number().min(0.01).optional().describe("Trigger when price decreases by at least this percent."), }) .refine(thresholdRefinement, { message: "Provide at least one of increasePct or decreasePct." }), - src/tools/index.ts:29-30 (registration)The createAlertTool is imported from './alerts.js' and registered in the tools array at line 80.
listAlertsTool, createAlertTool, - src/tools/index.ts:90-92 (registration)The toolsByName map (line 90-92) maps the string 'create_price_alert' to the createAlertTool object for dynamic lookup by name.
export const toolsByName: Record<string, ToolDefinition> = Object.fromEntries( tools.map((t) => [t.name, t]), ); - src/server.ts:32-62 (registration)The MCP server's CallToolRequestSchema handler looks up the tool by name from toolsByName, validates args with the schema, and invokes the handler.
server.setRequestHandler(CallToolRequestSchema, async (req) => { const tool = toolsByName[req.params.name]; if (!tool) { return { isError: true, content: [{ type: "text", text: `Unknown tool: ${req.params.name}` }], }; } const args = tool.inputSchema.safeParse(req.params.arguments ?? {}); if (!args.success) { return { isError: true, content: [ { type: "text", text: `Invalid arguments for ${tool.name}: ${args.error.message}`, }, ], }; } try { const result = await tool.handler(args.data); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; } catch (err) { return { isError: true, content: [{ type: "text", text: formatError(err) }] }; } });