getShippingAddresses
Retrieve all shipping addresses for authenticated customers, including pickup locations with coordinates and postal codes.
Instructions
Retrieves all shipping addresses (pickup locations) for the authenticated customer. Returns complete list with coordinates and postal codes.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for the 'getShippingAddresses' MCP tool. It retrieves the API key, creates an API client, fetches all shipping addresses from the Europarcel API, formats them using the helper function, and returns a formatted text response or error.async () => { // Get API key from async context const apiKey = apiKeyStorage.getStore(); if (!apiKey) { return { content: [ { type: "text", text: "Error: X-API-KEY header is required", }, ], }; } // Create API client with customer's API key const client = new EuroparcelApiClient(apiKey); try { logger.info("Fetching all shipping addresses"); const response = await client.getShippingAddresses({ all: true, }); logger.info(`Retrieved ${response.list.length} shipping addresses`); let formattedResponse = `Found ${response.meta.total} shipping address${response.meta.total !== 1 ? "es" : ""}:\n\n`; if (response.list.length === 0) { formattedResponse += "No shipping addresses found."; } else { response.list.forEach((address: ShippingAddress) => { formattedResponse += formatAddress(address, "Shipping") + "\n"; }); } return { content: [ { type: "text", text: formattedResponse, }, ], }; } catch (error: any) { logger.error("Failed to fetch shipping addresses", error); return { content: [ { type: "text", text: `Error fetching shipping addresses: ${error.message || "Unknown error"}`, }, ], }; } }, );
- src/tools/addresses/getShippingAddresses.ts:34-107 (registration)Registers the 'getShippingAddresses' tool on the MCP server, including the tool name, schema (title, description, empty inputSchema), and handler callback.export function registerGetShippingAddressesTool(server: McpServer): void { // Create API client instance // Register getShippingAddresses tool server.registerTool( "getShippingAddresses", { title: "Get All Shipping Addresses", description: "Retrieves all shipping addresses (pickup locations) for the authenticated customer. Returns complete list with coordinates and postal codes.", inputSchema: {}, }, async () => { // Get API key from async context const apiKey = apiKeyStorage.getStore(); if (!apiKey) { return { content: [ { type: "text", text: "Error: X-API-KEY header is required", }, ], }; } // Create API client with customer's API key const client = new EuroparcelApiClient(apiKey); try { logger.info("Fetching all shipping addresses"); const response = await client.getShippingAddresses({ all: true, }); logger.info(`Retrieved ${response.list.length} shipping addresses`); let formattedResponse = `Found ${response.meta.total} shipping address${response.meta.total !== 1 ? "es" : ""}:\n\n`; if (response.list.length === 0) { formattedResponse += "No shipping addresses found."; } else { response.list.forEach((address: ShippingAddress) => { formattedResponse += formatAddress(address, "Shipping") + "\n"; }); } return { content: [ { type: "text", text: formattedResponse, }, ], }; } catch (error: any) { logger.error("Failed to fetch shipping addresses", error); return { content: [ { type: "text", text: `Error fetching shipping addresses: ${error.message || "Unknown error"}`, }, ], }; } }, ); logger.info("getShippingAddresses tool registered successfully"); }
- Input/output schema definition for the tool: empty input schema, with title and description.{ title: "Get All Shipping Addresses", description: "Retrieves all shipping addresses (pickup locations) for the authenticated customer. Returns complete list with coordinates and postal codes.", inputSchema: {}, },
- src/tools/addresses/index.ts:7-16 (registration)Top-level registration function that calls registerGetShippingAddressesTool(server) to register the tool as part of address tools group.export function registerAddressTools(server: McpServer): void { logger.info("Registering address tools..."); // Register all address-related tools registerGetBillingAddressesTool(server); registerGetShippingAddressesTool(server); registerGetDeliveryAddressesTool(server); logger.info("All address tools registered successfully"); }
- Helper function to format a shipping address into a readable string for the tool's output.function formatAddress(address: any, type: string): string { let details = `${type} Address #${address.id}: - Type: ${address.address_type} - Contact: ${address.contact} - Phone: ${address.phone} - Email: ${address.email} - Location: ${address.locality_name}, ${address.county_name} (${address.country_code}) - Street: ${address.street_name || "N/A"} ${address.street_no}${address.street_details ? ", " + address.street_details : ""}`; if ((type === "Shipping" || type === "Delivery") && address.zipcode) { details += ` - Zip Code: ${address.zipcode}`; } if ((type === "Shipping" || type === "Delivery") && address.coordinates) { details += ` - Coordinates: ${address.coordinates.lat}, ${address.coordinates.lng}`; } details += ` - Default: ${address.is_default ? "Yes" : "No"} `; return details; }