Set up an AI agent for shopper authentication

Use this guide to add shopper sign-in to an AI agent that calls the Shopper MCP Server for an Adobe Commerce Optimizer merchant. You’ll learn how to onboard the agent and include its credentials and a shopper session ID in requests. The guide also covers how to handle sign-in requests, receive notifications, and retry calls

For how the flow works and what the merchant sets up, see How it works.

Before you begin before-you-begin

  • You have the OAuth Server-to-Server credentials that Adobe provides to get an IMS service token for the MCP Registry API. See Get an IMS service token.
  • You have a public HTTPS endpoint that can receive webhook notifications.
  • You have a place to store a secret (the agent API key), such as a secrets manager.
  • From the merchant, you have the tenant ID (X-Environment-Id) and the view ID (X-View-Id).

See Endpoints by environment for the Shopper MCP Server and MCP Registry URLs.

Step 1: Register your agent register-agent

Call onboardAgent on the MCP Registry with your webhook URL:

curl -X POST 'https://na1-sandbox.api.commerce.adobe.com/mcp-registry/api/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <ims-service-token>' \
  -d '{"query": "mutation { onboardAgent(input: { webhookUrl: \"https://agent.example.com/smcp/webhook\" }) { agentId apiKey } }"}'
  • webhookUrl is an absolute https:// URL on a public host, at most 2048 characters. See Step 4.
  • The response contains your agentId and apiKey (64 lowercase hexadecimal characters). Always send the key exactly as returned.
  • An agent registration is not tied to one merchant. Use the same credentials for every Adobe Commerce Optimizer tenant.
WARNING
The API key is shown only once. Store it in a secrets manager. Never put it in source control, URLs, or logs.

Step 2: Send agent credentials and a shopper session headers

Send these headers on every call to Shopper MCP Server:

Header
Required
Value
X-Agent-ID
Always
Your agentId.
X-Agent-Key
Always
Your apiKey, exactly as returned at registration.
X-Environment-Id
Always
The merchant’s tenant ID.
X-View-Id
Always
The merchant’s Adobe Commerce Optimizer view ID. Required to route the call as Adobe Commerce Optimizer.
X-Session-Id
When a tool needs a shopper
Your ID for the shopper’s conversation: at least 32 characters from A-Z, a-z, 0-9, ., _, and -. Send it on every call of that conversation.
X-Mcp-Registry
Always
true. Shopper MCP Server then reads the merchant’s registration from the MCP Registry. Without this header, the merchant’s custom tools are not loaded and shopper sign-in is unavailable.
curl -X POST 'https://commerce-storefront-sandbox.adobe.io/mcp' \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -H 'X-Agent-ID: <agent-id>' \
  -H 'X-Agent-Key: <agent-api-key>' \
  -H 'X-Environment-Id: <merchant-tenant-id>' \
  -H 'X-View-Id: <merchant-view-id>' \
  -H 'X-Session-Id: <shopper-session-id>' \
  -H 'X-Mcp-Registry: true' \
  -d '{
    "jsonrpc": "2.0",
    "method": "tools/call",
    "params": { "name": "<custom-tool-name>", "arguments": {} },
    "id": 1
  }'
  • Generate session IDs with a secure random generator, for example python3 -c "import secrets; print(secrets.token_urlsafe(32))" (43 characters).
  • Treat the session ID like a session cookie: unguessable, never in URLs or logs, and never shared between shoppers.
  • A session ID belongs to your agent. If another agent sends the same session ID, it gets a separate session and its own sign-in.
  • Reuse the same session ID to reuse the shopper’s sign-in. When the access token is within 5 minutes of expiry, the next call refreshes it, or asks the shopper to sign in again if there is no usable refresh token. Use a new session ID to start over, for example when the shopper signs out or another shopper uses the agent.
  • Missing or wrong agent credentials return HTTP 401 with {"error": "unauthorized", "message": "Invalid agent credentials."}.

Step 3: Handle sign-in requests sign-in-requests

When a tool cannot run without a signed-in shopper, the tool result has isError: true, and its text content is a JSON object:

{
  "error": "auth_required",
  "authorizationUrl": "https://login.example.com/oauth2/authorize?response_type=code&client_id=...&redirect_uri=...&state=Qm9...&code_challenge=E9M...&code_challenge_method=S256",
  "state": "Qm9...",
  "expiresAt": "2026-01-15T10:10:00.000Z",
  "hint": "The shopper must log in. Send the shopper to authorizationUrl, then retry this tool call with the same X-Session-Id after your webhook is notified for this state."
}
error
When
What to do
auth_required
The shopper has not signed in yet, or must sign in again.
Show authorizationUrl to the shopper. It expires at expiresAt, after 10 minutes. Remember state for this conversation and wait for the webhook (Step 4).
session_id_required
X-Session-Id is missing or malformed.
Send a valid X-Session-Id and retry.
auth_unavailable
Sign-in is temporarily unavailable, or the merchant’s runtime rejected the shopper’s token.
Retry later. If the error persists, contact the merchant.
NOTE
Never pass shopper tokens yourself. Tools do not accept an auth_token argument, and the Authorization header that you send is never forwarded to Adobe Commerce or to custom tools.

Step 4: Receive webhook notifications webhook

When the sign-in finishes, the MCP Auth Server sends:

POST https://agent.example.com/smcp/webhook
Content-Type: application/json

{"tenantId": "<merchant-tenant-id>", "state": "Qm9...", "status": "AUTHORIZED"}
status
When
error
AUTHORIZED
The shopper signed in and the tokens are stored.
Absent
DENIED
The shopper or the merchant’s authorization server denied the request.
The OAuth 2.0 error code, for example access_denied or invalid_scope. Absent when the authorization server returned a non-standard code.
FAILED
The sign-in could not be completed.
invalid_grant, temporarily_unavailable, or server_error
  • Answer with any 2xx within 5 seconds. 5xx responses, timeouts, and connection errors are retried, with 3 attempts in total and exponential backoff from 0.5 seconds. 3xx and 4xx responses are not retried, and redirects are not followed.
  • Delivery is best effort. If no notification arrives, let the shopper tell you that they are done, and retry anyway.
  • Use tenantId and state to find the conversation.
IMPORTANT
Notifications are not signed and never contain tokens or the session ID. Treat them as a signal to retry, not as proof of sign-in.

Step 5: Retry the tool call retry

Notification
Next step
AUTHORIZED
Retry the same tool call with the same X-Session-Id and headers. Shopper MCP Server now passes the shopper’s token to the custom tool.
DENIED
Check error. For access_denied or no error, tell the shopper that sign-in was cancelled. Calling the tool again starts a new sign-in. For temporarily_unavailable, try again later. For any other code, for example invalid_scope, unauthorized_client, or server_error, the merchant must fix their configuration first. Do not retry in a loop.
FAILED
For invalid_grant or temporarily_unavailable, call the tool again to start a new sign-in. For server_error, the merchant must fix their configuration first.

Manage agent credentials manage

Rotate the API key:

curl -X POST 'https://na1-sandbox.api.commerce.adobe.com/mcp-registry/api/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <ims-service-token>' \
  -d '{"query": "mutation { rotateAgentApiKey(agentId: \"<agent-id>\") { agentId apiKey } }"}'

The new key is shown only once. The previous key keeps working until cached validations expire, for up to about 2 minutes (120 seconds).

Delete the agent:

curl -X POST 'https://na1-sandbox.api.commerce.adobe.com/mcp-registry/api/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <ims-service-token>' \
  -d '{"query": "mutation { deleteAgent(agentId: \"<agent-id>\") }"}'

Troubleshooting troubleshooting

Problem
Solution
The agent gets HTTP 401 Invalid agent credentials.
Check both X-Agent-ID and X-Agent-Key, and check that the key was not rotated and the agent was not deleted.
onboardAgent or rotateAgentApiKey fails with Agent key generation is temporarily unavailable.
No agent or key was created or changed. Retry the call later.
The merchant’s custom tools are missing from tools/list.
Send X-Mcp-Registry: true. Custom tools are loaded only from the MCP Registry.
The agent gets auth_unavailable instead of a sign-in link.
Check that you send X-Mcp-Registry: true. If you do, the merchant’s registration or runtime is misconfigured. See the merchant troubleshooting.
The webhook never arrives.
Check that the webhook URL is a public https:// URL, answers 2xx within 5 seconds, and does not redirect. Delivery is best effort, so retry the tool call anyway.

Limits limits

Item
Value
Sign-in link (state)
Valid for 10 minutes. Can be used once.
X-Session-Id
At least 32 characters from A-Z, a-z, 0-9, ., _, and -.
Webhook
3 attempts, 5 seconds each, exponential backoff from 0.5 seconds.
Webhook URL
https://, public host, at most 2048 characters.

Next step next-step

Connect to Shopper MCP Server and verify that the merchant’s custom tools appear in tools/list.

recommendation-more-help
commerce-help-shopper-mcp