chargeable_weight_calculator
Calculate air freight chargeable weight by comparing actual and volumetric weight with an adjustable divisor.
Instructions
Calculate air freight chargeable weight (volumetric vs actual).
Airlines charge by "chargeable weight" — the greater of actual weight or volumetric weight. The IATA standard volumetric factor is 6,000 (1 CBM = 166.67 kg). Some carriers use different factors (e.g., 5,000 for DHL).
Use this tool when you need to:
Quote air freight shipments
Determine if a shipment is charged by volume or weight
Compare volumetric factors across carriers
A ratio > 1.0 means the shipment is "volumetric" (light for its size). A ratio < 1.0 means it's "heavy" (dense cargo).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| length_cm | Yes | Length in centimetres | |
| width_cm | Yes | Width in centimetres | |
| height_cm | Yes | Height in centimetres | |
| gross_weight_kg | Yes | Actual gross weight in kilograms | |
| pieces | No | Number of identical pieces (default: 1) | |
| factor | No | Volumetric divisor (default: 6000 IATA standard, DHL uses 5000) |
Implementation Reference
- src/tools.ts:95-99 (handler)The handler function that executes chargeable_weight_calculator logic. Calls the external FreightUtils API endpoint 'chargeable-weight' via apiGet, passing length_cm, width_cm, height_cm, gross_weight_kg, pieces, and factor as query parameters.
handler: async (args) => apiGet('chargeable-weight', { l: args.length_cm, w: args.width_cm, h: args.height_cm, gw: args.gross_weight_kg, pcs: args.pieces, factor: args.factor, }), - src/tools.ts:84-91 (schema)Zod schema defining input validation for chargeable_weight_calculator. Accepts length_cm, width_cm, height_cm, gross_weight_kg (required positives), plus optional pieces (default 1) and factor (default 6000 IATA standard). Uses .strict() to reject unknown keys.
schema: z.object({ length_cm: z.number().positive().describe('Length in centimetres'), width_cm: z.number().positive().describe('Width in centimetres'), height_cm: z.number().positive().describe('Height in centimetres'), gross_weight_kg: z.number().positive().describe('Actual gross weight in kilograms'), pieces: z.number().int().positive().optional().describe('Number of identical pieces (default: 1)'), factor: z.number().int().positive().optional().describe('Volumetric divisor (default: 6000 IATA standard, DHL uses 5000)'), }).strict(), - src/tools.ts:713-715 (registration)The tool is registered in the ALL_TOOLS array, which is iterated by the server to register each tool with the MCP SDK via server.tool().
export const ALL_TOOLS: ToolDef[] = [ cbmCalculator, chargeableWeightCalculator, - src/server.ts:18-41 (registration)Server registration: iterates ALL_TOOLS and calls server.tool() for each tool definition, wrapping handler results in text content for MCP response protocol.
// Register every tool for (const tool of ALL_TOOLS) { server.tool( tool.name, tool.description, tool.schema.shape, tool.annotations, async (args: Record<string, unknown>) => { try { const result = await tool.handler(args); return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2) }, ], }; } catch (err: unknown) { const message = err instanceof Error ? err.message : String(err); return { content: [{ type: 'text' as const, text: `Error: ${message}` }], isError: true, }; } }, ); - src/api.ts:7-24 (helper)The apiGet helper function used by the chargeable_weight_calculator handler to make GET requests to the external FreightUtils API.
export async function apiGet(endpoint: string, params: Record<string, unknown>): Promise<unknown> { const url = new URL(`${BASE_URL}/${endpoint}`); for (const [k, v] of Object.entries(params)) { if (v === undefined || v === null || v === '') continue; url.searchParams.set(k, String(v)); } const res = await fetch(url.toString(), { headers: { 'Accept': 'application/json' }, }); if (!res.ok) { const body = await res.text(); throw new Error(`FreightUtils API error ${res.status}: ${body}`); } return res.json(); }