MCP Authentication for Ecommerce Integrations
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
resourceparameter 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.
| Party | Requirement | Level |
|---|---|---|
| Authorization server | Implement OAuth 2.1 for confidential and public clients | MUST |
| MCP server | Implement OAuth 2.0 Protected Resource Metadata (RFC 9728) | MUST |
| MCP client | Use Protected Resource Metadata to discover the authorization server | MUST |
| Authorization server | Offer RFC 8414 metadata or OpenID Connect Discovery | MUST (at least one) |
| Client and authorization server | Support Client ID Metadata Documents | SHOULD |
| Client and authorization server | Dynamic Client Registration (RFC 7591) | MAY; deprecated, kept for compatibility |
| MCP client | Send resource (canonical server URI) in authorization and token requests | MUST |
| MCP client | Send Authorization: Bearer on every HTTP request; never put tokens in the query string | MUST |
| MCP server | Validate tokens were issued for it as the audience; reject others with 401 | MUST |
| MCP server | Not accept or transit any other tokens | MUST 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
Unauthenticated request gets a challenge
The server returns 401 with
WWW-Authenticate: Bearer resource_metadata="..."and, ideally, ascopelisting what this operation needs. - 2
Client reads Protected Resource Metadata
It fetches the metadata document and picks an authorization server from
authorization_servers. - 3
Client discovers authorization server metadata
Via RFC 8414 or OpenID Connect Discovery, and records the expected
issuer. - 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
User authenticates and consents
Authorization code flow with PKCE and the
resourceparameter set to your server's canonical URI. - 6
Client validates the response
It checks the
issparameter against the recorded issuer (RFC 9207) before redeeming the code. - 7
Client calls tools with the token
Every request carries the Bearer token. Your server validates signature, expiry, audience, and scope per request.
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.
| Tool group | Example tools | Identity needed | Example scope | Confirmation |
|---|---|---|---|---|
| Public catalog | search_products, get_product | None or client only | catalog:read or none | No |
| Cart | create_cart, update_cart | Anonymous cart handle or user | cart:write | No |
| Own orders | list_my_orders, get_order_status | Customer | orders:read:self | No |
| Own account | get_addresses, update_address | Customer | account:read:self, account:write:self | Yes for writes |
| Returns | start_return | Customer | returns:write:self | Yes |
| Checkout and payment | complete_checkout | Customer | Platform-specific | Always; payment collected in a trusted UI |
| Staff operations | update_inventory, refund_order | Staff user | ops:inventory:write, ops:refunds | Yes, 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.
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 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.
| Control | What the guidance requires |
|---|---|
| Per-client consent | Keep a per-user registry of approved client_id values and check it before starting third-party authorization |
| Consent page | Name 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 URIs | Exact string match with the registered value; reject changes without re-registration |
OAuth state | Cryptographically random, stored only after consent, single-use, short expiry (for example 10 minutes) |
How should consent and secrets be handled?
Consent should be specific to the client and the action, and secrets should never enter the model's context. The tools section of the spec says there SHOULD always be a human able to deny tool invocations, and clients should confirm sensitive operations.
- Separate consent from confirmation. OAuth consent grants a client a scope. Per-action confirmation ("Submit this return for 1 item?") is a second layer for consequential tools.
- Keep secrets server-side. Platform API keys, client secrets, and signing keys live in a secret manager, never in tool descriptions, results, or error messages.
- Short-lived tokens. Shopify's Checkout MCP credentials, for example, issue tokens with a 60-minute TTL and Shopify recommends fetching fresh ones at runtime. Apply the same habit to your own servers.
- Refresh tokens are confidential. The spec requires clients to protect them in transit and storage, and servers shouldn't list
offline_accessin their scopes. - Don't mirror sensitive parameters into headers. The spec warns against marking passwords, tokens, or PII with
x-mcp-header, because intermediaries see header values. - Redact logs. Log tool name, client ID, subject, scope decision, and correlation ID. Don't log tokens, payment data, or handoff URLs.
Platform-provided servers have their own models. WooCommerce's MCP integration uses WordPress Application Passwords on a dedicated user (see our WooCommerce MCP guide), and Shopify's UCP endpoints combine an agent profile with tokens or signatures for checkout (see the Shopify Storefront MCP migration).
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.
| # | Test | Expected result |
|---|---|---|
| 1 | Call a protected tool with no Authorization header | 401 with WWW-Authenticate including resource_metadata |
| 2 | Expired or malformed token | 401 |
| 3 | Valid token issued for a different resource (wrong audience) | 401; token not used downstream |
| 4 | Token passed in the URL query string | Rejected; tokens must use the header |
| 5 | Customer A requests customer B's order by ID | Tool error with the same "not found" text as a nonexistent order; nothing logged as success |
| 6 | Customer A passes customer_id of B as an argument | Argument rejected by schema (not accepted) or ignored; result scoped to A |
| 7 | Customer A uses customer B's cart ID | Refused; handle not bound to A |
| 8 | Catalog-only token calls list_my_orders | 403 insufficient_scope naming the required scope |
| 9 | Customer token calls a staff tool | Tool absent from tools/list and 403 if called directly |
| 10 | Sequential or guessed order numbers in a loop | Rate-limited; identical not-found responses |
| 11 | Consequential tool without user confirmation | Not executed; confirmation required |
| 12 | Request with an invalid Origin header on Streamable HTTP | 403 |
| 13 | Prompt-injected product description instructs the model to fetch another customer's data | Tool still scoped to token subject; nothing returned |
| 14 | Proxy: authorization request with a changed redirect_uri | Rejected; 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.
Related
- MCP server developmentAuthorization design and denied-access testing as part of a build.
- MCP server ecommerce guideThe broad guide to MCP in commerce.
- Build an ecommerce MCP server in TypeScriptA hands-on server tutorial.
- WooCommerce MCP guideApplication Passwords and least-privilege users.
- Shopify Storefront MCP migrationAgent profiles, tokens, and signed checkout calls.
Sources
- MCP specification: Authorization (2026-07-28)
- MCP security best practices (2026-07-28)
- MCP specification: Streamable HTTP transport (2026-07-28)
- MCP specification: Tools (2026-07-28)
- RFC 9728: OAuth 2.0 Protected Resource Metadata
- RFC 8707: Resource Indicators for OAuth 2.0
- WooCommerce: MCP integration
- 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.