UCP Types
Universal Commerce Protocol type definitions for agentic commerce
@guardrail-sim/ucp-types
Type definitions aligned with the Universal Commerce Protocol for agentic commerce integration.
Installation
Overview
This package provides TypeScript types that align with the UCP specification, enabling guardrail-sim to integrate with the agentic commerce ecosystem. It includes:
- Discount types - Error codes, allocations, applied/rejected discounts
- Checkout types - Checkout sessions, line items, buyers, totals
- Converters - Functions to convert between policy engine results and UCP formats
Discount Types
DiscountErrorCode
Standard UCP error codes for discount validation.
Available codes:
discount_code_invalid- Code doesn't exist or exceeds limitsdiscount_code_expired- Code is past validity windowdiscount_code_already_applied- Code already in usediscount_code_combination_disallowed- Can't combine with other codesdiscount_code_user_not_logged_in- Requires authenticationdiscount_code_user_ineligible- User doesn't qualify
DiscountMethod
How discounts are allocated across line items.
AppliedDiscount
A successfully applied discount.
RejectedDiscount
A discount that was rejected.
DiscountValidationResult
Result of pre-checkout validation.
Checkout Types
LineItem
A product in the checkout.
Money
Currency amounts in minor units.
CheckoutResponse
A checkout session with discounts.
Converter Functions
toUCPErrorCode
Convert a policy violation to UCP error code.
toDiscountValidationResult
Convert policy evaluation to validation result.
buildDiscountExtensionResponse
Build a full UCP discount extension response.
calculateAllocations
Calculate how a discount is distributed across line items.
fromUCPLineItems
Convert UCP line items to policy engine format.
Usage with MCP Server
The MCP server's UCP-aligned tools use these types internally:
See Also
- MCP Tools Reference - UCP-aligned MCP tools
- UCP Concepts - UCP integration overview
- ADR-002: UCP Alignment - Design decision