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 } }"}'
webhookUrlis an absolutehttps://URL on a public host, at most 2048 characters. See Step 4.- The response contains your
agentIdandapiKey(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.
Step 2: Send agent credentials and a shopper session headers
Send these headers on every call to Shopper MCP Server:
X-Agent-IDagentId.X-Agent-KeyapiKey, exactly as returned at registration.X-Environment-IdX-View-IdX-Session-IdA-Z, a-z, 0-9, ., _, and -. Send it on every call of that conversation.X-Mcp-Registrytrue. 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
401with{"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."
}
errorauth_requiredauthorizationUrl to the shopper. It expires at expiresAt, after 10 minutes. Remember state for this conversation and wait for the webhook (Step 4).session_id_requiredX-Session-Id is missing or malformed.X-Session-Id and retry.auth_unavailableauth_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"}
statuserrorAUTHORIZEDDENIEDaccess_denied or invalid_scope. Absent when the authorization server returned a non-standard code.FAILEDinvalid_grant, temporarily_unavailable, or server_error- Answer with any
2xxwithin 5 seconds.5xxresponses, timeouts, and connection errors are retried, with 3 attempts in total and exponential backoff from 0.5 seconds.3xxand4xxresponses 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
tenantIdandstateto find the conversation.
Step 5: Retry the tool call retry
AUTHORIZEDX-Session-Id and headers. Shopper MCP Server now passes the shopper’s token to the custom tool.DENIEDerror. 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.FAILEDinvalid_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
401 Invalid agent credentials.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.tools/list.X-Mcp-Registry: true. Custom tools are loaded only from the MCP Registry.auth_unavailable instead of a sign-in link.X-Mcp-Registry: true. If you do, the merchant’s registration or runtime is misconfigured. See the merchant troubleshooting.https:// URL, answers 2xx within 5 seconds, and does not redirect. Delivery is best effort, so retry the tool call anyway.Limits limits
state)X-Session-IdA-Z, a-z, 0-9, ., _, and -.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.