Skip to main content
Create a supplier and a purchase order for ten mugs at a unit cost of five. Submit it for approval, approve it, and record it as sent. Check the stored state after each step and verify that invalid transitions leave the record unchanged. This walkthrough uses @stateset/embedded 1.35.1 and a temporary local database. It needs no API key and makes no supplier deliveries.
purchaseOrders.send records the PO’s sent state. It does not email the supplier or submit an EDI document. Keep delivery evidence from your actual connector separate from this state.

Prerequisites

Use Node.js 20.20.0+ and npm 10+:
For native-module installation problems, see SDK installation.

Run the complete example

Save this as purchasing-demo.mjs:
Run it:
Success: all assertions pass and the output is:

Understand the records and approval boundary

The demonstrated path is draft → pending_approval → approved → sent. A draft cannot skip directly to sent. The separate cancellation case shows that a cancelled PO cannot be resubmitted through this path. The published Node input accepts numeric quantity and unitCost. This example uses whole numbers to make the total easy to verify. It does not expose a currency field in CreatePurchaseOrderInput; do not add an invented currency or unitCostExact parameter. Confirm currency and rounding requirements for the interface you choose before using it for real procurement. The returned PurchaseOrderOutput in this binding contains summary fields, not a PO line-item array or approval history. Retain your submitted line data and approval evidence in the owning system; do not write code that assumes po.items or po.approvedBy is present.

Connect purchasing to real operations

Before adapting this example, decide which system owns supplier identities, commercial terms, approval policy, and supplier delivery. The connection guide provides a mapping and task-brief template.
  1. Resolve the supplier using a stored mapping. Creating a supplier on every run is suitable for this fresh demonstration database, not a synchronization strategy.
  2. Retain an external procurement-request identity and its returned PO ID. The published create signature has no idempotency-key parameter; a lost response is not a reason to create another PO without reconciliation.
  3. Enforce approval permissions and amount limits before calling approve. A caller-supplied name does not prove the approver’s identity or authority.
  4. Use your configured connector to deliver the approved document. Record its delivery ID, outcome, and supplier acknowledgement separately; reconcile partial failures before retrying.
  5. Track the inbound goods and verify inventory through your receiving process. A PO marked sent does not prove supplier acceptance, receipt of goods, or available stock.
The warehouse receiving quickstart demonstrates a separate inbound shipment. It does not automatically link that shipment to this PO. Keep the relationship explicit in your integration, or use the receipt-from-PO operation supported by your chosen interface as described in receiving and put-away.

Give an agent a purchasing task

Start with a read-only request containing the actual PO ID: report its supplier ID, PO number, status, and exact total, with the tool results supporting the answer. Ask it to report supplier delivery and approval evidence as unknown unless those records are available. For a write task, specify the permitted transition, the approval policy, the authorized identity, and the procurement-request identity. A draft-creation task does not authorize approval or supplier delivery. Discover the installed server’s tool schemas instead of guessing MCP tool names from these Node methods. See the agent operating procedure. After a failed or interrupted call, read the exact PO before deciding whether further action is needed. Do not reinterpret every CONFLICT as success; the example’s conflicts are rejected transitions. See error handling and retries.

Troubleshooting

Next steps

Last modified on September 20, 2026