calculate_vat_amount
Calculate VAT amounts from net or gross values. Returns net amount, VAT amount, gross amount, rate, and currency for pricing tools or checkout flows.
Instructions
Calculates VAT amounts from either a net (excluding VAT) or gross (including VAT) amount for a given VAT rate. Returns { net_amount, vat_amount, gross_amount, vat_rate, currency }. Use when building pricing tools, invoice calculators, or checkout flows that need to split gross prices into net + VAT components.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | The amount to calculate VAT for | |
| vat_rate | Yes | VAT rate as a percentage. Example: 23 for 23% | |
| amount_type | Yes | Whether the input amount is net (excluding VAT) or gross (including VAT) | |
| currency | No | Currency code. Example: 'EUR', 'GBP'. Defaults to 'EUR' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| net_amount | Yes | ||
| vat_amount | Yes | ||
| gross_amount | Yes | ||
| vat_rate | Yes | ||
| currency | Yes |
Implementation Reference
- index.js:1006-1016 (registration)Registration of the 'calculate_vat_amount' tool with its input schema (amount, vat_rate, amount_type, currency), output schema (net_amount, vat_amount, gross_amount, vat_rate, currency), and description.
server.registerTool("calculate_vat_amount", { description: "Calculates VAT amounts from either a net (excluding VAT) or gross (including VAT) amount for a given VAT rate. Returns { net_amount, vat_amount, gross_amount, vat_rate, currency }. Use when building pricing tools, invoice calculators, or checkout flows that need to split gross prices into net + VAT components.", inputSchema: { amount: z.number().describe("The amount to calculate VAT for"), vat_rate: z.number().describe("VAT rate as a percentage. Example: 23 for 23%"), amount_type: z.enum(["net", "gross"]).describe("Whether the input amount is net (excluding VAT) or gross (including VAT)"), currency: z.string().optional().describe("Currency code. Example: 'EUR', 'GBP'. Defaults to 'EUR'") }, outputSchema: { net_amount: z.number(), vat_amount: z.number(), gross_amount: z.number(), vat_rate: z.number(), currency: z.string() }, annotations: { title: "Calculate VAT Amount", readOnlyHint: true, idempotentHint: true, openWorldHint: false } }, async ({ amount, vat_rate, amount_type, currency = "EUR" }) => { - index.js:1008-1015 (schema)Input and output schema definitions for the calculate_vat_amount tool. Input takes an amount, VAT rate percentage, amount type (net or gross), and optional currency. Output returns net_amount, vat_amount, gross_amount, vat_rate, and currency.
inputSchema: { amount: z.number().describe("The amount to calculate VAT for"), vat_rate: z.number().describe("VAT rate as a percentage. Example: 23 for 23%"), amount_type: z.enum(["net", "gross"]).describe("Whether the input amount is net (excluding VAT) or gross (including VAT)"), currency: z.string().optional().describe("Currency code. Example: 'EUR', 'GBP'. Defaults to 'EUR'") }, outputSchema: { net_amount: z.number(), vat_amount: z.number(), gross_amount: z.number(), vat_rate: z.number(), currency: z.string() }, annotations: { title: "Calculate VAT Amount", readOnlyHint: true, idempotentHint: true, openWorldHint: false } - index.js:1016-1029 (handler)Handler function for calculate_vat_amount. Calculates VAT from either a net (excl. VAT) or gross (incl. VAT) amount for a given VAT rate percentage. Returns net_amount, vat_amount, gross_amount rounded to 2 decimal places.
}, async ({ amount, vat_rate, amount_type, currency = "EUR" }) => { const round = (n) => Math.round(n * 100) / 100; let net, vat, gross; if (amount_type === "net") { net = round(amount); vat = round(amount * vat_rate / 100); gross = round(net + vat); } else { gross = round(amount); net = round(amount / (1 + vat_rate / 100)); vat = round(gross - net); } return { content: [{ type: "text", text: JSON.stringify({ net_amount: net, vat_amount: vat, gross_amount: gross, vat_rate, currency }) }] }; });