tracking-delivery
Track parcel deliveries using a tracking number and carrier ID with the MCP server. Automatically detect carriers or specify manually for accurate results.
Instructions
Track a parcel delivery via 17TRACK
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| carrier | No | Carrier ID (number). If omitted, 17TRACK will auto-detect, but accuracy may be lower. | |
| number | Yes | The tracking number of the parcel |
Implementation Reference
- src/index.ts:180-225 (handler)The main handler function for the 'tracking-delivery' tool. Validates the carrier ID if provided, registers the tracking number with 17TRACK API, fetches the delivery information, and returns it as JSON. Handles errors and prompts for carrier if missing.async ({ number, carrier }) => { if (carrier && !validateCarrierId(carrier)) { return { content: [ { type: "text", text: `The carrier ID "${carrier}" is not valid. Please use the 'search-carrier' tool to find the correct carrier ID.`, } as const, ], }; } if (!carrier) { return { content: [ { type: "text", text: "Please specify the carrier ID along with the tracking number for more accurate results. You can use the 'search-carrier' tool to look up the carrier ID first.", } as const, ], }; } try { await register({ number, carrier }); const data = await getDelivery({ number, carrier }); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), } as const, ], }; } catch (error) { return { content: [ { type: "text", text: "Error tracking delivery: " + (error instanceof Error ? error.message : String(error)), } as const, ], }; } }
- src/index.ts:171-179 (schema)Zod input schema defining the parameters for the 'tracking-delivery' tool: required 'number' (tracking number as string) and optional 'carrier' (carrier ID as number). Includes descriptions for each parameter.{ number: z.string().describe("The tracking number of the parcel"), carrier: z .number() .optional() .describe( "Carrier ID (number). If omitted, 17TRACK will auto-detect, but accuracy may be lower." ), },
- src/index.ts:168-226 (registration)Registers the 'tracking-delivery' tool on the MCP server using server.tool(), providing the tool name, description, input schema, and handler function.server.tool( "tracking-delivery", "Track a parcel delivery via 17TRACK", { number: z.string().describe("The tracking number of the parcel"), carrier: z .number() .optional() .describe( "Carrier ID (number). If omitted, 17TRACK will auto-detect, but accuracy may be lower." ), }, async ({ number, carrier }) => { if (carrier && !validateCarrierId(carrier)) { return { content: [ { type: "text", text: `The carrier ID "${carrier}" is not valid. Please use the 'search-carrier' tool to find the correct carrier ID.`, } as const, ], }; } if (!carrier) { return { content: [ { type: "text", text: "Please specify the carrier ID along with the tracking number for more accurate results. You can use the 'search-carrier' tool to look up the carrier ID first.", } as const, ], }; } try { await register({ number, carrier }); const data = await getDelivery({ number, carrier }); return { content: [ { type: "text", text: JSON.stringify(data, null, 2), } as const, ], }; } catch (error) { return { content: [ { type: "text", text: "Error tracking delivery: " + (error instanceof Error ? error.message : String(error)), } as const, ], }; } } );
- src/index.ts:84-103 (helper)Helper function to register a tracking number with the 17TRACK API prior to querying status.async function register({ number, carrier }: Props) { const body = [ { number, carrier: carrier ?? 0, }, ]; const res = await fetch(`${TRACKER_API_BASE_URL}/register`, { method: "POST", headers: { "17token": apiToken, "Content-Type": "application/json", "User-Agent": USER_AGENT, }, body: JSON.stringify(body), }); return res.json(); }
- src/index.ts:105-124 (helper)Helper function to fetch the current delivery tracking information from the 17TRACK API.async function getDelivery({ number, carrier }: Props) { const body = [ { number, carrier: carrier ?? 0, }, ]; const res = await fetch(`${TRACKER_API_BASE_URL}/gettrackinfo`, { method: "POST", headers: { "17token": apiToken, "Content-Type": "application/json", "User-Agent": USER_AGENT, }, body: JSON.stringify(body), }); return res.json(); }