@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+:Run the complete example
Save this aspurchasing-demo.mjs:
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.- Resolve the supplier using a stored mapping. Creating a supplier on every run is suitable for this fresh demonstration database, not a synchronization strategy.
- Retain an external procurement-request identity and its returned PO ID. The published
createsignature has no idempotency-key parameter; a lost response is not a reason to create another PO without reconciliation. - Enforce approval permissions and amount limits before calling
approve. A caller-supplied name does not prove the approver’s identity or authority. - Use your configured connector to deliver the approved document. Record its delivery ID, outcome, and supplier acknowledgement separately; reconcile partial failures before retrying.
- 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.
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 everyCONFLICT as success; the example’s conflicts are rejected
transitions. See error handling and retries.
Troubleshooting
Next steps
- Warehouse receiving: count expected and received units separately from inventory.
- Your first operation: connect a persistent local fixture to an agent.
- Integration test plan: verify persistence and recovery behavior.