Skip to content
Ahmad Raza
Menu
All posts

4 min read

Authenticate the Agent, Not Just the Shopper

Why storefront MCP servers should authenticate the agent as well as the shopper: per-integration credentials, short-lived tokens, and clean revocation.

Authenticate the Agent, Not Just the Shopper
On this page

Most eCommerce stacks know how to authenticate a shopper. There is a session, a login, maybe a one-time code. When an AI agent starts calling your store on behalf of that shopper, a second identity enters the picture, and it needs its own authentication. If you only check who the shopper is, you have no way to tell which agent did what, and no clean way to cut one off.

This post covers how I approach agent authentication for storefront MCP servers: per-integration credentials, short-lived tokens, and revocation that does not break everyone else.

Two identities in every agent request

When an agent places an order or reads an order history, there are really two questions:

  1. Which shopper is this for? That decides whose data and whose payment method are in scope.
  2. Which agent is acting? That decides what tools are allowed, which limits apply, and who is accountable in the logs.

Collapsing these into one token is the common mistake. A shopper's session token handed to an agent gives that agent everything the shopper can do in the browser, with no way to distinguish the agent's actions from the shopper's own clicks.

Keep them separate. The agent authenticates as itself, and then presents a delegated grant that says which shopper it may act for and with what scope.

Per-integration credentials

Every agent integration gets its own client identity. Not one shared key for "AI traffic", but a distinct client id and secret, or better, a key pair, for each partner or internal agent.

This gives you:

  • Attribution. Every call carries an agent id you can log and report on.
  • Independent scopes. A comparison shopping agent might only need catalog tools. A support agent needs order read access. Neither needs both.
  • Independent limits. Rate limits and caps can be tuned per integration.
  • Isolated revocation. Turning off one integration leaves the rest untouched.

In practice I store integrations in a simple table: client id, display name, owner contact, allowed tools, allowed scopes, limits, status, and created date. That table becomes the control panel for every agent touching the store.

Short-lived tokens

Long-lived API keys are easy and risky. They end up in logs, config files, and prompt contexts. If one leaks, it works until someone notices.

A better pattern:

  • The integration authenticates with its long-term credential only to the token endpoint.
  • It receives an access token that lasts minutes, not days.
  • The token carries the agent id, the shopper id if delegated, and the scopes granted.
  • Refresh requires the integration credential again, so a stolen access token expires on its own.

For shopper delegation, use a standard OAuth style consent step. The shopper sees which agent is asking, what it wants to do, and approves. The resulting grant is tied to that agent and that shopper, nothing broader.

Keep scopes narrow and named after real actions: catalog:read, cart:write, orders:read, checkout:initiate. Avoid catch-all scopes like full_access. They are tempting during development and painful to remove later.

Scoped payment tokens

Payment deserves its own layer. An agent should never see raw card data. Instead, issue scoped payment tokens that are limited by merchant, amount, and time. A token that can pay up to a set amount at your store in the next fifteen minutes is far less dangerous than a reusable card reference.

Combined with per-agent identity, this means that even if an agent misbehaves, the money it can move is bounded and traceable.

Revoke one agent without breaking others

Revocation is where shared credentials hurt the most. If every agent uses the same key, revoking it takes down every integration at once, so in practice nobody revokes anything.

With per-integration credentials, revocation becomes routine:

  1. Mark the integration as disabled in your integrations table.
  2. Reject new token requests for that client id.
  3. Invalidate outstanding access tokens, either through a deny list checked at the gateway or by keeping token lifetimes short enough that they expire quickly.
  4. Revoke shopper grants tied to that agent, and notify affected shoppers if appropriate.

Other agents keep working. Shoppers using a different assistant notice nothing.

It also helps to support finer revocation: a single shopper revoking a single agent from their account settings, or you pulling one scope from an integration without disabling it entirely.

Where to enforce it

I enforce agent authentication at the MCP server boundary, before any tool runs:

  • Verify the token signature and expiry.
  • Load the integration record and check its status.
  • Confirm the requested tool is in the integration's allowed list.
  • Confirm the scope covers the action and the shopper grant is valid.
  • Attach the agent id and shopper id to the request context so logs and downstream services see both.

Tools themselves should not re-implement auth checks in different ways. Keep one middleware, test it well, and let tools trust the context it provides.

Common mistakes to avoid

  • Passing the shopper's browser session to the agent. It hides the agent and grants too much.
  • One key for all agents. No attribution, no isolated revocation.
  • Tokens that live for weeks. Leaks stay useful far too long.
  • Scopes defined by endpoint instead of action. They drift as the API grows.
  • No owner contact per integration. When something looks wrong, you need someone to call.

Wrapping up

Authenticating the shopper tells you whose account is involved. Authenticating the agent tells you who is acting and lets you control it. Per-integration credentials, short-lived scoped tokens, and clean revocation are not exotic. They are the same ideas good API platforms already use, applied to a new kind of client.

If you are adding MCP tools or AI agents to a Next.js eCommerce store and want the auth layer designed properly from the start, I can help. Reach out through my contact section or at ahmadraza365pro@gmail.com.

  • 5 min read

    A 30-Day Agentic Commerce Rollout for a Next.js Store

    A practical, week by week plan to make a Next.js store ready for AI shopping agents: clean the data, ship a read only catalog MCP server, add carts, hand off to confirmed checkout, then log and cap everything.

  • 5 min read

    Fraud and Abuse When Agents Shop Your Checkout

    AI shopping agents look a lot like bots, and bots look a lot like agents. Here is how to tell them apart, where to put bot challenges, and why hosted checkout like Shop Pay is your best trust boundary.

  • 4 min read

    Hydrogen SDK vs Calling Storefront API Yourself in 2026

    Shopify's Hydrogen SDK now reaches beyond Remix and React Router into other frameworks. Here is what it gives you for agent ready storefronts, what a thin Next.js client gives you, and when each one pays off.