Development

MCP Authentication for Ecommerce Integrations

By Michael E.Updated Sources checked 15 min

Short answer

Under the MCP specification revision 2026-07-28, a remote ecommerce MCP server acts as an OAuth 2.1 resource server: it must publish OAuth Protected Resource Metadata, validate that each access token was issued for it, and never pass client tokens to downstream APIs. Customer data stays safe when every order or account tool derives the customer from the verified token, not from tool arguments.

Key takeaways

  • MCP authorization is optional, but HTTP servers that support it should follow the spec; STDIO servers should take credentials from the environment instead.
  • Servers must implement Protected Resource Metadata (RFC 9728) and validate token audience; clients must send the resource parameter (RFC 8707).
  • Token passthrough is explicitly forbidden: an MCP server must not accept tokens not issued for it or forward client tokens downstream.
  • Bind every customer-data tool to the token subject; possession of an order ID, cart ID, or other handle is not authorization.
  • Start with minimal scopes and step up with 403 insufficient_scope challenges when a tool needs more.
  • Test denied paths explicitly: cross-customer order reads, wrong-audience tokens, expired tokens, and missing scopes.

How do I authorize ecommerce MCP tools under the current MCP spec?

Use OAuth 2.1 with your MCP server as the resource server. The MCP specification revision 2026-07-28 makes authorization optional, but says HTTP-based implementations that support it SHOULD conform to its authorization section, which builds on OAuth 2.1 (draft-ietf-oauth-v2-1-13) and a selected set of related RFCs.

MCP (Model Context Protocol)
An open protocol for AI clients to discover and call tools on servers using JSON-RPC 2.0.
Resource server
The MCP server: it accepts access tokens and enforces what they allow.
Authorization server
The system that authenticates the user, records consent, and issues tokens. It can be your identity provider or your commerce platform's.
Protected Resource Metadata (RFC 9728)
A JSON document at a well-known URL that tells clients which authorization servers protect this MCP server and which scopes exist.
Resource indicator (RFC 8707)
The resource parameter a client sends so the token is issued for one specific MCP server.
Token passthrough
The forbidden pattern of accepting a token not issued for your server, or forwarding a client's token to a downstream API.
Core requirements in MCP 2026-07-28 authorization (paraphrased; MUST/SHOULD as written in the spec)
PartyRequirementLevel
Authorization serverImplement OAuth 2.1 for confidential and public clientsMUST
MCP serverImplement OAuth 2.0 Protected Resource Metadata (RFC 9728)MUST
MCP clientUse Protected Resource Metadata to discover the authorization serverMUST
Authorization serverOffer RFC 8414 metadata or OpenID Connect DiscoveryMUST (at least one)
Client and authorization serverSupport Client ID Metadata DocumentsSHOULD
Client and authorization serverDynamic Client Registration (RFC 7591)MAY; deprecated, kept for compatibility
MCP clientSend resource (canonical server URI) in authorization and token requestsMUST
MCP clientSend Authorization: Bearer on every HTTP request; never put tokens in the query stringMUST
MCP serverValidate tokens were issued for it as the audience; reject others with 401MUST
MCP serverNot accept or transit any other tokensMUST NOT

Error codes are fixed too: 401 when authorization is required or a token is invalid, 403 for invalid scopes or insufficient permissions, and 400 for a malformed authorization request.

Does a local STDIO MCP server need OAuth?

No. The spec says STDIO implementations SHOULD NOT follow the HTTP authorization flow and should retrieve credentials from the environment. A merchant running a local catalog tool for staff can pass an API key through environment variables and rely on the operating system's process boundary.

That doesn't make STDIO risk-free. The security best practices page notes local servers run with the client's privileges and recommends STDIO for local servers precisely because it limits access to the launching client. If a local server listens on HTTP instead, the spec's Streamable HTTP transport says it MUST validate the Origin header and SHOULD bind to 127.0.0.1, because otherwise DNS rebinding lets websites reach it. Transport trade-offs are covered in MCP vs REST APIs for ecommerce.

How does the MCP OAuth flow work step by step?

The client discovers your authorization server from your server's 401 response, registers or identifies itself, runs an authorization code flow with PKCE and a resource indicator, then calls tools with the resulting token.

  1. 1

    Unauthenticated request gets a challenge

    The server returns 401 with WWW-Authenticate: Bearer resource_metadata="..." and, ideally, a scope listing what this operation needs.

  2. 2

    Client reads Protected Resource Metadata

    It fetches the metadata document and picks an authorization server from authorization_servers.

  3. 3

    Client discovers authorization server metadata

    Via RFC 8414 or OpenID Connect Discovery, and records the expected issuer.

  4. 4

    Client identifies itself

    With a Client ID Metadata Document (an HTTPS URL as client_id), a pre-registered client ID, or deprecated Dynamic Client Registration.

  5. 5

    User authenticates and consents

    Authorization code flow with PKCE and the resource parameter set to your server's canonical URI.

  6. 6

    Client validates the response

    It checks the iss parameter against the recorded issuer (RFC 9207) before redeeming the code.

  7. 7

    Client calls tools with the token

    Every request carries the Bearer token. Your server validates signature, expiry, audience, and scope per request.

Illustrative challenge and metadata exchange for a hypothetical store MCP server (shape follows the 2026-07-28 spec examples; hostnames and scopes are invented).
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer resource_metadata="https://mcp.shop.example/.well-known/oauth-protected-resource",
                         scope="catalog:read"

GET /.well-known/oauth-protected-resource HTTP/1.1
Host: mcp.shop.example

HTTP/1.1 200 OK
Content-Type: application/json

{
  "resource": "https://mcp.shop.example/mcp",
  "authorization_servers": ["https://auth.shop.example"],
  "scopes_supported": ["catalog:read", "cart:write"],
  "bearer_methods_supported": ["header"]
}

Note that scopes_supported lists a minimal set. The spec says it is intended to represent the minimal scopes for basic functionality, with more requested through step-up. Publishing every possible scope there is listed in the security guidance as a common mistake.

How should ecommerce MCP tools be scoped?

Split tools by risk and by whose data they touch, then give each group its own scope. Public catalog reads may need no user at all; anything about a specific customer needs a user-bound token; anything that moves money or changes an order needs a narrow scope plus human confirmation.

Example scope design for a store MCP server (our recommendation; scope names are illustrative)
Tool groupExample toolsIdentity neededExample scopeConfirmation
Public catalogsearch_products, get_productNone or client onlycatalog:read or noneNo
Cartcreate_cart, update_cartAnonymous cart handle or usercart:writeNo
Own orderslist_my_orders, get_order_statusCustomerorders:read:selfNo
Own accountget_addresses, update_addressCustomeraccount:read:self, account:write:selfYes for writes
Returnsstart_returnCustomerreturns:write:selfYes
Checkout and paymentcomplete_checkoutCustomerPlatform-specificAlways; payment collected in a trusted UI
Staff operationsupdate_inventory, refund_orderStaff userops:inventory:write, ops:refundsYes, plus audit log

The spec allows tools/list to vary by the authorization presented, "returning only the tools the caller's granted scopes permit." Hiding staff tools from customer tokens reduces what a model can even attempt. It's a convenience, not a control: still enforce scope inside every tool.

Illustrative step-up challenge when a catalog-only token calls an order tool (format from the spec's insufficient_scope example).
HTTP/1.1 403 Forbidden
WWW-Authenticate: Bearer error="insufficient_scope",
                         scope="orders:read:self",
                         resource_metadata="https://mcp.shop.example/.well-known/oauth-protected-resource",
                         error_description="Reading your orders requires the orders:read:self scope"

Servers SHOULD include all scopes needed for the current operation in one challenge, rather than one at a time, and clients compute the union of old and new scopes when they re-authorize.

How do we prevent one customer seeing another customer's orders?

Derive the customer from the verified token on every call and check ownership of every record before returning it. Never accept customer_id or email as a tool argument for customer-scoped tools, and never treat knowing an order number or cart ID as proof of ownership.

The 2026-07-28 security guidance names this risk state handle hijacking. Because MCP in this revision has no protocol-level sessions, servers mint explicit handles such as cart IDs, and the guidance says servers MUST NOT treat possession of a handle as authentication, SHOULD use non-guessable handles, and SHOULD bind them server-side to the user, for example keying state as <user_id>:<handle> with the user ID taken from the verified token.

  • Ownership check after lookup. Fetch by ID, compare the owner to the token's customer, and return the same "not found" message for both missing and foreign records.
  • No identity in arguments. Prompt injection or a confused model can put any value in an argument. The token is the only identity source.
  • Minimal outputs. An order-status tool returns status and carrier, not payment details or full addresses.
  • Guest orders. If you support lookup without login, require a second factor the model can't guess (for example, a one-time code sent to the order email) and rate-limit attempts.
  • Downstream queries filtered by customer. Query WHERE customer_id = :fromToken, so a coding mistake returns nothing instead of someone else's data.
Illustrative user binding for an order tool. Helper objects (orders, customers, InsufficientScope) are placeholders.
// Illustrative TypeScript. Not production code and not run in this session.
// The rule it demonstrates: the customer comes from the verified token, never from tool arguments.

interface VerifiedToken {
  sub: string;            // customer identity at the authorization server
  aud: string | string[]; // must contain this server's canonical URI
  scope: string;
  client_id: string;
}

const CANONICAL_URI = "https://mcp.shop.example/mcp";

function requireScope(token: VerifiedToken, needed: string) {
  const granted = token.scope.split(" ");
  if (!granted.includes(needed)) {
    throw new InsufficientScope(needed); // becomes 403 + WWW-Authenticate insufficient_scope
  }
}

export async function getOrderStatus(token: VerifiedToken, args: { order_id: string }) {
  requireScope(token, "orders:read:self");

  // Look up the order, then check ownership against the token subject.
  const order = await orders.findById(args.order_id);
  const customerId = await customers.idForSubject(token.sub);

  if (!order || order.customerId !== customerId) {
    // Same response for "doesn't exist" and "not yours" so IDs can't be probed.
    return {
      isError: true,
      content: [{ type: "text", text: "No order with that number was found on your account." }],
    };
  }

  // Return only what the tool promises; no payment details, no internal notes.
  return {
    structuredContent: { order_id: order.publicId, status: order.status, carrier: order.carrier },
    content: [{ type: "text", text: "Order " + order.publicId + " is " + order.status + "." }],
  };
}

// Calling the commerce backend: use the server's own credential, scoped to this customer.
// Never forward the MCP access token to the backend (token passthrough).

What are token passthrough and confused deputy attacks in MCP?

Token passthrough is an MCP server accepting a token not issued for it, or forwarding a client's token to a downstream API. A confused deputy attack abuses an MCP proxy's static OAuth client ID and an existing consent cookie to get an authorization code sent to an attacker. Both turn your server into a tool for someone else.

Token passthrough

Say a client presents a token for your Shopify, BigCommerce, or ERP API, and your MCP server forwards it unchanged. Your server can't tell clients apart, audit trails point at the wrong party, and any rate limits or validation tied to the token's audience are bypassed. The spec's mitigation is absolute: MCP servers MUST NOT accept any tokens not explicitly issued for the MCP server. Your server calls downstream systems with its own credentials, scoped by what the validated user may do.

Confused deputy

This applies when your MCP server proxies a third-party API (for example, a commerce platform) using one static client ID, lets MCP clients register dynamically, the third-party sets a consent cookie, and your server doesn't ask for its own per-client consent. An attacker registers a client with their redirect URI, sends the user a link, the third party skips consent because of the cookie, and the code lands with the attacker.

Required protections for MCP proxy servers (from the 2026-07-28 security best practices)
ControlWhat the guidance requires
Per-client consentKeep a per-user registry of approved client_id values and check it before starting third-party authorization
Consent pageName the client, show third-party scopes and the registered redirect_uri, use CSRF protection, block framing
Consent cookies__Host- prefix; Secure, HttpOnly, SameSite=Lax; signed; bound to the client_id
Redirect URIsExact string match with the registered value; reject changes without re-registration
OAuth stateCryptographically random, stored only after consent, single-use, short expiry (for example 10 minutes)

Which denied-access test cases should an ecommerce MCP server pass?

Write these as automated tests before launch, and rerun them whenever tools or scopes change. Each row is a request that must fail, with the failure the spec or our design expects.

Denied-access test matrix (expected results per the 2026-07-28 spec and the design above; run them against your own server)
#TestExpected result
1Call a protected tool with no Authorization header401 with WWW-Authenticate including resource_metadata
2Expired or malformed token401
3Valid token issued for a different resource (wrong audience)401; token not used downstream
4Token passed in the URL query stringRejected; tokens must use the header
5Customer A requests customer B's order by IDTool error with the same "not found" text as a nonexistent order; nothing logged as success
6Customer A passes customer_id of B as an argumentArgument rejected by schema (not accepted) or ignored; result scoped to A
7Customer A uses customer B's cart IDRefused; handle not bound to A
8Catalog-only token calls list_my_orders403 insufficient_scope naming the required scope
9Customer token calls a staff toolTool absent from tools/list and 403 if called directly
10Sequential or guessed order numbers in a loopRate-limited; identical not-found responses
11Consequential tool without user confirmationNot executed; confirmation required
12Request with an invalid Origin header on Streamable HTTP403
13Prompt-injected product description instructs the model to fetch another customer's dataTool still scoped to token subject; nothing returned
14Proxy: authorization request with a changed redirect_uriRejected; exact match required

Frequently asked questions

Does MCP require OAuth?

Authorization is optional in the MCP specification. When an HTTP-based server supports it, the spec says it should follow the OAuth 2.1-based authorization section. STDIO servers should take credentials from the environment instead.

Which MCP spec version does this guide follow?

Revision 2026-07-28, checked on 2026-11-29. That revision deprecates Dynamic Client Registration in favor of Client ID Metadata Documents and removes protocol-level sessions, which affects how cart and order handles must be protected.

Can my MCP server just forward the user's Shopify or ERP token?

No. The spec forbids token passthrough. Your server must accept only tokens issued for it and call downstream systems with its own credentials, limited to what the validated user may do.

Is a public product search tool required to have authentication?

Not by the protocol. Public catalog reads can run without a user, though you may still want client identification and rate limits. Customer-specific and write tools need user-bound tokens.

Why return 'not found' instead of 'forbidden' for another customer's order?

Distinct responses let an attacker confirm which order numbers exist. Returning the same message for missing and foreign orders, combined with rate limits, makes probing unproductive.

What is the difference between 401 and 403 in MCP?

The spec uses 401 when authorization is required or the token is invalid or expired, and 403 for insufficient scopes or permissions. A 403 with error="insufficient_scope" tells the client which scopes to request in a step-up flow.

Do tool annotations protect destructive tools?

No. The spec says clients must treat tool annotations as untrusted unless they come from trusted servers. Enforce permissions and confirmations on the server.

Who handles login if we already have customer accounts?

Your existing identity provider or commerce platform can act as the authorization server if it supports the required discovery and OAuth 2.1 features. The MCP server stays a resource server that validates its tokens.

Need customer-safe MCP tools?

Tell us which customer data your tools must touch, your identity provider, and your commerce backend. We'll design scopes and bindings and run the denied-access matrix before launch.

Sources

  1. MCP specification: Authorization (2026-07-28)
  2. MCP security best practices (2026-07-28)
  3. MCP specification: Streamable HTTP transport (2026-07-28)
  4. MCP specification: Tools (2026-07-28)
  5. RFC 9728: OAuth 2.0 Protected Resource Metadata
  6. RFC 8707: Resource Indicators for OAuth 2.0
  7. WooCommerce: MCP integration
  8. Shopify: Authenticate your agent

Platform capabilities, eligibility, and specifications change. Sources were checked on 2026-11-29; confirm the current primary documentation before scoping an implementation. See our editorial policy and methodology.