# USPS shipments through an agent

Use these tools to ship an existing paid store order containing products sold as `physical_manual`. The connected organization must have USPS configured in **Integrations**, and the credential must belong to a current organization owner or administrator. Use `puppetto_get_authorized_context` to confirm the organization first. Credentials stay encrypted on the server; do not request USPS secrets in chat.

The [customer setup guide](https://puppetto.com/blog/posts/ship-handmade-products-with-usps) covers USPS Ship enrollment, EPS, credentials, product setup, and printing. Manual products can also be created with `puppetto_create_product_template` and `data.listingKind: "physical_manual"`, then the existing variant, pricing, collection, and publishing tools.

## Shipment workflow

1. Discover orders with `puppetto_list_commerce_orders`, then read the selected order with `puppetto_get_commerce_order_bundle`. Read all item pages when needed.
2. Call `puppetto_get_usps_shipping` with the `orderId`. Use its `canCreate`, `disabledReason`, `manualItems`, `toAddress`, and `environment`. The delivery address comes from the order; agents cannot override it in the purchase request. If USPS is unconfigured, hand off to organization Integrations using the setup guide.
3. Obtain the sender address, actual sealed-package weight in **ounces**, dimensions in **inches**, service, handling category, and mailing date from the person packing it. One package contains all manual items. Do not invent measurements or include Printful/Slant3D/digital items.
4. Obtain authorization to buy postage from the organization's USPS EPS account. A production label purchases postage; this API does not provide a rate quote first. In `test`, labels are watermarked and buy no postage. Pass the environment you just inspected as `expectedEnvironment`; a mismatch is rejected.
5. Call `puppetto_create_usps_label`. Save its label ID, environment, tracking number, postage, and status. Creating the label does **not** mark the order shipped.
6. Call `puppetto_download_usps_label` with `orderId` and the explicit label `environment`. Decode `base64` into the returned `filename` as an `application/pdf` file for private download or printing. The PDF contains addresses; do not publish it or place it in public storage.
7. After the person confirms physical carrier handoff, call `puppetto_mark_usps_shipped` with `confirmCarrierHandoff: true`. Only a production label can be used. Read shipping state and the order again to report tracking and updated status. Mixed orders keep their other fulfillment groups' status.

Example label request (replace the IDs, addresses, mailing date, and measured package values):

```json
{
  "orderId": "<order UUID>",
  "expectedEnvironment": "test",
  "fromAddress": {
    "name": "Artisan Studio",
    "address1": "100 Main St",
    "city": "Portland",
    "stateCode": "OR",
    "zip": "97201",
    "countryCode": "US"
  },
  "package": {
    "mailClass": "USPS_GROUND_ADVANTAGE",
    "weightOz": 24,
    "lengthIn": 12,
    "widthIn": 8,
    "heightIn": 6,
    "processingCategory": "MACHINABLE",
    "mailingDate": "<YYYY-MM-DD>"
  },
  "confirmPostageCharge": true
}
```

Use `PRIORITY_MAIL` for the other supported service. Mailing dates must be within the next seven days. Own packaging only; no flat-rate packaging or international customs labels. This release does not schedule pickups, monitor delivery, split manual packages, or void/refund postage.

## Retry and recovery

Web and MCP share one durable purchase record per order and environment. Retrying after success returns the saved label. Concurrent web/agent calls cannot purchase a second label. A test record does not block a later production record.

After a timeout or restart, **read first**. `creating` or `review` may mean postage was bought; never automatically buy again. If `canRecover` is true, `puppetto_download_usps_label` can recover the saved carrier response without contacting USPS. If recovery fails or no response was saved, have the organization reconcile the purchase in its USPS account and contact support with the order ID. Do not delete the purchase lock, change environments to bypass it, or treat a timeout as proof of no charge.

A definitive carrier rejection can leave status `failed` and `canCreate: true`. Correct the reported problem and explicitly authorize a corrected request. Do not loop retries. Repeating carrier handoff is safe once it has succeeded.

Organization identity comes from the verified MCP credential, never tool arguments. API keys and owner/admin access are rechecked before every call, including saved-label readback.
