Staff can ask a store operations agent which products are running low, check an order's status, or propose a catalog edit. The agent retrieves current Shopify data and asks for approval before submitting a product change.
Vercel Connect manages the Shopify connection and supplies short-lived Admin API tokens to your server. The AI SDK handles the agent's tools and chat responses, with model requests routed through AI Gateway. Both Connect and AI Gateway can authenticate the deployment through Vercel OIDC.
Copy link to headingOverview
Start with the staff agent for interactive store operations. The optional extensions add catalog analysis, background reviews, or a separate shopper-facing assistant.
| Build | Start with | Additional setup |
|---|---|---|
| Staff chat agent | Steps 1–11 | Staff sign-in and permission checks |
| Catalog analysis | Staff agent, then the Drives add-on | Persistent workspace and sandbox execution |
| Background order reviews | Shopify connector setup, then the Daemons add-on | Worker deployment and order-write access |
| Shopper account assistant | Customer Accounts MCP add-on | Shopper sign-in and a separate OAuth connector |
Copy link to headingPrerequisites
Before you begin, prepare:
- A Vercel account.
- A Shopify development store for app installation and product edits
- Server-side sign-in and staff permission checks for the connected store
- A private signing secret for tool approvals, configured in step seven
For local development, you also need Node.js 24+ and the Vercel CLI.
The staff session adapter must return a trusted user ID and enforce your store permissions before the agent route is deployed.
Copy link to headingHow it works
The agent runs in a Next.js route handler. Each Shopify tool uses a Connect token to query the Admin API and return data to the model.
| Piece | Role |
|---|---|
ToolLoopAgent (AI SDK 7) | Runs the model and tool loop, and pauses for approval before write tools run |
| AI Gateway | Routes model calls from a creator/model-name string, authenticated with your project's OIDC token |
| Vercel Connect | Exchanges the same OIDC token for a short-lived Shopify Admin API token |
| Shopify Admin GraphQL API | Serves product and order data at API version 2026-10 |
The app doesn't need to persist Shopify credentials. Connect verifies the deployment's OIDC identity and its connector link for the project and environment.
The SDK keeps the token in server memory and reuses it for matching requests until it is within 30 seconds of expiry. Separate instances and concurrent cache misses can make additional token requests.
Copy link to headingWhy not use a Shopify MCP server?
Shopify runs several MCP servers, but none of them gives a staff agent read and write access to a store's products and orders:
| Server | Access it provides | Fit for this agent |
|---|---|---|
| Shopify Dev MCP | Shopify documentation, schemas, and development validation | Helps build the integration; it does not access store records |
| Storefront Catalog MCP | Public product discovery for shoppers | Useful for catalog browsing; it does not provide staff Admin API access |
| Customer Accounts MCP | The authorized customer's orders and account | Use for the shopper-facing add-on |
| A custom Admin API MCP server | The operations and authentication its implementation exposes | Review its tools, credentials, and approval controls before use |
Defining the tools yourself lets you expose the Admin API operations this agent needs and require approval for catalog changes. Each tool declares its requested scopes alongside the operation it calls.
The Customer Accounts server is a good fit for a different agent, one that shoppers talk to. The last add-on builds that agent with Vercel Connect.
Copy link to headingSteps
Copy link to heading1. Create a Next.js app
pnpm create next-app@latest shopify-agent --yescd shopify-agentCopy link to heading2. Install the packages
pnpm add ai@^7 @ai-sdk/react@^4 @vercel/connect@^2.9 zod@^4The examples use AI SDK 7, React adapter 4, and Connect 2.9 or later within major version 2. Keep the lockfile to deploy the versions you tested.
Copy link to heading3. Link the project and create the Shopify connector
Link the project, then create its Shopify connector:
Use an app-level connection method with credentials for a Shopify app installed on the store. Create the app in Shopify before configuring the connector.
If you use the client-credentials grant, the app and store must belong to the same Shopify organization. To inspect the preset's connection methods, run:
Grant the app these Admin API access scopes:
| Scope | Used by |
|---|---|
read_products | searchProducts and the Drives exportCatalog tool |
write_products | updateProduct |
read_orders | getOrder and the order review daemon |
write_orders | Optional order review daemon; omit this scope for the chat-only setup |
Order access also follows Shopify's protected customer data requirements. Public apps must request the data they use; custom apps have different access rules.
For development stores, select the required data and fields in the app dashboard. Production review is not required for development-only access. The daemon's shipping-address query needs address access.
Without the read_all_orders scope, which Shopify grants only after you request it, Shopify returns only the last 60 days of orders.
Attach the connector to your project. With no --environment option, the CLI links Production, Preview, and Development:
Copy link to heading4. Add your store domain and pull environment variables
Add your store's myshopify.com domain so the client knows where to send requests. The domain identifies the store and is safe to keep in configuration.
Enter a value such as acme.myshopify.com and select the environments linked to this store. Pulling the environment variables creates .env.local with the development OIDC token used by Connect and AI Gateway.
Local OIDC tokens expire after about 12 hours. If authentication starts failing, run vercel env pull again.
If you named the connector something other than acme-shopify, also add SHOPIFY_CONNECTOR with the connector's UID, such as shopify/my-store.
Copy link to heading5. Create a Shopify client
Create lib/shopify.ts to pass each operation's requested scopes to Connect and send the GraphQL request:
The app subject acts with your Shopify app's authority. It does not inherit the signed-in staff member's permissions.
Requested scopes describe what a tool needs, but the connector's authorization method determines the token's permissions. Shopify's client-credentials grant returns the installation's granted scopes even when fewer are requested. Approval controls whether the tool executes.
If Shopify rejects a token with HTTP 401, the helper removes its matching SDK cache entry and requests a token again. It retries the Shopify request once; Connect and Shopify determine whether the returned token is renewed.
Copy link to heading6. Define the agent's tools
Create lib/tools.ts with three tools. Each tool has a description the model reads, a Zod input schema, and an execute function that calls Shopify:
Product search accepts Shopify filters such as status, vendor, tag, and inventory_total. Its result includes the shop currency so the agent can quote prices correctly. Order lookup accepts names such as #1001.
Product updates return Shopify's userErrors for the agent to explain. Passing tags replaces the complete tag list, so the lookup includes existing tags for the proposed replacement to retain.
These lookups return up to 10 variants per product and 50 line items per order. Add pagination before using them for analysis that requires every variant or line item.
Copy link to heading7. Create the agent
Create a private TOOL_APPROVAL_SECRET so the SDK can verify that approval requests came from your server. Generate a value, add it to each deployment environment, and pull it for local development:
Use the same value across instances that handle the same approval conversation. Keep it server-side and never prefix it with NEXT_PUBLIC_.
Create lib/tool-approval.ts to require the setting:
Then create lib/agent.ts:
The agent asks for approval before running updateProduct. The SDK signs the tool name, call ID, and arguments, then checks that signature when the decision returns.
Signatures do not identify the approver or prevent a valid approval from being replayed. Keep staff authorization on the route and use server-owned conversation state to bind sensitive approvals to a user and record completed writes.
isStepCount(10) caps one run at ten model steps. The model ID comes from AGENT_MODEL when it's set, so you can switch models without a code change.
Copy link to heading8. Add the route handler
Connect getStoreOperator to your authentication library's server-side session lookup. It must check permission for the store in SHOPIFY_STORE_DOMAIN. The adapter below deliberately throws until that integration exists.
Create lib/staff-session.ts:
Then add app/api/agent/route.ts:
Copy link to heading9. Build the chat UI
Replace app/page.tsx with a minimal chat that renders text and approval requests:
The page shows each proposed product change with Approve and Deny buttons. It sends the staff member's decision to the route.
The chat also shows request and tool failures. Empty submissions and overlapping sends are disabled while a response is in progress.
Copy link to heading10. Run it locally
Start the dev server:
pnpm devOpen http://localhost:3000 and try these prompts:
- Which active products have fewer than 5 units in stock?
- What's the fulfillment status of order #1001?
- Rename the Acme Mug to "Acme Mug (Restocked)".
Confirm that the third prompt shows Approve and Deny before the product changes. Use a test product in the development store, then check that denying the request leaves it unchanged.
Your staff session controls route access. .env.local holds the OIDC token for Connect requests through the Development link.
Copy link to heading11. Deploy
On Vercel, the SDK reads the deployment's OIDC token automatically. Open the connector's Observability tab in the Connect dashboard to see the connector's token requests, which you can filter by project and environment.
Copy link to headingAdd-on: Give the agent a persistent workspace with Vercel Drives
Compare this week's vendors with saved catalog exports. Vercel Drives preserve those snapshots across sessions for analysis in Vercel Sandbox.
The function keeps the Shopify token and writes catalog data to the drive. Generated commands get a read-only mount and no outbound network access.
Install the Sandbox SDK:
pnpm add @vercel/sandboxCopy link to headingWrite to and read from the drive
Create lib/workspace.ts:
Each drive allows one read-write mount at a time, so run catalog exports one at a time. The writer releases its mount when the sandbox stops. Multiple agent runs can read snapshots concurrently.
Both helpers create the sandbox in the drive's region and discard its temporary filesystem on shutdown. The analysis command has a 30-second deadline.
The helper stops the command if stdout exceeds 20,000 characters or stderr exceeds 5,000, and reports truncated output. It consumes logs incrementally instead of collecting the complete output before slicing it.
Copy link to headingAdd the workspace tools
Create lib/workspace-tools.ts:
Exports support up to 5,000 products and are saved only after the last page. Each export gets a unique path to preserve previous snapshots.
If products remain after 20 pages, the tool saves nothing and directs the agent to use a Shopify bulk export. Export the catalog before analysis; command failures return an error to the model.
Copy link to headingRegister the tools with the agent
Update lib/agent.ts:
Ask the agent to export the catalog, then ask a question that needs the full file, such as "How many products from each vendor are in today's snapshot?" On later days, ask it to compare two snapshots.
Each export or analysis starts a sandbox, which adds startup and execution time to the tool call. Drive storage charges depend on stored data. Review the storage rates and included usage when choosing how many snapshots to retain.
Copy link to headingAdd-on: Review orders in the background with Vercel Daemons
Staff can tag an order agent-review in Shopify for a background review. The Vercel Daemon polls for tagged orders and writes a model-generated note to each one.
Successful reviews receive an agent-reviewed tag. Orders the model flags for staff attention also receive needs-human.
The pending tag identifies work for the daemon without a separate queue. It provides no job lease, so more than one worker can process the same order.
Vercel Daemons is in public beta and runs only for production deployments. Run the worker locally with Docker because vercel dev does not start daemons.
Copy link to headingWrite the worker
Create a worker/ directory with its own package.json:
The override enables file-based OIDC authentication for this worker's model calls. Daemons supply their token through VERCEL_OIDC_TOKEN_FILE, which version 4.0 and later of @vercel/oidc can read.
The AI Gateway dependency used here still pins version 3.2.0. Keep the override when generating the worker's lockfile so model calls can read the daemon token.
Create worker/worker.js:
The worker saves the note and checks for errors before adding the outcome tags. It removes agent-review only after both writes succeed. Each order has its own error handler so a failed review does not skip the rest of the selected batch.
Retries can duplicate notes after a partial success or restart. Before production use, track reviews by durable ID and skip completed work.
The worker reads the note again after generation to include intervening staff edits. The update still replaces the entire note field, so coordinate shared edits or store agent reviews separately to prevent concurrent changes from being overwritten.
On SIGTERM, the abort signal ends the 60-second wait immediately, and the loop exits after the order it's working on. If a review outlasts the 30-second default grace period, raise terminationGracePeriodSeconds in the daemon's configuration.
Generate the lockfile that the Dockerfile installs from:
Copy link to headingAdd a Dockerfile
Create worker/Dockerfile:
Copy link to headingDeclare the daemon
Add the daemons key to vercel.json at the project root:
The configuration requests one instance, but deployments can briefly overlap old and new workers. Reading the pending tag and updating it are separate operations, so both workers can select the same order.
For multiple consumers, use Vercel Queues in poll mode with a visibility timeout that covers processing. Review writes must tolerate repeat delivery.
Setting resources.requests.memory to 1Gi gives the worker 1 vCPU and halves its Provisioned Memory usage compared with the 2 GiB default.
On Hobby, team daemons share 420 GB-hours of Provisioned Memory and 5 Active CPU-hours each month. Idle time counts toward memory usage, so an always-on 1 GiB instance exhausts that allowance in about two and a half weeks.
Reaching either quota stops the team's daemons until the next month or a plan upgrade. Use Hobby to try the worker; budget for Pro usage if it needs to stay online throughout the month.
Copy link to headingDeploy and watch the logs
After the production deployment is ready, select order-review under Daemons in the project dashboard to view its instance and logs.
Tag a test order with agent-review in Shopify. The worker checks for tagged orders between batches, with a 60-second wait after each batch. After a successful review, confirm that the log names the order and its note includes the new review.
The daemon uses the same Shopify connector as your app, so its token requests appear in the same Observability tab under the production environment.
Copy link to headingAdd-on: Let shoppers ask about their own orders with the Customer Accounts MCP server
The staff agent uses your app's authority. Shopify's Customer Accounts MCP server instead gives a shopper access to their own orders and account after authorization.
Vercel Connect manages the OAuth flow and stores each shopper's authorization under the user ID you supply. The MCP adapter gets the shopper's token through Connect and can reuse it from the SDK's process cache. Your application does not need a token database.
Copy link to headingSet up the Shopify app for customer accounts
The Customer Accounts MCP server has its own requirements:
- Your store has a custom domain, such as
shop.acme.com. - Your app meets Shopify's protected customer data requirements, with access requested for
name,email,phone, andaddress. - Your app is set up for customer accounts authentication.
Use the directory containing your Shopify app configuration. For an app created in the Dev Dashboard, run shopify app config link there first.
Merge the customer scopes into the existing scope list and add Connect's callback URI. Keep other scopes your app needs, including write_orders if the order-review worker uses this app:
Run shopify app deploy to release the configuration, then install or update the app on the store to grant the required access. For a development store, shopify app dev applies the configuration during the development session.
Copy link to headingCreate the connector
Create a connector from your storefront domain. Connect reads the store's OpenID Connect discovery document to find the authorization and token endpoints:
Enter your Shopify app's client ID and leave the client secret blank. This app configuration uses a public OAuth client with PKCE.
Use the UID printed by create for the connector link and CUSTOMER_ACCOUNTS_CONNECTOR. Confirm it matches the UID in the attach command.
Add the storefront domain, and the connector UID if it differs from oauth/acme-customer-accounts, then pull the variables:
Install the AI SDK MCP client:
pnpm add @ai-sdk/mcp@^2Copy link to headingIdentify the shopper
Connect stores one grant per user ID, so the ID has to come from your own sign-in session. Create lib/session.ts and connect it to your auth library:
An ID taken from the request body would let anyone use another shopper's grant.
Copy link to headingFind the MCP endpoint
Read the store's discovery document to find its Customer Accounts MCP endpoint:
AccountUIMessage adds a consent data part, which the route uses to send the shopper a sign-in link through the chat.
Copy link to headingAdd the route
Use the step 7 signing helper for the customer route below:
The route requests a customer token with the signed-in user's ID and Shopify's MCP scope. Eager consent checks authorization before any MCP traffic.
During MCP setup, the route returns a consent link when Connect requires authorization or reports that no valid token remains. Both paths authorize the same shopper and scope, then return the shopper to /account.
This public client receives no refresh token. Expired access requires another browser authorization, which can reuse an active Shopify customer session.
The route asks for approval except when Shopify marks a tool read-only. For other MCP servers, define your own tool allowlist and approval policy.
Each request opens its own MCP client. The route closes it when the stream ends or response creation fails, and preserves the original error if cleanup also fails.
Copy link to headingAdd the account page
Create app/account/page.tsx:
Customer Accounts tools arrive as dynamic-tool parts because their names are discovered at runtime. The page handles their approval requests and errors alongside the consent link.
Copy link to headingTry it
Sign in to your app as a shopper, open /account, and ask "Where's my most recent order?" The first reply is a Connect your Shopify account link. Approve access on Shopify's sign-in page, and Connect returns you to /account. Ask again, and the agent answers from the Customer Accounts MCP server.
Handle disconnect on the server using the connector UID and the shopper ID from the authenticated session. Connect removes its stored authorization and clears the current process's token cache.
Whether previously issued tokens stop working immediately depends on the connector and Shopify's revocation support:
Copy link to headingBest practices
- Require server-verified approval for staff mutations. Restrict the background worker to its intended note and tag updates.
- Request the scopes each tool needs. Configure installed Shopify permissions separately, since requested scopes may not narrow the issued token.
- Keep test stores on separate connectors. Every environment linked to a connector reaches the same store, so link the development-store connector only to Development and Preview.
- Set
AGENT_MODELand redeploy to switch models. - Keep the Admin API version pinned and schedule upgrades before support ends. Shopify supports stable versions for at least 12 months.
Copy link to headingTroubleshooting
Copy link to headingConnect returns 403 with code forbidden
Check that the project is linked to the connector and the link includes the request's environment. Run vercel connect attach shopify/acme-shopify from the project directory. Local requests require a Development link.
Copy link to headingConnect returns 404 with code not_found
vercel connect list --all-projects includes connectors that aren't linked to the current project. Check the team and UID before setting SHOPIFY_CONNECTOR, then attach the connector to the project.
Copy link to headingRequests fail locally after working earlier
The development OIDC token in .env.local has expired. Run vercel env pull again.
Copy link to headingShopify returns an access denied error
Check the scope or protected-data permission named in Shopify's error. Update the app's scopes and approve the changed installation permissions when needed. For order or address data, also check protected customer data access.
Copy link to headingDaemon logs show GatewayAuthenticationError
Run npm ls @vercel/oidc from worker/ to inspect the resolved dependencies. If AI Gateway uses version 3.x, add the override and regenerate the lockfile with npm install before redeploying.
If the dependency is already 4.x, check the Gateway authentication configuration. This error can have more than one cause.
Copy link to headingThe daemon doesn't start on a preview deployment
Daemons run only in production during the beta. For local testing, create .env.docker at the project root with SHOPIFY_STORE_DOMAIN and VERCEL_OIDC_TOKEN from .env.local. Include SHOPIFY_CONNECTOR if you used a custom connector UID.
Leave out quotation marks because Docker reads the values literally. Keep this file out of version control, then build and run the worker:
The development OIDC token authenticates requests to Connect and AI Gateway. Pull a new token into .env.local and update .env.docker if it expires.
Copy link to headingRelated resources and next steps
- Plan connector access and token usage across projects.
- Check token requests and SDK errors when integrating Connect.
- Configure MCP authentication and consent.
- Set up Shopify Customer Accounts MCP.
- Manage drive snapshots, forks, and storage limits.
- Configure daemon scaling and graceful shutdown.
- Add durable agent execution with WorkflowAgent.
Copy link to headingFrequently asked questions
Copy link to headingDo I need to store a Shopify access token to build this agent?
No. Set the store domain and connector ID. Connect uses the deployment's OIDC identity to fetch tokens and cache them in server memory.
Copy link to headingHow does the agent avoid changing products without permission?
The chat shows the proposed product change and returns the staff member's decision. The SDK checks the signed approval before executing the tool, and the route checks staff access on each request. For one-time approval, the application must also track completion and bind the conversation to the signed-in user.
Copy link to headingHow many Vercel Connect token requests does the agent make?
The count depends on which tools run and whether their tokens are cached. Different scopes use separate cache entries, and new instances, concurrent misses, expiry, or rejected-token retries can trigger additional requests.
Connect pricing includes 500 token requests each month on Hobby. Pro charges $3.00 per 1,000 requests.
Copy link to headingWhen should I add Vercel Drives to a Shopify agent?
Add a drive when the agent needs data that's larger than a tool result or needs to persist between conversations, such as daily catalog snapshots it compares over time. The drive stores the files, and each analysis runs in a short-lived sandbox that mounts a read-only snapshot of it.
Copy link to headingWhy does the order review daemon need an @vercel/oidc override?
The override lets the daemon read its OIDC token file. AI Gateway pins @vercel/oidc 3.2.0, but file-based tokens require version 4.0 or later.
Copy link to headingCan a Shopify agent use Shopify's MCP servers with Vercel Connect?
Yes, for agents that act for shoppers. The Customer Accounts MCP server needs a per-shopper OAuth grant, and connectAuthProvider gets that grant from Vercel Connect for each signed-in user. For a store operations agent, the Admin GraphQL API is the better fit, because none of Shopify's MCP servers gives staff access to the store's products and orders.