@commercengine/ai is designed around explicit capabilities and a narrow commerce safety boundary. The agent gets structured tools instead of DOM access, and each tool exposes only the data needed for that operation.
WebMCP status
WebMCP is an evolving browser capability. Commerce Engine prefersdocument.modelContext and retains compatibility where browser implementations differ.
In unsupported browsers:
Default tool inventory
Catalog
Session and cart
These are included when the storefront exposes a browser session client. Registration can happen before that session is bootstrapped; calls return a retryable not-ready failure until the session is usable.Navigation / UI bridges
No autonomous purchase completion
Commerce Engine deliberately does not provide tools for:- entering passwords or OTPs
- selecting saved payment instruments
- typing card/bank details
- entering addresses on behalf of the user
- placing an order
- confirming payment
Safe cart projection
get_cart and mutation results return an allow-listed representation. That boundary matters because the canonical Commerce Engine cart can evolve over time; new API fields must not silently become agent-visible.
The agent-facing projection includes commerce fields such as:
- cart ID
- line ID
- product/variant identifiers
- names/SKUs necessary to identify the line
- paid quantity, free quantity, total quantity
- pricing/currency/totals
- availability and order-quantity constraints
- whether a line is removable
Cart mutation rules
add_to_cart
Adds to the existing paid quantity. It can accept a small batch of items in one invocation.
For an existing cart, additions are applied sequentially. If a later line fails, the tool reports the lines already applied rather than pretending the whole request was atomic.
set_cart_item_quantity
Sets an absolute paid quantity for one existing line.
- positive values must satisfy
minOrderQuantity,maxOrderQuantity, andincrementalQuantity 0means removal only when the line is removable- malformed values such as
null,false, empty strings, or fractional numbers are rejected rather than coerced into a removal signal
Promotional/free quantities
A free promotion line or free units attached to a paid line cannot be treated as shopper-selected quantity.Cancellation and confirmed mutations
Tool execution may receive anAbortSignal. The package checks cancellation around asynchronous work, but the Commerce Engine SDK does not currently abort an already-started network request.
Therefore cancellation is not rollback.
If the server has already applied a mutation and returned the resulting cart, the tool returns that confirmed state even if cancellation arrived around the same time. This prevents an agent from retrying an already-applied add and duplicating quantity.
Anonymous sessions
Anonymous shoppers have real Commerce Engine sessions. Cart tools do not require sign-in. The same browser session can evolve from anonymous to authenticated, preserving the guest cart. This is not a cross-device cart-merge guarantee.get_session_state reports status, not identity:
Route trust
Public route shapes should be shared with@commercengine/seo:
External navigation
Navigation is same-origin unless an origin is explicitly allowed:Untrusted merchant content
Catalog text and policy/FAQ results are data, not instructions. Commerce Engine marks appropriate tool results as untrusted content and keeps tool descriptions/schema package-authored. This prevents a malicious product description from redefining what a tool does.Input constraints
Tool schemas use narrow types, bounded free-form strings, andadditionalProperties: false where appropriate. Runtime validation is still defensive; safety does not depend on the calling model obeying JSON Schema perfectly.
Diagnostics
Configure diagnostics during integration:- diagnostic says unsupported → mount code ran; browser lacks WebMCP
- diagnostic says registered → package reached
modelContext.registerTool - no diagnostic at all → your registration block likely never executed
Test the tool set without WebMCP
createCommerceAiTools() is DOM-free:
Extend the module set
Commerce AI tools are built from plain modules.extraModules to append merchant-specific tools. Use modules only when you intentionally want to replace the default module list.
A duplicate tool name is a composition error and should fail early rather than allow two implementations to compete.
Policy/FAQ bridge
Merchant editorial content is intentionally an extension point rather than a CMS-specific dependency:Recommended review checklist
Before enabling agent tools in production:- tools are registered only once per live browser document/runtime
- registration is aborted on component/runtime teardown
- diagnostics are visible in development
- public routes resolve to the same URLs as SEO
- external navigation allow-list is explicit
- no custom tool exposes tokens, addresses, raw customer objects, or payment data
- cart tools return the resulting cart after mutations
- checkout completion remains human-controlled
- custom CMS output is treated as untrusted content
AI package
Setup and common integration patterns.
Agent Skills
Teach coding agents the same contracts.