Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
discountTypeYesType: percentage, fixed, loyalty, bulk
discountValueYesDiscount percentage or fixed amount
quantityNoQuantity for bulk pricing
skuYesProduct SKU

Implementation Reference

  • 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 }; });
  • 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)}` }] }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wspotter/mcpart'

If you have feedback or need assistance with the MCP directory API, please join our Discord server