Search by

run-as-root / module-agentic-commerce-protocol

DavidLambauer

Agentic Commerce Protocol for Magento 2 and Mage-OS: product feed and checkout API for AI agents

Package info

github.com/run-as-root/ACP-for-Magento-2

Type:magento2-module

pkg:composer/run-as-root/module-agentic-commerce-protocol

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 13

Open Issues: 0

0.4.0 2026-12-01 18:34 UTC

This package is auto-updated.

Last update: 2026-12-01 18:36:26 UTC


README

Connects a Magento 2 / Mage-OS store to AI agents through the Agentic Commerce Protocol (ACP): a product feed in the format ChatGPT ingests, and the protocol's checkout API.

License: MIT Tests

Status

Part State
Product feed Follows the current OpenAI product feed spec. Verified on Mage-OS 4 (Magento 2.4.9 code base); compiles on Magento Open Source 2.4.7 to 2.4.9.
Checkout API Implements the Agentic Checkout API of ACP 2026-04-17, as REST API and as MCP tools. Its responses validate against the protocol's JSON schema, and the whole flow is tested on Mage-OS 4 against a stubbed Stripe API. It has not been run against a live agent platform or a live Stripe account. Treat it as beta and test in a sandbox first.

OpenAI's current merchant documentation for ChatGPT describes paying on the merchant's own checkout (ChatGPT Wallet) and plugins, not this REST API. Ask your agent platform which ACP version and transport it speaks before you build on the checkout API.

Requirements

  • Magento Open Source 2.4.7+ or Mage-OS
  • PHP 8.1+

Installation

composer require run-as-root/module-agentic-commerce-protocol
bin/magento module:enable RunAsRoot_AgenticCommerceProtocol
bin/magento setup:upgrade

Product feed

The feed is JSON Lines: one JSON object per line, one line per purchasable item.

{"item_id":"MUG-350","title":"Blue ceramic mug, 350 mL","description":"Holds 350 mL.","url":"https://example.com/blue-mug.html","brand":"Northline","seller_name":"Northline Home","image_url":"https://example.com/media/catalog/product/m/u/mug.jpg","availability":"in_stock","price":"18.00 EUR","target_countries":["DE","AT"],"store_country":"DE","sale_price":"14.50 EUR","product_category":"Kitchen > Mugs","seller_url":"https://example.com/","is_eligible_search":true,"is_eligible_checkout":false}

What ends up in it:

  • Simple, virtual, downloadable and bundle products get one row each.
  • Configurable products get one row per enabled variant. The rows share a group_id (the SKU of the configurable product) and carry the selected options in variant_dict.
  • Grouped products are not exported; their simple products are, when they are visible on their own.
  • item_id is the SKU.
  • price is the regular price and sale_price the final price when it is lower, both as shown in the store.
  • Out-of-stock products are exported with availability: out_of_stock.
  • Values that are unknown are left out. The feed spec rejects placeholders.

Products the feed would reject are skipped and counted by reason: no image, no price, no title. So are products with Enable Agentic Search switched off.

Configuration

Stores > Configuration > Agentic Commerce Protocol > Product Feed Settings, per store view:

Setting Purpose Default
Enable Product Feed Turns the feed on for the store view No
Include Categories Limit the feed to these categories all
Maximum Products Catalog products to export; every variant is a row of its own 1000
Seller Name seller_name, required on every row store name
Store Country / Target Countries store_country, target_countries store country
Brand Attribute / Default Brand brand, required on every row manufacturer / seller name
GTIN Attribute / MPN Attribute gtin (validated, invalid values are left out), mpn gtin / mpn
Include Review Data review_count, star_rating Yes
Accepts Returns, Return Deadline, Return Policy URL accepts_returns, return_deadline_in_days, return_policy not specified
Privacy Policy URL, Terms of Service URL seller_privacy_policy, seller_tos empty

is_eligible_checkout is only true when the checkout API is enabled, both policy URLs are set, the product is salable and Enable Agentic Checkout is on for the product. The checkout API refuses products that have it switched off.

Each product has two switches in the Agentic Commerce section of the product form: Enable Agentic Search and Enable Agentic Checkout.

Getting the feed

# Writes var/acp/feed-<store code>.jsonl
bin/magento acp:feed:generate
bin/magento acp:feed:generate --store=german --output=feed-de.jsonl
  • A cron job regenerates the file every six hours for every store view that has the feed enabled.
  • GET /acp/feed returns the feed of the current store view. The response is cached for an hour in the ACP Product Feed cache type.

Checkout API

An agent creates a checkout session, updates it until it is ready for payment, and completes it with a payment credential. The module turns the session into a guest quote and, on completion, into a normal Magento order.

Operation Request
Create a session POST /acp/checkout_sessions
Update items, buyer, address, shipping option, discount code POST /acp/checkout_sessions/{id}
Retrieve GET /acp/checkout_sessions/{id}
Complete (places the order) POST /acp/checkout_sessions/{id}/complete
Cancel POST /acp/checkout_sessions/{id}/cancel
Discovery document (public) GET /.well-known/acp.json
curl -X POST https://example.com/acp/checkout_sessions \
  -H 'Authorization: Bearer <api key>' \
  -H 'API-Version: 2026-04-17' \
  -H 'Idempotency-Key: 5f0c1a9e-7c56-4c5e-9d0b-0d6f6f0b7c11' \
  -H 'Content-Type: application/json' \
  -d '{"currency":"eur","line_items":[{"id":"MUG-350","quantity":2}],"capabilities":{}}'

How it maps to Magento:

  • Items are addressed by SKU, the item_id of the product feed. quantity defaults to 1.
  • Prices, tax, discounts and shipping costs come from Magento's own totals, so catalog and cart price rules and tax rules apply. All amounts are integers in minor units. Tax is its own line; the other amounts are net.
  • Fulfillment options are the shipping rates for the address. The cheapest one is preselected. A quote with only virtual products gets a digital option.
  • Discount codes (discounts.codes or coupons): Magento applies one coupon code per cart. Further codes are reported as rejected.
  • Status is ready_for_payment as soon as nothing is missing. Until then the messages say what is: an address, a phone number if the store requires one, an item that is out of stock, and so on.
  • Orders are guest orders with the payment method "Agentic Checkout". That method is only available while such an order is placed, so it never appears in the storefront or admin checkout.
  • Idempotency follows the protocol: every POST needs an Idempotency-Key. A repeated request gets the stored response, a reused key with another body gets 422, a request still in flight gets 409.
  • Sessions that are not completed expire after 24 hours (configurable). After 30 days (configurable) abandoned sessions are deleted, and the buyer's data is removed from completed ones. The order keeps it, as usual.

Setup

Stores > Configuration > Agentic Commerce Protocol

  1. Checkout API: enable it and set an API Key, the bearer token the agent platform authenticates with.
  2. Payment: Stripe Shared Payment Tokens: enable it and enter your Stripe secret key and account ID (see below). Without a payment handler no session can be completed.
  3. Order Webhooks (optional): the endpoint URL and signing secret the agent platform gave you.
  4. Request Signatures (optional): reject requests without a valid Signature header.
  5. Set the policy URLs in Product Feed Settings; they are returned as links of each session.

The API runs in the store view the request is routed to, like any storefront URL. The settings above can differ per website or store view. Only the display currency of that store view is accepted.

Payment

The agent pays with a credential issued for one purchase. Out of the box the module supports card payments through Stripe (dev.acp.tokenized.card): the agent delivers a Shared Payment Token, and the module charges it with a PaymentIntent on your Stripe account while the order is placed.

  • The payment is captured immediately. The order gets an invoice and the PaymentIntent ID as transaction ID.
  • The token is never stored.
  • A declined payment leaves the session open; the response carries a payment_declined message.
  • 3-D Secure is not supported. A payment that needs it is canceled and reported as declined.
  • Refunds are not sent to Stripe. Refund in the Stripe dashboard and create an offline credit memo.
  • If saving the order fails after the charge, the charge is refunded automatically.

Other payment providers can be added without touching the module: implement RunAsRoot\AgenticCommerceProtocol\Model\Payment\HandlerInterface and register it in di.xml.

<type name="RunAsRoot\AgenticCommerceProtocol\Model\Payment\HandlerPool">
    <arguments>
        <argument name="handlers" xsi:type="array">
            <item name="my_psp" xsi:type="object">Vendor\Module\Model\MyPspHandler</item>
        </argument>
    </arguments>
</type>

Order webhooks

When webhooks are enabled, the module posts order_create after an order was placed through the API and order_update when that order, a shipment, a tracking number or a credit memo is saved. Each event contains the full order: status, line items with shipped and refunded quantities, shipments with tracking numbers, refunds and totals. Events are queued and sent by cron every minute, with retries.

Requests are signed as the protocol defines: Merchant-Signature: t=<unix seconds>,v1=<hex HMAC-SHA256> over <timestamp>.<raw body>.

Request signatures

The protocol leaves the signature algorithm to the seller. With Require Signed Requests on, the module expects a Timestamp header (RFC 3339) and a Signature header with the HMAC-SHA256 of <Timestamp header>.<raw body>, base64url or hex encoded, and rejects timestamps outside the tolerance.

MCP endpoint

The same five operations are available as Model Context Protocol tools at /acp/mcp, following the protocol's MCP transport binding. Turn it off with Enable MCP Endpoint.

Tool REST operation
create_checkout_session POST /acp/checkout_sessions
get_checkout_session GET /acp/checkout_sessions/{id}
update_checkout_session POST /acp/checkout_sessions/{id}
complete_checkout_session POST /acp/checkout_sessions/{id}/complete
cancel_checkout_session POST /acp/checkout_sessions/{id}/cancel

Every tool takes meta (the REST headers: api_version is required, idempotency_key is optional), id (the session, not on create) and payload (the REST request body):

curl -X POST https://example.com/acp/mcp \
  -H 'Authorization: Bearer <api key>' \
  -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"create_checkout_session","arguments":{
        "meta":{"api_version":"2026-04-17","idempotency_key":"5f0c1a9e-7c56-4c5e-9d0b-0d6f6f0b7c11"},
        "payload":{"currency":"eur","line_items":[{"id":"MUG-350","quantity":2}],"capabilities":{}}}}}'
  • Transport: Streamable HTTP, stateless. Every POST gets one JSON response; there are no MCP sessions and no event streams (GET answers 405). MCP protocol versions 2025-03-26 to 2025-11-25.
  • Authentication: the API key as bearer token on the HTTP request, never in the tool arguments. The endpoint does not offer OAuth, so the MCP client must be able to send a static Authorization header.
  • Results: a normal MCP tool result. The checkout session is in structuredContent and, as JSON text, in content. The binding's examples show the session directly as the JSON-RPC result, which MCP clients reject.
  • Errors: as the binding defines, a JSON-RPC error with code -32000 and the ACP error object in data. A malformed tool call (unknown tool, missing meta, id or payload) gets -32602.
  • Idempotency: with meta.idempotency_key a call behaves like the REST request with that header, and both transports share the stored responses. Without it the call is simply executed.
  • Signatures: with Require Signed Requests on, meta.timestamp and meta.signature are required. The signature is the HMAC-SHA256 of <meta.timestamp>.<payload>, with the payload as compact JSON with object keys sorted ({} when there is none). The binding does not define this; it is this module's reading.
  • Tool schemas are the protocol's request schemas (etc/mcp/tools.json, built by dev/build-mcp-tools.py), plus the optional quantity on items.

Not supported

  • Customer accounts: all orders are guest orders, so guest checkout must be allowed.
  • 3-D Secure and other interventions, delegated authentication.
  • Several shipments per order (fulfillment_groups), pickup and local delivery options.
  • Other currencies than the store view's display currency.
  • The cart API and the feed API of the protocol. On the MCP endpoint: OAuth, MCP sessions and event streams.
  • Products that need options chosen at purchase (configurable parents, bundles, custom options). Configurable variants are bought by their own SKU, as listed in the feed.

Development

composer config repositories.mage-os composer https://repo.mage-os.org/
composer install
vendor/bin/phpunit -c Test/Unit/phpunit.xml.dist

Inside a Magento installation, run the tests with Magento's own configuration:

vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/run-as-root/module-agentic-commerce-protocol/Test/Unit

Contributing

Issues and pull requests are welcome. Please add tests for new behaviour.

License

MIT, see LICENSE.