calculate_discount
Calculate discounted prices for art supplies using percentage, fixed amount, loyalty, or bulk order discounts based on product SKU and quantity.
Instructions
Calculate discounted price for promotions, bulk orders, or loyalty rewards.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sku": "<sku>",
"discountType": "<discountType>",
"discountValue": "<discountValue>"
},
"name": "calculate_discount"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| discountType | Yes | Type: percentage, fixed, loyalty, bulk | |
| discountValue | Yes | Discount percentage or fixed amount | |
| quantity | No | Quantity for bulk pricing | |
| sku | Yes | Product SKU |
Implementation Reference
- src/index.ts:299-311 (schema)Defines the input schema for the calculate_discount tool, specifying parameters like sku, discountType, discountValue, and optional quantity.
name: 'calculate_discount', description: 'Calculate discounted price for promotions, bulk orders, or loyalty rewards.', inputSchema: { type: 'object', properties: { sku: { type: 'string', description: 'Product SKU' }, discountType: { type: 'string', description: 'Type: percentage, fixed, loyalty, bulk' }, discountValue: { type: 'number', description: 'Discount percentage or fixed amount' }, quantity: { type: 'number', description: 'Quantity for bulk pricing' }, }, required: ['sku', 'discountType', 'discountValue'], }, }, - src/index.ts:516-518 (registration)Registers all tools including calculate_discount by returning the tools array in response to ListToolsRequestSchema.
server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; }); - src/index.ts:961-1002 (handler)The handler function for calculate_discount: parses arguments, finds product in inventory, applies discount based on type, computes final price and total, returns formatted response.
case 'calculate_discount': { const sku = String(args?.sku || ''); const discountType = String(args?.discountType || 'percentage'); const discountValue = Number(args?.discountValue || 0); const quantity = Number(args?.quantity || 1); const item = storeData.inventory.find(i => i.id === sku); if (!item) { return { content: [{ type: 'text', text: `❌ Product ${sku} not found` }] }; } let finalPrice = item.price; let discount = 0; switch (discountType) { case 'percentage': discount = item.price * (discountValue / 100); finalPrice = item.price - discount; break; case 'fixed': discount = discountValue; finalPrice = item.price - discount; break; case 'loyalty': discount = discountValue / 10; finalPrice = item.price - discount; break; case 'bulk': if (quantity >= 5) { discount = item.price * 0.15; finalPrice = item.price - discount; } break; } return { content: [{ type: 'text', text: `💲 Price Calculation: ${item.name}\n\n- Original Price: $${item.price}\n- Discount Type: ${discountType}\n- Discount Amount: $${discount.toFixed(2)}\n- Final Price: $${finalPrice.toFixed(2)}\n- Quantity: ${quantity}\n- Total: $${(finalPrice * quantity).toFixed(2)}` }] }; }