@klaudworks/shopify-mcp 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +531 -0
- package/dist/index.js +107 -0
- package/dist/lib/formatters.js +72 -0
- package/dist/lib/shopifyAuth.js +96 -0
- package/dist/lib/toolUtils.js +36 -0
- package/dist/tools/completeDraftOrder.js +76 -0
- package/dist/tools/createCustomer.js +142 -0
- package/dist/tools/createDraftOrder.js +160 -0
- package/dist/tools/createFulfillment.js +100 -0
- package/dist/tools/createProduct.js +123 -0
- package/dist/tools/createRefund.js +115 -0
- package/dist/tools/deleteCustomer.js +47 -0
- package/dist/tools/deleteMetafields.js +54 -0
- package/dist/tools/deleteProduct.js +43 -0
- package/dist/tools/deleteProductVariants.js +82 -0
- package/dist/tools/getCollectionById.js +123 -0
- package/dist/tools/getCollections.js +88 -0
- package/dist/tools/getCustomerById.js +122 -0
- package/dist/tools/getCustomerOrders.js +131 -0
- package/dist/tools/getCustomers.js +125 -0
- package/dist/tools/getFulfillmentOrders.js +106 -0
- package/dist/tools/getInventoryItems.js +86 -0
- package/dist/tools/getInventoryLevels.js +82 -0
- package/dist/tools/getLocations.js +85 -0
- package/dist/tools/getMarkets.js +91 -0
- package/dist/tools/getMetafieldDefinitions.js +112 -0
- package/dist/tools/getMetafields.js +68 -0
- package/dist/tools/getOrderById.js +212 -0
- package/dist/tools/getOrderRefundDetails.js +131 -0
- package/dist/tools/getOrderTransactions.js +85 -0
- package/dist/tools/getOrders.js +148 -0
- package/dist/tools/getPriceLists.js +92 -0
- package/dist/tools/getProductById.js +171 -0
- package/dist/tools/getProductVariantsDetailed.js +139 -0
- package/dist/tools/getProducts.js +155 -0
- package/dist/tools/getShopInfo.js +74 -0
- package/dist/tools/manageCustomerAddress.js +149 -0
- package/dist/tools/manageProductOptions.js +293 -0
- package/dist/tools/manageProductVariants.js +203 -0
- package/dist/tools/manageTags.js +79 -0
- package/dist/tools/mergeCustomers.js +74 -0
- package/dist/tools/orderCancel.js +77 -0
- package/dist/tools/orderCloseOpen.js +74 -0
- package/dist/tools/orderMarkAsPaid.js +51 -0
- package/dist/tools/registry.js +106 -0
- package/dist/tools/setInventoryQuantities.js +74 -0
- package/dist/tools/setMetafields.js +61 -0
- package/dist/tools/updateCustomer.js +119 -0
- package/dist/tools/updateOrder.js +131 -0
- package/dist/tools/updateProduct.js +132 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Shopify MCP Server Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
# Shopify MCP Server
|
|
2
|
+
|
|
3
|
+
(please leave a star if you like!)
|
|
4
|
+
|
|
5
|
+
MCP Server for Shopify API, enabling interaction with store data through GraphQL API. This server provides tools for managing products, customers, orders, and more.
|
|
6
|
+
|
|
7
|
+
**📦 Package Name: `@klaudworks/shopify-mcp`**
|
|
8
|
+
**🚀 Command: `shopify-mcp`**
|
|
9
|
+
|
|
10
|
+
> Security-hardened fork of [`shopify-mcp`](https://github.com/GeLi2001/shopify-mcp) (MIT): updated dependencies (0 known runtime vulnerabilities), strict `*.myshopify.com` domain validation, and a leaner dependency tree.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- **Product Management**: Full CRUD for products, variants, and options (8 tools)
|
|
15
|
+
- **Customer Management**: Full CRUD, merge, and address management (8 tools)
|
|
16
|
+
- **Order Management**: Smart lookup, cancel, close/open, mark as paid, fulfillment, refunds (10 tools)
|
|
17
|
+
- **Metafield Management**: Get, set, and delete metafields on any resource (3 tools)
|
|
18
|
+
- **Inventory Management**: Set absolute inventory quantities at locations (1 tool)
|
|
19
|
+
- **Tag Management**: Add/remove tags on any taggable resource (1 tool)
|
|
20
|
+
- **Pagination & Sorting**: Cursor-based pagination and sort keys on all list queries
|
|
21
|
+
- **Advanced Filtering**: Pass-through Shopify query syntax for all list endpoints
|
|
22
|
+
- **GraphQL Integration**: Direct integration with Shopify's GraphQL Admin API (2026-01)
|
|
23
|
+
- **Comprehensive Error Handling**: Clear error messages for API and authentication issues
|
|
24
|
+
|
|
25
|
+
## Prerequisites
|
|
26
|
+
|
|
27
|
+
1. Node.js (version 18 or higher)
|
|
28
|
+
2. A Shopify store with a custom app (see setup instructions below)
|
|
29
|
+
|
|
30
|
+
## Setup
|
|
31
|
+
|
|
32
|
+
### Authentication
|
|
33
|
+
|
|
34
|
+
This server supports two authentication methods:
|
|
35
|
+
|
|
36
|
+
#### Option 1: Client Credentials (Dev Dashboard apps, January 2026+)
|
|
37
|
+
|
|
38
|
+
As of January 1, 2026, new Shopify apps are created in the **Dev Dashboard** and use OAuth client credentials instead of static access tokens.
|
|
39
|
+
|
|
40
|
+
1. From your Shopify admin, go to **Settings** > **Apps and sales channels**
|
|
41
|
+
2. Click **Develop apps** > **Build app in dev dashboard**
|
|
42
|
+
3. Create a new app and configure **Admin API scopes**:
|
|
43
|
+
- `read_products`, `write_products`
|
|
44
|
+
- `read_customers`, `write_customers`
|
|
45
|
+
- `read_orders`, `write_orders`
|
|
46
|
+
4. Install the app on your store
|
|
47
|
+
5. Copy your **Client ID** and **Client Secret** from the app's API credentials
|
|
48
|
+
|
|
49
|
+
The server will automatically exchange these for an access token and refresh it before it expires (tokens are valid for ~24 hours).
|
|
50
|
+
|
|
51
|
+
#### Option 2: Static Access Token (legacy apps)
|
|
52
|
+
|
|
53
|
+
If you have an existing custom app with a static `shpat_` access token, you can still use it directly.
|
|
54
|
+
|
|
55
|
+
### Usage with Claude Desktop
|
|
56
|
+
|
|
57
|
+
**Client Credentials (recommended):**
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"shopify": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": [
|
|
65
|
+
"@klaudworks/shopify-mcp",
|
|
66
|
+
"--clientId",
|
|
67
|
+
"<YOUR_CLIENT_ID>",
|
|
68
|
+
"--clientSecret",
|
|
69
|
+
"<YOUR_CLIENT_SECRET>",
|
|
70
|
+
"--domain",
|
|
71
|
+
"<YOUR_SHOP>.myshopify.com"
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Static Access Token (legacy):**
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"mcpServers": {
|
|
83
|
+
"shopify": {
|
|
84
|
+
"command": "npx",
|
|
85
|
+
"args": [
|
|
86
|
+
"@klaudworks/shopify-mcp",
|
|
87
|
+
"--accessToken",
|
|
88
|
+
"<YOUR_ACCESS_TOKEN>",
|
|
89
|
+
"--domain",
|
|
90
|
+
"<YOUR_SHOP>.myshopify.com"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Locations for the Claude Desktop config file:
|
|
98
|
+
|
|
99
|
+
- MacOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
100
|
+
- Windows: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
101
|
+
|
|
102
|
+
### Usage with Claude Code
|
|
103
|
+
|
|
104
|
+
**Client Credentials:**
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
claude mcp add shopify -- npx @klaudworks/shopify-mcp \
|
|
108
|
+
--clientId YOUR_CLIENT_ID \
|
|
109
|
+
--clientSecret YOUR_CLIENT_SECRET \
|
|
110
|
+
--domain your-store.myshopify.com
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Static Access Token (legacy):**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
claude mcp add shopify -- npx @klaudworks/shopify-mcp \
|
|
117
|
+
--accessToken YOUR_ACCESS_TOKEN \
|
|
118
|
+
--domain your-store.myshopify.com
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Alternative: Run Locally with Environment Variables
|
|
122
|
+
|
|
123
|
+
If you prefer to use environment variables instead of command-line arguments:
|
|
124
|
+
|
|
125
|
+
1. Create a `.env` file with your Shopify credentials:
|
|
126
|
+
|
|
127
|
+
**Client Credentials:**
|
|
128
|
+
```
|
|
129
|
+
SHOPIFY_CLIENT_ID=your_client_id
|
|
130
|
+
SHOPIFY_CLIENT_SECRET=your_client_secret
|
|
131
|
+
MYSHOPIFY_DOMAIN=your-store.myshopify.com
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**Static Access Token (legacy):**
|
|
135
|
+
```
|
|
136
|
+
SHOPIFY_ACCESS_TOKEN=your_access_token
|
|
137
|
+
MYSHOPIFY_DOMAIN=your-store.myshopify.com
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
2. Run the server with npx:
|
|
141
|
+
```
|
|
142
|
+
npx @klaudworks/shopify-mcp
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Direct Installation (Optional)
|
|
146
|
+
|
|
147
|
+
If you want to install the package globally:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
npm install -g @klaudworks/shopify-mcp
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Then run it:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
shopify-mcp --clientId=<ID> --clientSecret=<SECRET> --domain=<YOUR_SHOP>.myshopify.com
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Additional Options
|
|
160
|
+
|
|
161
|
+
- `--apiVersion`: Specify the Shopify API version (default: `2026-01`). Can also be set via `SHOPIFY_API_VERSION` environment variable.
|
|
162
|
+
|
|
163
|
+
**⚠️ Important:** If you see errors about "SHOPIFY_ACCESS_TOKEN environment variable is required" when using command-line arguments, you might have a different package installed. Make sure you're using `shopify-mcp`, not `shopify-mcp-server`.
|
|
164
|
+
|
|
165
|
+
## Available Tools (31)
|
|
166
|
+
|
|
167
|
+
### Pagination, Sorting & Filtering
|
|
168
|
+
|
|
169
|
+
All list query tools (`get-products`, `get-customers`, `get-orders`, `get-customer-orders`) support:
|
|
170
|
+
|
|
171
|
+
- **Cursor-based pagination**: `after` / `before` (cursor strings), with `pageInfo` in the response (`hasNextPage`, `hasPreviousPage`, `startCursor`, `endCursor`)
|
|
172
|
+
- **Sorting**: `sortKey` (enum specific to each resource) and `reverse` (boolean)
|
|
173
|
+
- **Advanced filtering**: `query` or `searchQuery` parameter accepting [Shopify query syntax](https://shopify.dev/docs/api/usage/search-syntax)
|
|
174
|
+
|
|
175
|
+
### Product Management (8 tools)
|
|
176
|
+
|
|
177
|
+
1. **`get-products`**
|
|
178
|
+
|
|
179
|
+
- Get all products or search by title with pagination and sorting
|
|
180
|
+
- Inputs:
|
|
181
|
+
- `searchTitle` (string, optional): Filter products by title (wraps in `title:*...*`)
|
|
182
|
+
- `limit` (number, default: 10): Maximum number of products to return
|
|
183
|
+
- `query` (string, optional): Raw Shopify query string (e.g. `"status:active vendor:Nike tag:sale"`)
|
|
184
|
+
- `sortKey` (string, optional): One of `CREATED_AT`, `ID`, `INVENTORY_TOTAL`, `PRODUCT_TYPE`, `PUBLISHED_AT`, `RELEVANCE`, `TITLE`, `UPDATED_AT`, `VENDOR`
|
|
185
|
+
- `reverse` (boolean, optional): Reverse the sort order
|
|
186
|
+
- `after` / `before` (string, optional): Pagination cursors
|
|
187
|
+
|
|
188
|
+
2. **`get-product-by-id`**
|
|
189
|
+
|
|
190
|
+
- Get a specific product by ID with full details including SEO, options, media, variants, and collections
|
|
191
|
+
- Inputs:
|
|
192
|
+
- `productId` (string, required): Shopify product GID
|
|
193
|
+
- Returns: `productType`, `descriptionHtml`, `seo`, `options` (with `optionValues`), `media` (images), `variants`, `collections`, `tags`, `vendor`, price range, inventory
|
|
194
|
+
|
|
195
|
+
3. **`create-product`**
|
|
196
|
+
|
|
197
|
+
- Create a new product. When using `productOptions`, Shopify registers all option values but only creates one default variant (first value of each option, price $0). Use `manage-product-variants` with `strategy: REMOVE_STANDALONE_VARIANT` afterward to create all real variants with prices.
|
|
198
|
+
- Inputs:
|
|
199
|
+
- `title` (string, required): Title of the product
|
|
200
|
+
- `descriptionHtml` (string, optional): Description with HTML
|
|
201
|
+
- `handle` (string, optional): URL slug. Auto-generated from title if omitted
|
|
202
|
+
- `vendor` (string, optional): Vendor of the product
|
|
203
|
+
- `productType` (string, optional): Type of the product
|
|
204
|
+
- `tags` (array of strings, optional): Product tags
|
|
205
|
+
- `status` (string, optional): `"ACTIVE"`, `"DRAFT"`, or `"ARCHIVED"`. Default `"DRAFT"`
|
|
206
|
+
- `seo` (object, optional): `{ title, description }` for search engines
|
|
207
|
+
- `metafields` (array of objects, optional): Custom metafields (`namespace`, `key`, `value`, `type`)
|
|
208
|
+
- `productOptions` (array of objects, optional): Options to create inline, e.g. `[{ name: "Size", values: [{ name: "S" }, { name: "M" }] }]`. Max 3 options.
|
|
209
|
+
- `collectionsToJoin` (array of strings, optional): Collection GIDs to add the product to
|
|
210
|
+
|
|
211
|
+
4. **`update-product`**
|
|
212
|
+
|
|
213
|
+
- Update an existing product's fields
|
|
214
|
+
- Inputs:
|
|
215
|
+
- `id` (string, required): Shopify product GID
|
|
216
|
+
- `title` (string, optional): New title
|
|
217
|
+
- `descriptionHtml` (string, optional): New description
|
|
218
|
+
- `handle` (string, optional): New URL slug
|
|
219
|
+
- `vendor` (string, optional): New vendor
|
|
220
|
+
- `productType` (string, optional): New product type
|
|
221
|
+
- `tags` (array of strings, optional): New tags (overwrites existing)
|
|
222
|
+
- `status` (string, optional): `"ACTIVE"`, `"DRAFT"`, or `"ARCHIVED"`
|
|
223
|
+
- `seo` (object, optional): `{ title, description }` for search engines
|
|
224
|
+
- `metafields` (array of objects, optional): Metafields to set or update
|
|
225
|
+
- `collectionsToJoin` (array of strings, optional): Collection GIDs to add the product to
|
|
226
|
+
- `collectionsToLeave` (array of strings, optional): Collection GIDs to remove the product from
|
|
227
|
+
- `redirectNewHandle` (boolean, optional): If true, old handle redirects to new handle
|
|
228
|
+
|
|
229
|
+
5. **`delete-product`**
|
|
230
|
+
|
|
231
|
+
- Delete a product
|
|
232
|
+
- Inputs:
|
|
233
|
+
- `id` (string, required): Shopify product GID
|
|
234
|
+
|
|
235
|
+
6. **`manage-product-options`**
|
|
236
|
+
|
|
237
|
+
- Create, update, or delete product options (e.g. Size, Color)
|
|
238
|
+
- Inputs:
|
|
239
|
+
- `productId` (string, required): Shopify product GID
|
|
240
|
+
- `action` (string, required): `"create"`, `"update"`, or `"delete"`
|
|
241
|
+
- `variantStrategy` (string, optional): `"LEAVE_AS_IS"` (default) or `"CREATE"` — controls whether new variant combinations are generated when adding options
|
|
242
|
+
- For `action: "create"`:
|
|
243
|
+
- `options` (array, required): Options to create, e.g. `[{ name: "Size", values: ["S", "M", "L"] }]`
|
|
244
|
+
- For `action: "update"`:
|
|
245
|
+
- `optionId` (string, required): Option GID to update
|
|
246
|
+
- `name` (string, optional): New name for the option
|
|
247
|
+
- `position` (number, optional): New position
|
|
248
|
+
- `valuesToAdd` (array of strings, optional): Values to add
|
|
249
|
+
- `valuesToDelete` (array of strings, optional): Value GIDs to remove
|
|
250
|
+
- For `action: "delete"`:
|
|
251
|
+
- `optionIds` (array of strings, required): Option GIDs to delete
|
|
252
|
+
|
|
253
|
+
7. **`manage-product-variants`**
|
|
254
|
+
|
|
255
|
+
- Create or update product variants in bulk
|
|
256
|
+
- Inputs:
|
|
257
|
+
- `productId` (string, required): Shopify product GID
|
|
258
|
+
- `strategy` (string, optional): How to handle the default variant when creating. `"DEFAULT"` (removes "Default Title" automatically), `"REMOVE_STANDALONE_VARIANT"` (recommended for full control), or `"PRESERVE_STANDALONE_VARIANT"`
|
|
259
|
+
- `variants` (array, required): Variants to create or update. Each variant:
|
|
260
|
+
- `id` (string, optional): Variant GID for updates. Omit to create new
|
|
261
|
+
- `price` (string, optional): Price, e.g. `"49.00"`
|
|
262
|
+
- `compareAtPrice` (string, optional): Compare-at price for showing discounts
|
|
263
|
+
- `sku` (string, optional): SKU (mapped to `inventoryItem.sku`)
|
|
264
|
+
- `tracked` (boolean, optional): Whether inventory is tracked. Set `false` for print-on-demand
|
|
265
|
+
- `taxable` (boolean, optional): Whether the variant is taxable
|
|
266
|
+
- `barcode` (string, optional): Barcode
|
|
267
|
+
- `weight` (number, optional): Weight of the variant
|
|
268
|
+
- `weightUnit` (string, optional): `"GRAMS"`, `"KILOGRAMS"`, `"OUNCES"`, or `"POUNDS"`
|
|
269
|
+
- `optionValues` (array, optional): Option values, e.g. `[{ optionName: "Size", name: "A4" }]`
|
|
270
|
+
|
|
271
|
+
8. **`delete-product-variants`**
|
|
272
|
+
|
|
273
|
+
- Delete one or more variants from a product
|
|
274
|
+
- Inputs:
|
|
275
|
+
- `productId` (string, required): Shopify product GID
|
|
276
|
+
- `variantIds` (array of strings, required): Variant GIDs to delete
|
|
277
|
+
|
|
278
|
+
### Customer Management (8 tools)
|
|
279
|
+
|
|
280
|
+
1. **`get-customers`**
|
|
281
|
+
|
|
282
|
+
- List customers with search, pagination, and sorting
|
|
283
|
+
- Inputs:
|
|
284
|
+
- `searchQuery` (string, optional): Freetext or Shopify query syntax (e.g. `"country:US tag:vip orders_count:>5"`)
|
|
285
|
+
- `limit` (number, default: 10): Maximum number of customers to return
|
|
286
|
+
- `sortKey` (string, optional): One of `CREATED_AT`, `ID`, `LAST_UPDATE`, `LOCATION`, `NAME`, `ORDERS_COUNT`, `RELEVANCE`, `TOTAL_SPENT`, `UPDATED_AT`
|
|
287
|
+
- `reverse` (boolean, optional): Reverse the sort order
|
|
288
|
+
- `after` / `before` (string, optional): Pagination cursors
|
|
289
|
+
|
|
290
|
+
2. **`get-customer-by-id`**
|
|
291
|
+
|
|
292
|
+
- Get a single customer by ID with full details
|
|
293
|
+
- Inputs:
|
|
294
|
+
- `id` (string, required): Shopify customer ID (numeric only, e.g. `"6276879810626"`)
|
|
295
|
+
- Returns: name, email, phone, addresses, tags, note, tax status, amount spent, order count, metafields
|
|
296
|
+
|
|
297
|
+
3. **`create-customer`**
|
|
298
|
+
|
|
299
|
+
- Create a new customer
|
|
300
|
+
- Inputs:
|
|
301
|
+
- `firstName` (string, optional): Customer's first name
|
|
302
|
+
- `lastName` (string, optional): Customer's last name
|
|
303
|
+
- `email` (string, optional): Customer's email address
|
|
304
|
+
- `phone` (string, optional): Customer's phone number
|
|
305
|
+
- `tags` (array of strings, optional): Tags to apply
|
|
306
|
+
- `note` (string, optional): Note about the customer
|
|
307
|
+
- `taxExempt` (boolean, optional): Whether the customer is exempt from taxes
|
|
308
|
+
- `metafields` (array of objects, optional): Custom metafields (`namespace`, `key`, `value`, `type`)
|
|
309
|
+
- `addresses` (array of objects, optional): Customer addresses (`address1`, `address2`, `city`, `provinceCode`, `zip`, `country`, `phone`)
|
|
310
|
+
|
|
311
|
+
4. **`update-customer`**
|
|
312
|
+
|
|
313
|
+
- Update a customer's information
|
|
314
|
+
- Inputs:
|
|
315
|
+
- `id` (string, required): Shopify customer ID (numeric only, e.g. `"6276879810626"`)
|
|
316
|
+
- `firstName` (string, optional): Customer's first name
|
|
317
|
+
- `lastName` (string, optional): Customer's last name
|
|
318
|
+
- `email` (string, optional): Customer's email address
|
|
319
|
+
- `phone` (string, optional): Customer's phone number
|
|
320
|
+
- `tags` (array of strings, optional): Tags to apply to the customer
|
|
321
|
+
- `note` (string, optional): Note about the customer
|
|
322
|
+
- `taxExempt` (boolean, optional): Whether the customer is exempt from taxes
|
|
323
|
+
- `emailMarketingConsent` (object, optional): Email marketing consent settings
|
|
324
|
+
- `marketingState` (string, required): `"NOT_SUBSCRIBED"`, `"SUBSCRIBED"`, `"UNSUBSCRIBED"`, or `"PENDING"`
|
|
325
|
+
- `consentUpdatedAt` (string, optional): ISO 8601 timestamp
|
|
326
|
+
- `marketingOptInLevel` (string, optional): `"SINGLE_OPT_IN"`, `"CONFIRMED_OPT_IN"`, or `"UNKNOWN"`
|
|
327
|
+
- `metafields` (array of objects, optional): Customer metafields
|
|
328
|
+
|
|
329
|
+
5. **`delete-customer`**
|
|
330
|
+
|
|
331
|
+
- Delete a customer
|
|
332
|
+
- Inputs:
|
|
333
|
+
- `id` (string, required): Shopify customer ID (numeric only, e.g. `"6276879810626"`)
|
|
334
|
+
|
|
335
|
+
6. **`customer-merge`**
|
|
336
|
+
|
|
337
|
+
- Merge two customer records into one
|
|
338
|
+
- Inputs:
|
|
339
|
+
- `customerOneId` (string, required): GID of the first customer
|
|
340
|
+
- `customerTwoId` (string, required): GID of the second customer
|
|
341
|
+
- `overrideFields` (object, optional): Override which fields to keep from which customer (firstName, lastName, email, phone, defaultAddress, note, tags)
|
|
342
|
+
|
|
343
|
+
7. **`manage-customer-address`**
|
|
344
|
+
|
|
345
|
+
- Create, update, or delete a customer's mailing address
|
|
346
|
+
- Inputs:
|
|
347
|
+
- `customerId` (string, required): Customer GID
|
|
348
|
+
- `action` (string, required): `"create"`, `"update"`, or `"delete"`
|
|
349
|
+
- `addressId` (string, optional): Address GID (required for update/delete)
|
|
350
|
+
- `address` (object, optional): Address fields (required for create/update): `address1`, `address2`, `city`, `company`, `countryCode`, `firstName`, `lastName`, `phone`, `provinceCode`, `zip`
|
|
351
|
+
- `setAsDefault` (boolean, optional): Set as customer's default address
|
|
352
|
+
|
|
353
|
+
### Order Management (10 tools)
|
|
354
|
+
|
|
355
|
+
1. **`get-orders`**
|
|
356
|
+
|
|
357
|
+
- Get orders with filtering, pagination, and sorting
|
|
358
|
+
- Inputs:
|
|
359
|
+
- `status` (string, optional): `"any"`, `"open"`, `"closed"`, or `"cancelled"`. Default `"any"`
|
|
360
|
+
- `limit` (number, default: 10): Maximum number of orders to return
|
|
361
|
+
- `query` (string, optional): Raw Shopify query string (e.g. `"financial_status:paid fulfillment_status:shipped tag:rush"`)
|
|
362
|
+
- `sortKey` (string, optional): One of `CREATED_AT`, `ORDER_NUMBER`, `TOTAL_PRICE`, `FINANCIAL_STATUS`, `FULFILLMENT_STATUS`, `UPDATED_AT`, `CUSTOMER_NAME`, `PROCESSED_AT`, `ID`, `RELEVANCE`
|
|
363
|
+
- `reverse` (boolean, optional): Reverse the sort order
|
|
364
|
+
- `after` / `before` (string, optional): Pagination cursors
|
|
365
|
+
|
|
366
|
+
2. **`get-order-by-id`**
|
|
367
|
+
|
|
368
|
+
- Get a specific order by ID with smart lookup — accepts order name (`#77235` or `77235`), numeric ID (`8054938337547`), or full GID (`gid://shopify/Order/...`)
|
|
369
|
+
- Inputs:
|
|
370
|
+
- `orderId` (string, required): Order name, numeric ID, or full GID
|
|
371
|
+
- Returns: pricing, customer, shipping/billing addresses, line items, tags, notes, metafields, cancel reason, return status, discount codes, PO number, timestamps
|
|
372
|
+
|
|
373
|
+
3. **`update-order`**
|
|
374
|
+
|
|
375
|
+
- Update an existing order
|
|
376
|
+
- Inputs:
|
|
377
|
+
- `id` (string, required): Shopify order GID
|
|
378
|
+
- `tags` (array of strings, optional): New tags for the order
|
|
379
|
+
- `email` (string, optional): Update customer email on the order
|
|
380
|
+
- `note` (string, optional): Order notes
|
|
381
|
+
- `phone` (string, optional): Phone number for the order
|
|
382
|
+
- `poNumber` (string, optional): Purchase order number
|
|
383
|
+
- `customAttributes` (array of objects, optional): Custom key-value attributes
|
|
384
|
+
- `metafields` (array of objects, optional): Order metafields
|
|
385
|
+
- `shippingAddress` (object, optional): Shipping address fields
|
|
386
|
+
|
|
387
|
+
4. **`get-customer-orders`**
|
|
388
|
+
|
|
389
|
+
- Get orders for a specific customer with pagination and sorting
|
|
390
|
+
- Inputs:
|
|
391
|
+
- `customerId` (string, required): Shopify customer ID (numeric only, e.g. `"6276879810626"`)
|
|
392
|
+
- `limit` (number, default: 10): Maximum number of orders to return
|
|
393
|
+
- `sortKey` (string, optional): Same sort keys as `get-orders`
|
|
394
|
+
- `reverse` (boolean, optional): Reverse the sort order
|
|
395
|
+
- `after` / `before` (string, optional): Pagination cursors
|
|
396
|
+
|
|
397
|
+
5. **`order-cancel`**
|
|
398
|
+
|
|
399
|
+
- Cancel an order with options for refunding, restocking, and customer notification. **Irreversible.**
|
|
400
|
+
- Inputs:
|
|
401
|
+
- `orderId` (string, required): Order GID
|
|
402
|
+
- `reason` (string, required): `"CUSTOMER"`, `"DECLINED"`, `"FRAUD"`, `"INVENTORY"`, `"OTHER"`, or `"STAFF"`
|
|
403
|
+
- `restock` (boolean, required): Whether to restock inventory
|
|
404
|
+
- `notifyCustomer` (boolean, default: false): Notify the customer
|
|
405
|
+
- `staffNote` (string, optional): Internal note
|
|
406
|
+
- `refund` (boolean, optional): Refund to original payment method
|
|
407
|
+
|
|
408
|
+
6. **`order-close-open`**
|
|
409
|
+
|
|
410
|
+
- Close or reopen an order
|
|
411
|
+
- Inputs:
|
|
412
|
+
- `orderId` (string, required): Order GID
|
|
413
|
+
- `action` (string, required): `"close"` or `"open"`
|
|
414
|
+
|
|
415
|
+
7. **`order-mark-as-paid`**
|
|
416
|
+
|
|
417
|
+
- Mark an order as paid (for manual/offline payments)
|
|
418
|
+
- Inputs:
|
|
419
|
+
- `orderId` (string, required): Order GID
|
|
420
|
+
|
|
421
|
+
8. **`create-fulfillment`**
|
|
422
|
+
|
|
423
|
+
- Create a fulfillment (mark items as shipped) with optional tracking
|
|
424
|
+
- Inputs:
|
|
425
|
+
- `lineItemsByFulfillmentOrder` (array, required): Fulfillment orders and line items to fulfill
|
|
426
|
+
- `trackingInfo` (object, optional): `{ number, url, company }` tracking details
|
|
427
|
+
- `notifyCustomer` (boolean, default: false): Send shipping notification
|
|
428
|
+
|
|
429
|
+
9. **`refund-create`**
|
|
430
|
+
|
|
431
|
+
- Create a full or partial refund with optional restocking
|
|
432
|
+
- Inputs:
|
|
433
|
+
- `orderId` (string, required): Order GID
|
|
434
|
+
- `refundLineItems` (array, optional): Line items to refund with `lineItemId`, `quantity`, `restockType` (`CANCEL`/`RETURN`/`NO_RESTOCK`), `locationId`
|
|
435
|
+
- `shipping` (object, optional): `{ amount, fullRefund }` shipping refund
|
|
436
|
+
- `note` (string, optional): Refund note
|
|
437
|
+
- `notify` (boolean, optional): Send refund notification
|
|
438
|
+
|
|
439
|
+
10. **`create-draft-order`**
|
|
440
|
+
|
|
441
|
+
- Create a draft order for phone/chat sales, invoicing, or wholesale
|
|
442
|
+
- Inputs:
|
|
443
|
+
- `lineItems` (array, required): Product variants (`variantId`) or custom items (`title` + price). Max 499
|
|
444
|
+
- `customerId` (string, optional): Customer GID
|
|
445
|
+
- `email`, `phone`, `note`, `tags`, `poNumber` (optional)
|
|
446
|
+
- `shippingAddress`, `billingAddress` (objects, optional)
|
|
447
|
+
- `appliedDiscount` (object, optional): `{ title, value, valueType }` order-level discount
|
|
448
|
+
|
|
449
|
+
### Draft Order Management (1 tool)
|
|
450
|
+
|
|
451
|
+
1. **`complete-draft-order`**
|
|
452
|
+
|
|
453
|
+
- Complete a draft order, converting it into a real order
|
|
454
|
+
- Inputs:
|
|
455
|
+
- `draftOrderId` (string, required): Draft order GID
|
|
456
|
+
- `paymentGatewayId` (string, optional): Payment gateway GID
|
|
457
|
+
|
|
458
|
+
### Metafield Management (3 tools)
|
|
459
|
+
|
|
460
|
+
1. **`get-metafields`**
|
|
461
|
+
|
|
462
|
+
- Get metafields for any Shopify resource (products, orders, customers, variants, collections, etc.)
|
|
463
|
+
- Inputs:
|
|
464
|
+
- `ownerId` (string, required): GID of any resource
|
|
465
|
+
- `namespace` (string, optional): Filter by namespace
|
|
466
|
+
- `first` (number, default: 25): Number of metafields to return
|
|
467
|
+
- `after` (string, optional): Pagination cursor
|
|
468
|
+
|
|
469
|
+
2. **`set-metafields`**
|
|
470
|
+
|
|
471
|
+
- Set metafields on any Shopify resource. Creates or updates up to 25 metafields atomically
|
|
472
|
+
- Inputs:
|
|
473
|
+
- `metafields` (array, required): Metafields to set, each with `ownerId`, `key`, `value`, and optional `namespace`, `type`
|
|
474
|
+
|
|
475
|
+
3. **`delete-metafields`**
|
|
476
|
+
|
|
477
|
+
- Delete metafields from any Shopify resource
|
|
478
|
+
- Inputs:
|
|
479
|
+
- `metafields` (array, required): Metafields to delete, each with `ownerId`, `namespace`, `key`
|
|
480
|
+
|
|
481
|
+
### Inventory Management (1 tool)
|
|
482
|
+
|
|
483
|
+
1. **`inventory-set-quantities`**
|
|
484
|
+
|
|
485
|
+
- Set absolute inventory quantities for items at specific locations
|
|
486
|
+
- Inputs:
|
|
487
|
+
- `reason` (string, required): Reason for change (e.g. `"correction"`, `"cycle_count_available"`)
|
|
488
|
+
- `name` (string, required): `"available"` or `"on_hand"`
|
|
489
|
+
- `quantities` (array, required): Items with `inventoryItemId`, `locationId`, `quantity`
|
|
490
|
+
|
|
491
|
+
### Tag Management (1 tool)
|
|
492
|
+
|
|
493
|
+
1. **`manage-tags`**
|
|
494
|
+
|
|
495
|
+
- Add or remove tags on any taggable resource (orders, products, customers, draft orders, articles)
|
|
496
|
+
- Inputs:
|
|
497
|
+
- `id` (string, required): GID of the resource
|
|
498
|
+
- `tags` (array of strings, required): Tags to add or remove
|
|
499
|
+
- `action` (string, required): `"add"` or `"remove"`
|
|
500
|
+
|
|
501
|
+
### Order Query Filter Reference
|
|
502
|
+
|
|
503
|
+
The `get-orders` tool's `query` parameter supports [Shopify search syntax](https://shopify.dev/docs/api/usage/search-syntax):
|
|
504
|
+
|
|
505
|
+
| Filter | Example |
|
|
506
|
+
|--------|---------|
|
|
507
|
+
| `name` | `name:#77235` |
|
|
508
|
+
| `created_at` | `created_at:>2024-01-01` or `created_at:2024-01-01..2024-03-31` |
|
|
509
|
+
| `updated_at` | `updated_at:>2024-06-01` |
|
|
510
|
+
| `financial_status` | `financial_status:paid` |
|
|
511
|
+
| `fulfillment_status` | `fulfillment_status:shipped` |
|
|
512
|
+
| `status` | `status:open` |
|
|
513
|
+
| `email` | `email:customer@example.com` |
|
|
514
|
+
| `tag` / `tag_not` | `tag:vip tag_not:wholesale` |
|
|
515
|
+
| `discount_code` | `discount_code:SUMMER20` |
|
|
516
|
+
| `sku` | `sku:PROD-001` |
|
|
517
|
+
| `risk_level` | `risk_level:high` |
|
|
518
|
+
| `gateway` | `gateway:shopify_payments` |
|
|
519
|
+
| `test` | `test:true` |
|
|
520
|
+
|
|
521
|
+
## Debugging
|
|
522
|
+
|
|
523
|
+
If you encounter issues, check Claude Desktop's MCP logs:
|
|
524
|
+
|
|
525
|
+
```
|
|
526
|
+
tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
## License
|
|
530
|
+
|
|
531
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import dotenv from "dotenv";
|
|
5
|
+
import { GraphQLClient } from "graphql-request";
|
|
6
|
+
import minimist from "minimist";
|
|
7
|
+
import { ShopifyAuth } from "./lib/shopifyAuth.js";
|
|
8
|
+
import { tools } from "./tools/registry.js";
|
|
9
|
+
// Parse command line arguments
|
|
10
|
+
const argv = minimist(process.argv.slice(2));
|
|
11
|
+
// Load environment variables from .env file (if it exists)
|
|
12
|
+
dotenv.config();
|
|
13
|
+
// Define environment variables - from command line or .env file
|
|
14
|
+
const SHOPIFY_ACCESS_TOKEN = argv.accessToken || process.env.SHOPIFY_ACCESS_TOKEN;
|
|
15
|
+
const SHOPIFY_CLIENT_ID = argv.clientId || process.env.SHOPIFY_CLIENT_ID;
|
|
16
|
+
const SHOPIFY_CLIENT_SECRET = argv.clientSecret || process.env.SHOPIFY_CLIENT_SECRET;
|
|
17
|
+
const RAW_DOMAIN = argv.domain || process.env.MYSHOPIFY_DOMAIN;
|
|
18
|
+
const useClientCredentials = !!(SHOPIFY_CLIENT_ID && SHOPIFY_CLIENT_SECRET);
|
|
19
|
+
// Validate required environment variables
|
|
20
|
+
if (!SHOPIFY_ACCESS_TOKEN && !useClientCredentials) {
|
|
21
|
+
console.error("Error: Authentication credentials are required.");
|
|
22
|
+
console.error("");
|
|
23
|
+
console.error("Option 1 — Static access token (legacy apps):");
|
|
24
|
+
console.error(" --accessToken=shpat_xxxxx");
|
|
25
|
+
console.error("");
|
|
26
|
+
console.error("Option 2 — Client credentials (Dev Dashboard apps, Jan 2026+):");
|
|
27
|
+
console.error(" --clientId=your_client_id --clientSecret=your_client_secret");
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}
|
|
30
|
+
if (!RAW_DOMAIN) {
|
|
31
|
+
console.error("Error: MYSHOPIFY_DOMAIN is required.");
|
|
32
|
+
console.error("Please provide it via command line argument or .env file.");
|
|
33
|
+
console.error(" Command line: --domain=your-store.myshopify.com");
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
// Normalize and strictly validate the shop domain before it is ever used to
|
|
37
|
+
// build request URLs. The access token — and the client secret, during the
|
|
38
|
+
// OAuth token exchange — is sent to this host, so it must be a genuine Shopify
|
|
39
|
+
// *.myshopify.com domain, never an attacker-supplied host, scheme, or path.
|
|
40
|
+
const MYSHOPIFY_DOMAIN = String(RAW_DOMAIN)
|
|
41
|
+
.trim()
|
|
42
|
+
.replace(/^https?:\/\//i, "")
|
|
43
|
+
.replace(/\/+$/, "");
|
|
44
|
+
if (!/^[a-z0-9][a-z0-9-]*\.myshopify\.com$/i.test(MYSHOPIFY_DOMAIN)) {
|
|
45
|
+
console.error(`Error: invalid shop domain "${RAW_DOMAIN}".`);
|
|
46
|
+
console.error("Expected a bare myshopify.com host, e.g. your-store.myshopify.com");
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
// Resolve access token (client credentials or static)
|
|
50
|
+
let accessToken;
|
|
51
|
+
let auth = null;
|
|
52
|
+
if (useClientCredentials) {
|
|
53
|
+
auth = new ShopifyAuth({
|
|
54
|
+
clientId: SHOPIFY_CLIENT_ID,
|
|
55
|
+
clientSecret: SHOPIFY_CLIENT_SECRET,
|
|
56
|
+
shopDomain: MYSHOPIFY_DOMAIN,
|
|
57
|
+
});
|
|
58
|
+
accessToken = await auth.initialize();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
accessToken = SHOPIFY_ACCESS_TOKEN;
|
|
62
|
+
}
|
|
63
|
+
// Create Shopify GraphQL client
|
|
64
|
+
const API_VERSION = argv.apiVersion || process.env.SHOPIFY_API_VERSION || "2026-01";
|
|
65
|
+
const shopifyClient = new GraphQLClient(`https://${MYSHOPIFY_DOMAIN}/admin/api/${API_VERSION}/graphql.json`, {
|
|
66
|
+
headers: {
|
|
67
|
+
"X-Shopify-Access-Token": accessToken,
|
|
68
|
+
"Content-Type": "application/json"
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
// Let the auth manager hot-swap the token header on refresh
|
|
72
|
+
if (auth) {
|
|
73
|
+
auth.setGraphQLClient(shopifyClient);
|
|
74
|
+
}
|
|
75
|
+
// Initialize all tools with the shared GraphQL client
|
|
76
|
+
for (const tool of tools) {
|
|
77
|
+
tool.initialize(shopifyClient);
|
|
78
|
+
}
|
|
79
|
+
// Set up MCP server
|
|
80
|
+
const server = new McpServer({
|
|
81
|
+
name: "shopify",
|
|
82
|
+
version: "1.0.0",
|
|
83
|
+
description: "MCP Server for Shopify API, enabling interaction with store data through GraphQL API"
|
|
84
|
+
});
|
|
85
|
+
// Register all tools with the MCP server.
|
|
86
|
+
// NOTE: server.tool()'s generics try to deeply infer each Zod shape; across our
|
|
87
|
+
// heterogeneous tool array that exceeds TS's instantiation depth (TS2589). The
|
|
88
|
+
// shape is still validated by the SDK at runtime — we only widen the
|
|
89
|
+
// compile-time type at this single boundary.
|
|
90
|
+
for (const tool of tools) {
|
|
91
|
+
server.tool(tool.name,
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
+
tool.schema.shape, async (args) => {
|
|
94
|
+
const result = await tool.execute(args);
|
|
95
|
+
return {
|
|
96
|
+
content: [{ type: "text", text: JSON.stringify(result) }]
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Start the server
|
|
101
|
+
const transport = new StdioServerTransport();
|
|
102
|
+
server
|
|
103
|
+
.connect(transport)
|
|
104
|
+
.then(() => { })
|
|
105
|
+
.catch((error) => {
|
|
106
|
+
console.error("Failed to start Shopify MCP Server:", error);
|
|
107
|
+
});
|