Create Shipment
create_shipmentCreate a UPS shipment and generate a shipping label with tracking number and charges for domestic and international services.
Instructions
Create a UPS shipment and generate a shipping label. Supports all UPS domestic and international services. Returns tracking number, charges, and label image (base64-encoded GIF by default). Common service codes: 03=Ground, 02=2nd Day Air, 01=Next Day Air, 13=Next Day Air Saver, 12=3 Day Select, 07=Express (intl), 11=Standard (intl).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service | No | UPS service code (e.g. "03" for Ground, "01" for Next Day Air) | 03 |
| shipFrom | Yes | Origin/sender address | |
| shipTo | Yes | Destination/recipient address | |
| packages | Yes | Array of packages (1-200) | |
| description | No | Shipment description | |
| referenceNumber | No | Your reference number for this shipment | |
| labelFormat | No | Label image format | GIF |
Implementation Reference
- src/tools/shipping.ts:15-109 (registration)Tool registration entry point - addShippingTools function that registers 'create_shipment' with the MCP server
export function addShippingTools(server: McpServer, client: UPSHttpClient): void { server.registerTool( 'create_shipment', { title: 'Create Shipment', description: 'Create a UPS shipment and generate a shipping label. Supports all UPS domestic and international services. Returns tracking number, charges, and label image (base64-encoded GIF by default). Common service codes: 03=Ground, 02=2nd Day Air, 01=Next Day Air, 13=Next Day Air Saver, 12=3 Day Select, 07=Express (intl), 11=Standard (intl).', inputSchema: { service: z .string() .default('03') .describe('UPS service code (e.g. "03" for Ground, "01" for Next Day Air)'), shipFrom: fullAddressSchema.describe('Origin/sender address'), shipTo: fullAddressSchema.describe('Destination/recipient address'), packages: z .array(shippingPackageSchema) .min(1) .max(SHIPMENT_LIMITS.MAX_PACKAGES) .describe('Array of packages (1-200)'), description: z.string().optional().describe('Shipment description'), referenceNumber: z.string().optional().describe('Your reference number for this shipment'), labelFormat: z .enum(['GIF', 'EPL', 'ZPL', 'SPL', 'STARPL']) .default('GIF') .describe('Label image format'), }, }, async ({ service, shipFrom, shipTo, packages, description, referenceNumber, labelFormat }) => { const accountNumber = client.getAccountNumber(); const shipFromAddress = buildUPSAddress(shipFrom); const shipToAddress = buildUPSAddress(shipTo); const shipmentRequest = { ShipmentRequest: { Request: { SubVersion: API_VERSIONS.SHIPPING, RequestOption: SHIPMENT_REQUEST_OPTIONS.NON_VALIDATE, TransactionReference: { CustomerContext: referenceNumber ?? '' }, }, Shipment: { Description: description ?? '', Shipper: { ...shipFromAddress, ShipperNumber: accountNumber ?? '' }, ShipTo: shipToAddress, ShipFrom: shipFromAddress, PaymentInformation: { ShipmentCharge: [ { Type: CHARGE_TYPES.TRANSPORTATION, BillShipper: { AccountNumber: accountNumber ?? '' }, }, ], }, Service: { Code: service, Description: '' }, Package: packages.map((pkg) => ({ Packaging: { Code: pkg.packaging ?? '02', Description: '' }, Dimensions: pkg.length ? buildDimensions(pkg.length, pkg.width, pkg.height) : undefined, PackageWeight: buildWeight(pkg.weight), Description: pkg.description ?? '', ...(pkg.insuredValue ? { PackageServiceOptions: { DeclaredValue: { CurrencyCode: 'USD', MonetaryValue: String(pkg.insuredValue), }, }, } : {}), })), ...(referenceNumber ? { ReferenceNumber: { Code: REFERENCE_TYPES.PURCHASE_ORDER, Value: referenceNumber, }, } : {}), }, LabelSpecification: { LabelImageFormat: { Code: labelFormat, Description: '' }, LabelStockSize: { Height: LABEL_STOCK.HEIGHT, Width: LABEL_STOCK.WIDTH }, }, }, }; const response = await client.post<unknown>( `/api/shipments/${API_VERSIONS.SHIPPING}/ship`, shipmentRequest, ); return formatToolResponse(response); }, ); - src/tools/shipping.ts:42-108 (handler)Handler function that executes the create_shipment logic: builds the UPS ShipmentRequest, calls the API endpoint, and returns formatted response
async ({ service, shipFrom, shipTo, packages, description, referenceNumber, labelFormat }) => { const accountNumber = client.getAccountNumber(); const shipFromAddress = buildUPSAddress(shipFrom); const shipToAddress = buildUPSAddress(shipTo); const shipmentRequest = { ShipmentRequest: { Request: { SubVersion: API_VERSIONS.SHIPPING, RequestOption: SHIPMENT_REQUEST_OPTIONS.NON_VALIDATE, TransactionReference: { CustomerContext: referenceNumber ?? '' }, }, Shipment: { Description: description ?? '', Shipper: { ...shipFromAddress, ShipperNumber: accountNumber ?? '' }, ShipTo: shipToAddress, ShipFrom: shipFromAddress, PaymentInformation: { ShipmentCharge: [ { Type: CHARGE_TYPES.TRANSPORTATION, BillShipper: { AccountNumber: accountNumber ?? '' }, }, ], }, Service: { Code: service, Description: '' }, Package: packages.map((pkg) => ({ Packaging: { Code: pkg.packaging ?? '02', Description: '' }, Dimensions: pkg.length ? buildDimensions(pkg.length, pkg.width, pkg.height) : undefined, PackageWeight: buildWeight(pkg.weight), Description: pkg.description ?? '', ...(pkg.insuredValue ? { PackageServiceOptions: { DeclaredValue: { CurrencyCode: 'USD', MonetaryValue: String(pkg.insuredValue), }, }, } : {}), })), ...(referenceNumber ? { ReferenceNumber: { Code: REFERENCE_TYPES.PURCHASE_ORDER, Value: referenceNumber, }, } : {}), }, LabelSpecification: { LabelImageFormat: { Code: labelFormat, Description: '' }, LabelStockSize: { Height: LABEL_STOCK.HEIGHT, Width: LABEL_STOCK.WIDTH }, }, }, }; const response = await client.post<unknown>( `/api/shipments/${API_VERSIONS.SHIPPING}/ship`, shipmentRequest, ); return formatToolResponse(response); }, - src/tools/shipping.ts:22-41 (schema)Input schema for create_shipment tool: defines service, shipFrom, shipTo, packages, description, referenceNumber, labelFormat with Zod validation
inputSchema: { service: z .string() .default('03') .describe('UPS service code (e.g. "03" for Ground, "01" for Next Day Air)'), shipFrom: fullAddressSchema.describe('Origin/sender address'), shipTo: fullAddressSchema.describe('Destination/recipient address'), packages: z .array(shippingPackageSchema) .min(1) .max(SHIPMENT_LIMITS.MAX_PACKAGES) .describe('Array of packages (1-200)'), description: z.string().optional().describe('Shipment description'), referenceNumber: z.string().optional().describe('Your reference number for this shipment'), labelFormat: z .enum(['GIF', 'EPL', 'ZPL', 'SPL', 'STARPL']) .default('GIF') .describe('Label image format'), }, }, - src/types/shipping.ts:203-215 (schema)TypeScript interface CreateShipmentParams defining all parameters for creating a shipment
export interface CreateShipmentParams { readonly service: UPSServiceCode; readonly shipFrom: UPSAddress; readonly shipTo: UPSAddress; readonly packages: readonly ShipmentPackage[]; readonly description?: string; readonly referenceNumber?: string; readonly labelFormat?: LabelFormat; readonly returnService?: ReturnServiceCode; readonly paymentInformation?: PaymentInformation; readonly shipmentServiceOptions?: ShipmentServiceOptions; readonly documentsOnly?: boolean; } - src/tools/builders.ts:50-54 (helper)Helper that wraps API response into MCP tool output format with JSON text content
export function formatToolResponse(response: unknown) { return { content: [{ type: 'text' as const, text: JSON.stringify(response, null, 2) }], }; }