Skip to main content

Build a Storefront AI agent

Build an AI chat agent that helps shoppers find products faster and complete purchases through natural conversation. The agent can answer questions about products, shipping policies, and manage shopping carts using the Model Context Protocol (MCP) to connect with Shopify's commerce features.

Use natural language to search for products, get recommendations, ask questions about store policies, and complete checkout—all within a chat window.

Requirements

Node.js v18.20 or higher

Download from nodejs.org and install.

Shopify Partner account

Sign up at shopify.com/partners.

Shopify dev store with sample products

Create a dev store for testing - see the dev stores guide. Make sure to add some sample products.

Claude API Key

Generate a key in the Claude Console and store it securely. This template uses Claude, but you can swap in any LLM by updating the code.

Latest version of Shopify CLI

Install the latest version of Shopify CLI. You'll need this before starting the tutorial.

Project

Anchor to Clone the repositoryClone the repository

Terminal

git clone https://github.com/Shopify/shop-chat-agent.git
cd shop-chat-agent

Anchor to Install dependenciesInstall dependencies

Terminal

npm install

Anchor to Set up environment variablesSet up environment variables

Rename the .env.example file to .env and make sure it has your Claude API key:

.env

CLAUDE_API_KEY=your_claude_api_key
Note

See the Change the AI provider section if you want to use a different LLM.

Anchor to Install the latest Shopify CLIInstall the latest Shopify CLI

Terminal

npm install -g @shopify/cli@latest

Anchor to Start the development serverStart the development server

  1. Run the following command to start the development server:

Terminal

shopify app dev --use-localhost --reset

Anchor to Select your organizationSelect your organization

? Which organization is this work for?
> Organization name

Anchor to Select Yes to create this project as a new appSelect Yes to create this project as a new app

? Create this project as a new app on Shopify?
> (y) Yes, create it as a new app

Anchor to Accept the default app nameAccept the default app name

Hit enter to accept the default name shop-chat-agent. All references in the code use this name.

? App name:
> shop-chat-agent

Anchor to Keep the configuration file name blankKeep the configuration file name blank

? Configuration file name:
āœ” (empty)

Anchor to Overwrite existing configuration fileOverwrite existing configuration file

Select no and overwrite your existing configuration file:

? Configuration file shopify.app.toml already exists. Do you want to choose a different configuration name?
āœ” No, overwrite my existing configuration file

Anchor to Select your dev storeSelect your dev store

Choose the dev store you would like to use:

? Which store would you like to use to view your project?
āœ” your-store

Anchor to Enter your store passwordEnter your store password

You can get your store password from the URL that is in your terminal:

? Incorrect store password (
https://your-store.myshopify.com/admin/online_store/preferences ). Please
try again:
> *****ā–ˆ________
Note

At this stage, you will see Preview URL: https://your-store.myshopify.com/... in your terminal. You can now proceed to the next step. If you get an error, restart from the Shopify CLI installation step.

Anchor to Generate a certificate for localhostGenerate a certificate for localhost

? --use-localhost requires a certificate for `localhost`. Generate it now?
> Yes, use mkcert to generate it

Anchor to Allow automatic URL updatesAllow automatic URL updates

Select yes to automatically update your app's URL:

Have Shopify automatically update your app's URL in order to create a preview experience?
> Yes, automatically update

Follow the Preview URL: https://your-store.myshopify.com/... in your terminal to open your store in your browser.

Anchor to Enable the theme extensionEnable the theme extension

In your Shopify admin, navigate to Online Store > Themes

  • Click the Customize button
  • Click the App embeds icon in the sidebar
  • Enable the toggle
  • Click Save

Congratulations!

Your AI shopping assistant is now fully functional for product search, cart management, and store policy questions.

You can start testing and customizing your app, or continue to the next section to enhance it with the customer accounts MCP server.

Anchor to (Optional) Configure customer accounts authentication(Optional) Configure customer accounts authentication

Add order history and account management features to your AI assistant:

You'll need Level 2 protected customer data permissions to use the Customer accounts MCP server. See Shopify's guidelines.

Anchor to Verify Next-Gen Dev Platform accessVerify Next-Gen Dev Platform access

Verify that you have access to the Next-Gen dev platform. This is required for the customer accounts authentication features.

Anchor to Create your app on the Next-Gen Dev PlatformCreate your app on the Next-Gen Dev Platform

Follow the steps on the Next-Gen dev platform page to create a Storefront AI agent app using a partner organization. You can use the code from the reference app repo.

Anchor to Set up your dev storeSet up your dev store

Create a dev store on the Next-Gen Dev Platform. Make sure to add some sample products to test the AI agent functionality.

Anchor to Log in to Shopify PartnersLog in to Shopify Partners

Log in to your Shopify Partners dashboard.

Navigate to Apps and select your app under the Dev Dashboard apps tab.

Click API access requests.

Anchor to Request protected data accessRequest protected data access

Click Request access under the Protected customer data section.

Anchor to Provide a reason for accessing protected dataProvide a reason for accessing protected data

Click select on protected customer data. Provide a clear reason for requesting this data.

Anchor to Provide a reason for accessing specific data fieldsProvide a reason for accessing specific data fields

Click select for each data field: name, email, phone, and address. Provide a clear reason for requesting each field.

Anchor to Update your app's TOML fileUpdate your app's TOML file

shopify.app.toml

# Add customer accounts MCP configurations

[customer_authentication]
redirect_uris = [
"https://your-app-domain.com/callback"
]

Replace your-app-domain.com with your actual app domain.

Start app dev again if it's not already running:

Terminal

shopify app dev --use-localhost
Was this page helpful?