buy_supplies
Purchase cups, lemons, sugar, and ice to manage inventory for a lemonade stand business simulation game.
Instructions
Purchase supplies for the lemonade stand
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gameId | Yes | The game ID | |
| cups | No | Number of cups to buy | |
| lemons | No | Number of lemons to buy | |
| sugar | No | Amount of sugar to buy | |
| ice | No | Amount of ice to buy |
Implementation Reference
- server.js:62-98 (handler)The main handler function for the buy_supplies tool. It calculates the total cost of purchases based on fixed item prices, updates the inventory and money in the game state if sufficient funds are available, and tracks purchase history.const handleBuySupplies = (gameState, purchases) => { const prices = { cups: 0.05, lemons: 0.10, sugar: 0.08, ice: 0.02 }; let totalCost = 0; const newInventory = { ...gameState.inventory }; const purchaseRecord = { ...purchases, date: gameState.day }; for (const item of ['cups', 'lemons', 'sugar', 'ice']) { const amount = purchases[item] || 0; const cost = amount * prices[item]; totalCost += cost; newInventory[item] += amount; purchaseRecord[`${item}Cost`] = cost; } if (totalCost > gameState.money) { return { success: false, message: "Not enough money!" }; } purchaseRecord.totalCost = totalCost; return { success: true, gameState: { ...gameState, money: gameState.money - totalCost, inventory: newInventory, purchaseHistory: [...gameState.purchaseHistory, purchaseRecord], status: 'pricing' } }; };
- server.js:245-259 (schema)Defines the tool metadata including name, description, and input schema for validation of arguments (gameId required, optional quantities for cups, lemons, sugar, ice).{ name: "buy_supplies", description: "Purchase supplies for the lemonade stand", inputSchema: { type: "object", properties: { gameId: { type: "string", description: "The game ID" }, cups: { type: "number", description: "Number of cups to buy" }, lemons: { type: "number", description: "Number of lemons to buy" }, sugar: { type: "number", description: "Amount of sugar to buy" }, ice: { type: "number", description: "Amount of ice to buy" } }, required: ["gameId"] } },
- server.js:315-331 (registration)Registers and dispatches the buy_supplies tool call: validates game existence, invokes the handleBuySupplies function, persists updated game state, and returns the result as JSON.case 'buy_supplies': { const buyGame = games.get(request.params.arguments?.gameId); if (!buyGame) { throw new McpError(ErrorCode.InvalidRequest, "Game not found"); } const result = handleBuySupplies(buyGame, request.params.arguments); if (result.success) { games.set(request.params.arguments.gameId, result.gameState); } return { content: [{ type: "text", text: JSON.stringify(result) }] }; }