Skip to main content

MCP 整合模式

本指南涵蓋在正式環境 Shopify 工作流程中使用 MCP 伺服器的進階模式。從單伺服器設定到複雜的多伺服器協調、CI/CD 整合和自動化資料管線。


模式 1:單伺服器設定

最簡單的模式。一個 MCP 伺服器處理所有互動。

┌──────────┐          ┌───────────────┐          ┌─────────────┐
│ AI Client │ ──MCP──► │ shopify-mcp │ ──API──► │ Shopify Store│
│ │ │ (GeLi2001) │ │ │
└──────────┘ └───────────────┘ └─────────────┘

適用時機:

  • 單一商店管理
  • 開始使用 MCP
  • 簡單的自動化任務

設定:

{
"mcpServers": {
"shopify": {
"command": "npx",
"args": ["-y", "shopify-mcp@latest"],
"env": {
"SHOPIFY_ACCESS_TOKEN": "shpat_xxxxxxxxxxxxx",
"MYSHOPIFY_DOMAIN": "my-store.myshopify.com"
}
}
}
}

限制:

  • 無法存取文件(僅有即時商店資料)
  • 無法根據 API schema 進行驗證
  • 單點故障

模式 2:雙伺服器(文件 + 商店)

大多數開發者的推薦模式。結合文件智慧與商店管理。

┌──────────┐     ┌───────────────────┐
│ │────►│ Shopify Dev MCP │──► Docs, Schemas, Liquid
│ AI Client │ └───────────────────┘
│ │ ┌───────────────────┐
│ │────►│ Shopify Store MCP │──► Products, Orders, etc.
└──────────┘ └───────────────────┘

適用時機:

  • 日常 Shopify 開發
  • 在管理商店的同時建構應用程式
  • 學習 Shopify 平台

設定:

{
"mcpServers": {
"shopify-dev": {
"command": "npx",
"args": ["-y", "@anthropic-ai/shopify-dev-mcp@latest"]
},
"shopify-store": {
"command": "npx",
"args": ["-y", "shopify-mcp@latest"],
"env": {
"SHOPIFY_ACCESS_TOKEN": "shpat_xxxxxxxxxxxxx",
"MYSHOPIFY_DOMAIN": "my-store.myshopify.com"
}
}
}
}

範例工作流程:

Prompt: "I need to add a 'care_instructions' metafield to all products
in the 'Apparel' collection. First, search the docs for the correct
metafield type and mutation. Then execute it on my store."

1. AI uses Dev MCP → search_docs("metafield definitions product")
2. AI uses Dev MCP → explore_api_schema("MetafieldDefinitionInput")
3. AI uses Store MCP → get_collections(type: "custom", title: "Apparel")
4. AI uses Store MCP → get_products(collection_id: "gid://...")
5. AI uses Store MCP → manage_product_metafields(product_id: "...", ...)

模式 3:多商店管理

從單一 AI 工作階段管理多個 Shopify 商店。適用於代理商、加盟體系和擁有地區商店的商家。

┌──────────┐     ┌─────────────────────┐
│ │────►│ Store: US Production │──► us-store.myshopify.com
│ │ └─────────────────────┘
│ AI Client │ ┌─────────────────────┐
│ │────►│ Store: EU Production │──► eu-store.myshopify.com
│ │ └─────────────────────┘
│ │ ┌─────────────────────┐
│ │────►│ Store: Staging │──► staging.myshopify.com
└──────────┘ └─────────────────────┘

設定:

{
"mcpServers": {
"shopify-dev": {
"command": "npx",
"args": ["-y", "@anthropic-ai/shopify-dev-mcp@latest"]
},
"store-us": {
"command": "npx",
"args": ["-y", "shopify-mcp@latest"],
"env": {
"SHOPIFY_ACCESS_TOKEN": "shpat_us_token",
"MYSHOPIFY_DOMAIN": "us-store.myshopify.com"
}
},
"store-eu": {
"command": "npx",
"args": ["-y", "shopify-mcp@latest"],
"env": {
"SHOPIFY_ACCESS_TOKEN": "shpat_eu_token",
"MYSHOPIFY_DOMAIN": "eu-store.myshopify.com"
}
},
"store-staging": {
"command": "npx",
"args": ["-y", "shopify-mcp@latest"],
"env": {
"SHOPIFY_ACCESS_TOKEN": "shpat_staging_token",
"MYSHOPIFY_DOMAIN": "staging-store.myshopify.com"
}
}
}
}

範例工作流程:

Prompt: "Sync the product catalog from the US store to the EU store.
For each product, convert the price from USD to EUR using a 1.08 rate
and update the description to include EU shipping information."

1. AI uses store-us → get_products(limit: 250)
2. For each product:
a. AI converts price * 1.08
b. AI uses store-eu → create_product(...) or update_product(...)
跨商店操作

始終先在暫存環境測試跨商店同步。產品 ID 在不同商店之間不同,因此您必須透過 SKU、handle 或其他唯一識別碼進行比對——而非 GID。


模式 4:Composio 工具路由器

Composio 作為中介層,透過單一 MCP 連線將工具呼叫路由到多個服務。

┌──────────┐     ┌──────────────┐     ┌──────────────┐
│ │ │ │────►│ Shopify Admin │
│ │ │ │ └──────────────┘
│ AI Client │────►│ Composio │ ┌──────────────┐
│ │ │ Tool Router │────►│ Google Sheets │
│ │ │ │ └──────────────┘
└──────────┘ │ │ ┌──────────────┐
│ │────►│ Slack │
└──────────────┘ └──────────────┘

適用時機:

  • 跨多個服務的工作流程
  • 您想要 OAuth 而非原始權杖
  • 具有稽核要求的企業環境

設定:

# Install Composio
pip install composio-core

# Add integrations
composio add shopify
composio add google-sheets
composio add slack

# Optionally filter to only the tools you need
composio actions --app shopify --filter "product,order"

設定:

{
"mcpServers": {
"composio": {
"command": "composio",
"args": ["serve", "--apps", "shopify,google-sheets,slack"]
}
}
}

範例工作流程:

Prompt: "Every morning, pull yesterday's orders from Shopify,
summarize them in a Google Sheet, and post the summary to #sales in Slack."

1. AI uses Composio → shopify.get_orders(created_at_min: yesterday)
2. AI uses Composio → google_sheets.append_rows(spreadsheet_id, data)
3. AI uses Composio → slack.post_message(channel: "#sales", text: summary)

模式 5:CI/CD 與 MCP

將 MCP 伺服器整合到您的持續整合管線中,以便在部署時自動管理商店。

┌──────────┐     ┌──────────┐     ┌──────────────┐     ┌─────────┐
│ Git Push │────►│ CI/CD │────►│ Claude Code │────►│ Shopify │
│ │ │ Pipeline │ │ + MCP Servers │ │ Store │
└──────────┘ └──────────┘ └──────────────┘ └─────────┘

GitHub Actions 範例

name: Shopify Store Sync
on:
push:
branches: [main]
paths:
- 'products/**'
- 'collections/**'

jobs:
sync-store:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code

- name: Configure MCP Servers
run: |
claude mcp add shopify-store \
-e SHOPIFY_ACCESS_TOKEN=${{ secrets.SHOPIFY_ACCESS_TOKEN }} \
-e MYSHOPIFY_DOMAIN=${{ secrets.SHOP_DOMAIN }} \
-- npx -y shopify-mcp@latest

- name: Sync Products
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
run: |
claude -p "Read the product definitions in ./products/
and sync them to the Shopify store. Create new products
that don't exist, update existing ones by SKU match."

CI/CD + MCP 的使用情境

觸發器動作範例
推送到 main同步產品目錄以 Git 中的產品資料作為事實來源
新的 release 標籤更新商店佈景主題 metafield在商店中顯示版本資訊
排程 cron稽核庫存水準每日低庫存警報
PR 合併更新商品系列規則以程式碼定義商品系列
來自 ERP 的 webhook同步庫存變更外部系統整合
CI/CD 中的速率限制

自動化管線可能會快速達到 Shopify 速率限制。請實作:

  • 對 429 回應的指數退避
  • 盡可能使用批次操作
  • 在管線日誌中監控速率限制

模式 6:自動化商店管理

使用 MCP 伺服器搭配排程任務,實現免人工的商店操作。

每日產品稽核

Schedule: Every day at 6:00 AM UTC

Prompt: "Run a product catalog audit:
1. Find all products with no description
2. Find all products with no images
3. Find all products with zero inventory across all locations
4. Find all draft products older than 30 days
5. Generate a summary report with recommendations"

每週價格最佳化

Schedule: Every Monday at 8:00 AM UTC

Prompt: "Analyze the last 7 days of orders:
1. Identify the top 20 best-selling products
2. For products with >90% sell-through, suggest a 10% price increase
3. For products with <10% sell-through and >60 days inventory, suggest a 15% discount
4. Present recommendations -- do NOT auto-apply changes"

庫存補貨警報

Schedule: Every 4 hours

Prompt: "Check inventory levels across all locations:
1. Find variants with quantity below their reorder point (stored in metafield 'custom.reorder_point')
2. Calculate recommended reorder quantity
3. Generate a reorder list grouped by vendor"

模式 7:資料管線架構

建構將 Shopify 資料流經轉換和分析階段的資料管線。

┌──────────┐     ┌──────────────┐     ┌──────────────┐     ┌──────────┐
│ Shopify │ │ Extract │ │ Transform │ │ Load │
│ Store MCP │────►│ (get_orders, │────►│ (AI-powered │────►│ (Sheets, │
│ │ │ get_products)│ │ analysis) │ │ DB, CSV)│
└──────────┘ └──────────────┘ └──────────────┘ └──────────┘

擷取:從 Shopify 提取資料

Prompt: "Extract all orders from the last 30 days with their line items,
customer data, and fulfillment status. Include calculated fields:
- Order value
- Number of items
- Days since order placed
- Fulfillment delay (days between order and first fulfillment)"

轉換:AI 驅動的分析

Prompt: "Analyze the extracted orders:
1. Customer cohort analysis (new vs returning)
2. Product affinity analysis (frequently bought together)
3. Geographic distribution of orders
4. Average order value trends by week
5. Fulfillment performance by location"

載入:輸出結果

Prompt: "Format the analysis as:
1. A CSV file with the raw data for our data warehouse
2. A summary table for the weekly stakeholder report
3. A list of actionable recommendations"

模式 8:建構自訂 MCP 伺服器

當現有的伺服器無法滿足您的需求時,建構自訂伺服器。

最小自訂伺服器(TypeScript)

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server(
{ name: "my-shopify-tools", version: "1.0.0" },
{ capabilities: { tools: {} } }
);

// Define a custom tool
server.setRequestHandler("tools/list", async () => ({
tools: [
{
name: "calculate_shipping_estimate",
description: "Calculate estimated shipping cost based on weight and destination",
inputSchema: {
type: "object",
properties: {
weight_kg: { type: "number", description: "Package weight in kg" },
destination_country: { type: "string", description: "ISO country code" },
shipping_method: {
type: "string",
enum: ["standard", "express", "overnight"],
description: "Shipping speed"
}
},
required: ["weight_kg", "destination_country"]
}
}
]
}));

// Handle tool execution
server.setRequestHandler("tools/call", async (request) => {
if (request.params.name === "calculate_shipping_estimate") {
const { weight_kg, destination_country, shipping_method } = request.params.arguments;

// Your custom business logic here
const rates = calculateRates(weight_kg, destination_country, shipping_method);

return {
content: [
{
type: "text",
text: JSON.stringify(rates, null, 2)
}
]
};
}
});

// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);

註冊您的自訂伺服器

# Claude Code
claude mcp add my-shopify-tools -- node /path/to/my-server/index.js

# Or with environment variables
claude mcp add my-shopify-tools \
-e SHOPIFY_ACCESS_TOKEN=xxx \
-e CUSTOM_CONFIG=value \
-- node /path/to/my-server/index.js

模式 9:安全優先設定

權杖輪換模式

# Store tokens in a secrets manager, not in config files
# Use a wrapper script that fetches the token at runtime

#!/bin/bash
# start-shopify-mcp.sh
export SHOPIFY_ACCESS_TOKEN=$(aws secretsmanager get-secret-value \
--secret-id shopify/production/api-token \
--query 'SecretString' --output text)
export MYSHOPIFY_DOMAIN="my-store.myshopify.com"

npx -y shopify-mcp@latest
{
"mcpServers": {
"shopify-store": {
"command": "/path/to/start-shopify-mcp.sh"
}
}
}

唯讀正式環境存取

對於正式環境商店,建立僅具有讀取範圍的權杖:

Scopes: read_products, read_orders, read_customers, read_inventory

使用單獨的開發商店權杖進行寫入操作。

稽核日誌

使用日誌代理包裝您的 MCP 伺服器:

// Log every tool call for compliance
server.setRequestHandler("tools/call", async (request) => {
const startTime = Date.now();

// Log the request
await auditLog({
timestamp: new Date().toISOString(),
tool: request.params.name,
arguments: request.params.arguments,
user: process.env.MCP_USER_ID
});

// Execute the actual tool
const result = await executeShopifyTool(request);

// Log the result
await auditLog({
timestamp: new Date().toISOString(),
tool: request.params.name,
duration_ms: Date.now() - startTime,
success: !result.isError
});

return result;
});

選擇正確的模式

模式複雜度最適用於
單伺服器學習、簡單任務
雙伺服器(文件 + 商店)日常開發
多商店代理商、加盟體系
Composio 路由器跨服務工作流程
CI/CD 整合自動化部署
自動化管理排程操作
資料管線分析、報表
自訂伺服器獨特的業務邏輯
安全優先正式環境
從簡單開始,逐步擴展

從模式 2(雙伺服器)開始。當您熟悉 MCP 互動後,隨著工作流程的需求增加複雜度。大多數開發者永遠不需要超過模式 2-3。