跳到正文
DEV Community· Serhiy K·· 44 分鐘前AI 評分47

透過 MCP 將 Magento 商店連接至 AI Agent:11 項唯讀工具及寫入防護措施

Connecting a Magento Store to AI Agents with MCP: Eleven Read-Only Tools and the Guardrails Around Writes

AI 導讀

Horizon 為 Magento 2 提供 MCP 伺服器,讓 AI Agent 透過 11 項唯讀工具查詢商品、庫存、配送、訂單及客戶資料。寫入工具仍在小規模客戶測試,須使用具獨立權限範圍的寫入金鑰,並先預覽、確認;所有寫入均會記錄。

正文

In June we wrote about building an MCP server for a Magento catalog: the architecture, why it talks to a flat index instead of the Magento API on every call, and why it is read-only. That prototype had eight tools. It has since shipped as Horizon, with eleven tools and an on-site shopping assistant built on the same tools.

This post is the practical one. What an AI agent can actually ask a Magento store through Horizon, what it cannot do, and the two lines it takes to connect one.

What does it mean to connect Magento to an AI agent?

An AI agent such as Claude can only answer questions about your store from what it can read. Without a connection it reads your public pages, the same way a scraper does: it guesses prices from HTML, has no idea whether something is in stock, and cannot tell a customer when their order will arrive.

The Model Context Protocol (MCP) replaces the guessing with typed tool calls. The agent calls search_products or get_inventory, and gets structured data back from the store itself. Horizon is the MCP server for Magento 2: a gateway hosted by Byte8 that speaks MCP to the agent, and a Magento extension that answers the gateway from a dedicated product index.

The result is that an agent answers from your catalog as it is right now, not as it looked the last time a crawler passed.

The eleven tools

These eleven tools come with every plan, and all of them are read-only. Grouped by the question each one answers:

What do you sell?

  • search_products: search by name, SKU or description, with filters and pagination. Results can be sorted by best-selling (units sold over the last year), top-rated or price, so "your most popular waterproof jacket" has a real answer.
  • get_product: the full product record: description, price, images, categories, attributes, average rating and the product URL.
  • get_categories: the category tree, so an agent can browse the way a shopper would.
  • get_reviews: approved reviews for a product, with the average and the count.

Can I get it, and when?

  • get_inventory: stock by SKU and by source, using Magento's multi-source inventory.
  • estimate_shipping: delivery availability and live carrier rates for a product to a country and postcode. The quote is thrown away afterwards; nothing is saved on the store.
  • get_store_info: contact details, the countries you ship to, active carriers and payment methods, how tax is displayed, and the text of your policy pages, so "what is your returns policy?" is answered from your policy, not a guess.

Where is my order? (for the merchant's own agents and support workflows)

  • get_orders and get_order: order lists and full order detail, including payment status, shipments, tracking and an estimated arrival date.
  • get_customers: customer search by name or email.

Which store?

  • list_stores: for accounts that connect more than one store or store view.

Write tools: built, in pre-release testing

Reading the catalog is the part that's generally available. The next step is letting the merchant's own agent do the work as well as answer questions about it, and those tools are built. They're in testing with a small group of customers before general release, grouped by what they can touch:

  • Content: create or update a CMS page.
  • Catalog: create or update products, bulk-update existing SKUs, create and move categories, add attribute options and create attributes.
  • Orders: invoice, ship or fulfil an order in one step, add an order comment, hold and release, and cancel an order only if nothing has been paid.
  • Customers: create and update customer accounts and addresses, and change a newsletter subscription when there is a recorded consent source.

The guardrails come first, because an agent that can change a store needs more care than one that can only read it:

  • A separate key with scopes. Writes need their own write key, and each key only gets the scopes you grant: content, catalog, orders or customers. The everyday read key can never write.
  • Preview, then confirm. A write tool called without confirmation returns the exact change it would make and saves nothing. The agent has to call again with the same arguments and confirm: true, and a confirmation can't apply anything that wasn't previewed. Customer writes always preview, whatever the store setting.
  • New things start switched off. New products, categories and CMS pages are created disabled, so nothing reaches the storefront until someone turns it on.
  • Every write is logged. The dashboard keeps an audit trail of each write: the tool, the record it touched, whether it was a preview, and the diff.

If you'd like to try the write tools on your store before general release, get in touch.

What Horizon deliberately does not do

The hard part of putting an AI agent in front of a store is not making it capable. It is making sure it can't do anything you haven't agreed to. So the boundaries are part of the product:

  • The standard connection never writes to your store. On the generally available plans the extension serves a read-only endpoint and a product index maintained by a native Magento indexer. With the read key, no agent can change a price, edit a product or touch an order. Writes need the separate pre-release key described above, and nothing can issue a refund.
  • The shopping assistant cannot add to cart or apply a coupon. It answers questions and links to the product page; the customer buys through your normal checkout.
  • Order and customer data stays behind the merchant's key. Each store gets its own API key, shown once in the dashboard and stored encrypted. The storefront widget uses a separate publishable key and cannot list orders or search customers. A shopper can look up one order, and only by giving both the order number and the email used at checkout; the answer leaves out addresses, the payment method and the customer's name.
  • It does not generate structured data or AEO manifests for your pages. That is on the roadmap, not in the product today.

The AI Shopping Assistant

The second half of Horizon is a chat widget for your storefront, hosted by Byte8 and grounded in the same tools. A shopper asks "do you have this in a size 10, and will it arrive by Friday in London?" and the assistant checks stock and runs a live shipping estimate before it answers, instead of composing something plausible. "Where is my order?" works the same way: given the order number and checkout email, it reports whether the order has shipped, the tracking number and an estimated arrival date, from the order itself.

Two details matter to merchants. First, you don't need an AI provider account; Byte8 runs the model and the price includes it. Second, the reply allowance is a hard cap: 500 replies a month on Starter, 3,000 on Pro and 15,000 on Agency. Past it, the widget pauses until the next billing month. You never get a surprise per-reply bill.

The widget works on any Magento-rendered storefront: Luma, Hyvä or a custom theme. The MCP gateway itself doesn't care about your theme at all, because agents talk to the gateway, not the storefront.

How to connect a store

Horizon supports Magento Open Source and Adobe Commerce 2.4.6 and later, and works on Mage-OS, on PHP 8.2 to 8.5. The extension only depends on standard Magento modules, so a Mage-OS store installs it the same way.

1. Install the extension and build the index.

composer require byte8/module-horizon
bin/magento setup:upgrade
bin/magento indexer:reindex byte8_horizon_product

The Horizon documentation covers the Composer repository setup.

2. Register the store in the Horizon dashboard and paste the API key it gives you into the Horizon settings in Magento admin.

3. Point an agent at it. The gateway is a standard MCP server over HTTP with a bearer token, so any MCP client that supports remote servers can connect. In Claude Code it is one command:

claude mcp add --transport http my-store https://horizon.byte8.io/mcp \
  --header "Authorization: Bearer $HORIZON_KEY"

Then ask it something only your store knows: "what are our three best-selling products this year, and are they all in stock?" The agent calls search_products sorted by best-selling, then get_inventory, and answers from live data. Every call shows up in the dashboard's usage log, so you can see exactly what was asked and what the store returned.

Why now

Shoppers are already asking AI assistants which product to buy, and buyers in B2B are starting to hand procurement research to agents. Those agents will recommend the stores whose data they can read accurately. A catalog that can only be scraped will be described approximately, and approximately is how you lose a sale to a competitor whose stock levels the agent could actually check.

Horizon isn't the only way to put AI in front of a Magento store, and we don't pretend otherwise. What it offers is a connection that is live, typed, read-only by default and metered so you can see what agents are doing with your catalog. If that's the connection you want, the Horizon page has plans and pricing (there's a 14-day trial on Pro).

來源:DEV Community · dev.to