Skip to main content
Glama
baskcart

W3Ship MCP Server

by baskcart

track_shipment

Check the delivery status of your shipment using the Shipment ID or Order ID to monitor its progress and location.

Instructions

Track the delivery status of a shipment (TMF621).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
shipmentIdNoThe unique Shipment ID
orderIdNoThe Order ID (optional, to lookup shipment)

Implementation Reference

  • The handler implementation for the `track_shipment` tool, located in the `src/index.ts` file as part of the main `CallToolRequestSchema` request handler switch case.
    case 'track_shipment': {
        const { shipmentService } = await import('./shipment/service.js');
        const shipmentId = args?.shipmentId as string;
        const orderId = args?.orderId as string;
    
        let shipment;
        if (shipmentId) {
            shipment = await shipmentService.getShipment(shipmentId);
        } else if (orderId) {
            shipment = await shipmentService.getShipmentByOrderId(orderId);
        } else {
            return { content: [{ type: 'text', text: `Error: Must provide shipmentId or orderId.` }], isError: true };
        }
    
        if (!shipment) {
            return { content: [{ type: 'text', text: `Error: Shipment not found.` }], isError: true };
        }
    
        // Simulate status update based on time elapsed
        const createdTime = new Date(shipment.events[0].timestamp).getTime();
        const now = Date.now();
        const minutesElapsed = (now - createdTime) / 60000;
    
        let newStatus = shipment.status;
        if (minutesElapsed > 5 && shipment.status === 'Label Created') newStatus = 'Picked Up';
        else if (minutesElapsed > 10 && shipment.status === 'Picked Up') newStatus = 'In Transit';
        else if (minutesElapsed > 20 && shipment.status === 'In Transit') newStatus = 'Out for Delivery';
        else if (minutesElapsed > 30 && shipment.status === 'Out for Delivery') newStatus = 'Delivered';
    
        if (newStatus !== shipment.status) {
            shipment.status = newStatus as any;
            shipment.events.push({
                timestamp: new Date().toISOString(),
                status: newStatus,
                description: `Status updated to ${newStatus}`
            });
            await shipmentService.updateShipment(shipment);
        }
    
        return { content: [{ type: 'text', text: JSON.stringify(shipment, null, 2) }] };
    }
  • The tool definition and input schema for `track_shipment` in the `ListToolsRequestSchema` handler.
        name: 'track_shipment',
        description: 'Track the delivery status of a shipment (TMF621).',
        inputSchema: {
            type: 'object',
            properties: {
                shipmentId: { type: 'string', description: 'The unique Shipment ID' },
                orderId: { type: 'string', description: 'The Order ID (optional, to lookup shipment)' },
            },
        },
    },

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/baskcart/w3ship-mcp-server'

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