This server provides access to the Shopify Storefront API via MCP, allowing AI assistants to query and interact with your Shopify store data. - Access to product, collection, and inventory data - Cart creation and management - Support for GraphQL queries and mutations - Automatic token handling and validation - Easy integration with MCP-compatible AI assistants 1. Clone this repository 2. Install
Add this skill
npx mdskills install QuentinCody/shopify-storefront-mcp-serverWell-documented MCP server with comprehensive setup, tool descriptions, and customer data management
1# Shopify Storefront MCP Server23This server provides access to the Shopify Storefront API via MCP, allowing AI assistants to query and interact with your Shopify store data.45## Features67- Access to product, collection, and inventory data8- Cart creation and management9- Support for GraphQL queries and mutations10- Automatic token handling and validation11- Easy integration with MCP-compatible AI assistants1213## Setup Instructions14151. Clone this repository162. Install dependencies: `pip install -r requirements.txt`173. Copy `.env.example` to `.env` and configure your environment variables184. Generate a Storefront API token via Shopify Admin (see below)195. Run the server: `python -m shopify_storefront_mcp_server`2021## Environment Variables2223Create a `.env` file using the provided `.env.example` as a template:2425```26# Required27SHOPIFY_STOREFRONT_ACCESS_TOKEN=your_storefront_token28SHOPIFY_STORE_NAME=your-store-name2930# Optional31SHOPIFY_API_VERSION=2025-0432SHOPIFY_BUYER_IP=127.0.0.133```3435## Generating a Storefront API Token36371. Log in to your Shopify admin382. Go to **Apps and sales channels** > **Develop apps** > **Create an app**393. Name your app (e.g., "MCP Storefront")404. Go to **API credentials** > **Configure Storefront API scopes**415. Select necessary scopes:42 - `unauthenticated_read_product_listings`43 - `unauthenticated_read_product_inventory`44 - `unauthenticated_read_product_pricing`45 - `unauthenticated_write_checkouts`46 - `unauthenticated_read_content`476. Save and copy the generated Storefront API access token487. Add the token to your `.env` file as `SHOPIFY_STOREFRONT_ACCESS_TOKEN`4950## Usage Examples5152Running with the MCP server:5354```55python -m shopify_storefront_mcp_server56```5758The server exposes the following MCP tools:5960- `shopify_discover`: Detect if a URL belongs to a Shopify storefront and discover authentication tokens61- `shopify_storefront_graphql`: Execute GraphQL queries against the Storefront API62- `customer_data`: Unified tool for all customer data operations (Create, Read, Update, Delete)6364### Customer Resources6566This server also provides MCP resources for customer information:6768- `customer://name`: Customer's full name69- `customer://email`: Customer's email address70- `customer://phone`: Customer's phone number71- `customer://shipping_address`: Customer's shipping address (including address1, address2, city, state, postal_code, country)72- `customer://billing_address`: Customer's billing address (including address1, address2, city, state, postal_code, country)73- `customer://profile`: Complete customer profile7475Customer data is stored in `user_data/customer.json` and should be managed using the `customer_data` tool.7677### Managing Customer Data7879The server provides a unified `customer_data` tool for managing all customer information. This tool consolidates create, read, update, and delete operations into a single interface.8081Examples:8283```84# Get all customer data85customer_data(operation="get")8687# Get a specific field88customer_data(operation="get", field="name")89customer_data(operation="get", field="shipping_address")9091# Update a specific field92customer_data(operation="update", field="name", value="Jane Doe")93customer_data(94 operation="update",95 shipping_address={96 "address1": "123 Main St",97 "address2": "Apt 4B",98 "city": "New York",99 "state": "NY",100 "postal_code": "10001",101 "country": "US"102 }103)104105# Add custom fields106customer_data(107 operation="update",108 custom_fields={109 "preferences": {110 "theme": "dark",111 "notifications": "email",112 "language": "en-US"113 },114 "loyalty_tier": "gold",115 "last_purchase_date": "2023-06-15"116 }117)118119# Get a custom field120customer_data(operation="get", field="preferences")121customer_data(operation="get", field="loyalty_tier")122123# Update single custom field124customer_data(operation="update", field="loyalty_tier", value="platinum")125126# Delete a specific field127customer_data(operation="delete", field="phone")128customer_data(operation="delete", field="preferences")129130# Delete all customer data131customer_data(operation="delete")132```133134This consolidated tool simplifies integration with AI assistants by providing a consistent interface for all customer data operations, including both standard customer information and any custom fields that may be useful for personalization.135136### Data Privacy & Storage137138Customer data is stored in `user_data/customer.json`. This file contains personal information and should not be committed to version control. The repository includes:139140- `user_data/customer.json.example`: A template file showing the expected structure with dummy data141- Entries in `.gitignore` to prevent accidental commits of actual customer data142143When deploying this server, the `user_data/customer.json` file will be created automatically when the `customer_data` tool is first used. You can also copy and rename the example file to get started:144145```bash146cp user_data/customer.json.example user_data/customer.json147```148149All data stored in the customer file persists between server restarts. The file supports both standard customer fields (name, email, addresses) and arbitrary custom fields for AI personalization.150151### Creating Checkouts with Customer Data152153The server makes it easy to create Shopify checkouts that include customer information by combining the `customer_data` and `shopify_storefront_graphql` tools.154155Example workflow:156157```158# Step 1: Get customer data159customer_profile = customer_data(operation="get")160161# Step 2: Create a cart with GraphQL162cart_mutation = """163mutation createCart($lines: [CartLineInput!]!) {164 cartCreate(input: {lines: $lines}) {165 cart {166 id167 checkoutUrl168 }169 userErrors {170 field171 message172 }173 }174}175"""176177cart_variables = {178 "lines": [179 {180 "merchandiseId": "gid://shopify/ProductVariant/12345678901234",181 "quantity": 1182 }183 ]184}185186cart_result = shopify_storefront_graphql(187 mode="execute",188 host="your-store.myshopify.com",189 token="your_storefront_token",190 query=cart_mutation,191 variables=cart_variables192)193194# Step 3: Apply customer attributes to the cart195cart_id = # extract from cart_result196customer_info = json.loads(customer_profile)197198attributes_mutation = """199mutation updateCartAttributes($cartId: ID!, $attributes: [AttributeInput!]!) {200 cartAttributesUpdate(cartId: $cartId, attributes: $attributes) {201 cart {202 id203 checkoutUrl204 }205 userErrors {206 field207 message208 }209 }210}211"""212213attributes_variables = {214 "cartId": cart_id,215 "attributes": [216 {217 "key": "email",218 "value": customer_info["email"]219 },220 {221 "key": "deliveryAddress",222 "value": json.dumps(customer_info["shipping_address"])223 }224 ]225}226227shopify_storefront_graphql(228 mode="execute",229 host="your-store.myshopify.com",230 token="your_storefront_token",231 query=attributes_mutation,232 variables=attributes_variables233)234```235236This approach gives you complete control over the checkout process while leveraging the stored customer information.237238## Troubleshooting239240If you encounter authentication errors:2412421. Verify token format: Storefront API tokens should start with `shpsa_` (newer) or `shpat_` (older)2432. Check store name: Ensure SHOPIFY_STORE_NAME is correct (without .myshopify.com)2443. Check API version: Make sure the API version is supported2454. Test token: Use cURL to test your token directly:246 ```247 curl -X POST \248 https://your-store.myshopify.com/api/2025-04/graphql.json \249 -H "Content-Type: application/json" \250 -H "X-Shopify-Storefront-Access-Token: your_token" \251 -d '{"query": "query { shop { name } }"}'252 ```2535. Regenerate token: If issues persist, create a new token with proper scopes254255## Security Considerations256257- Never commit your `.env` file or any files containing API tokens258- Use environment variables for all sensitive information259- Consider setting up IP restrictions in your Shopify Admin260- Review the permissions granted to your Storefront API token261262
Full transparency — inspect the skill content before installing.