หากต้องการระบุ Storefront MCP Server กับ OpenAI Responses API

ฟังก์ชั่นนี้จะพาคุณผ่านขั้นตอนต่างๆ มากมายและเทียบเท่า Shopify Storefront MCP Server กับ OpenAI Responses API แบบละเอียดแต่ละขั้นตอนที่แปลกประหลาดเริ่มต้น

📋 ก่อนอื่นต้องเตรียม

1. บัญชีและคีย์ API

  • ✅ บัญชี Shopify ที่เป็นอยู่
  • ✅ โทเค็นการเข้าถึง API ของหน้าร้าน
  • ✅ คีย์ OpenAI API (สมัครได้ที่ platform.openai.com )

2.เทคโนโลยีพัฒนา

  • Node.js ขึ้นไป 18.0.0 ขึ้นไป
  • npm หรือ yarn
  • โปรแกรมแก้ไขข้อความ (แนะนำ VS Code)
  • เทอร์มินัล หรือ Command Line

🔑 ขั้นตอนที่ 1: สร้างโทเค็นการเข้าถึง API หน้าร้าน

1.1 เข้าสู่ผู้ดูแลระบบ Shopify

  1. เข้าสู่ระบบ Shopify Admin ของคุณ
  2. ไปที่ การตั้งค่าแอพและช่องทางการขาย
  3. คลิก พัฒนาแอพ

1.2 สร้างแอปที่กำหนดเอง

  1. คลิก สร้างแอป
  2. แอปตรวจสอบ แปลว่า \"เซิร์ฟเวอร์ MCP หน้าร้าน\"
  3. คลิก Create app

1.3 กำหนดสิทธิ์ API หน้าร้าน

  1. ในส่วนของ การกำหนดค่า
  2. ใช่ API หน้าร้าน คลิก กำหนดค่า
  3. สิทธิ์ในการฟัง:
    • ✅ รายการผลิตภัณฑ์ unauthenticated_read_product_listings
    • ✅ สินค้า unauthenticated_read_product_inventory ตรวจสอบ
    • unauthenticated_write_checkouts
    • ✅ การอ่าน unauthenticated_read_checkouts ตรวจสอบสิทธิ์
  4. คลิก Save

1.4 สร้างโทเค็นการเข้าถึง

  1. ไปที่ ข้อมูลรับรอง API
  2. ใช่ โทเค็นการเข้าถึง API หน้าร้าน คลิก ติดตั้งแอป
  3. เรื่อง โทเค็นการเข้าถึง API หน้าร้าน และข้อมูลต่างๆ
 ตัวอย่าง Token:shpat_1234567890abcdefghijklmnopqrstuvwxyz

🤖 พาร์ท 2: สร้างคีย์ OpenAI API

2.1 สมัครบัญชี OpenAI

  1. ไปที่ platform.openai.com/signup
  2. สมัครบัญชีหรือเข้าสู่ระบบ
  3. เติมเครดิตในบัญชี (ขั้นต่ำ $5)

2.2 สร้าง API Key

  1. ไปที่ API Keys
  2. คลิก สร้างรหัสลับใหม่
  3. คีย์การเปิดใช้งาน = \"Shopify MCP Server\"
  4. เอกสาร API และนี่คือข้อมูล (ในวันนี้)
 ตัวอย่าง API Key:sk-proj-1234567890abcdefghijklmnopqrstuvwxyz

💻 ตัวกรอง 3: และติดตั้งโปรเจกต์

3.1 สร้างโปรเจกต์ใหม่

 # สร้างโฟลเดอร์โปรเจกต์mkdir shopify-mcp-servercd shopify-mcp-server# เริ่มต้นโปรเจกต์ Node.jsnpm init -y

3.2 การพึ่งพาอาศัยกัน

 npm install @shopify/storefront-mcp-server openai dotenv

3.3 สร้างไฟล์ .env

สร้างไฟล์ .env ในโปรเจกต์:

# Shopify ConfigurationSHOPIFY_STORE_DOMAIN=your-store.myshopify.comSHOPIFY_STOREFRONT_ACCESS_TOKEN=shpat_your_token_here# OpenAI ConfigurationOPENAI_API_KEY=sk-proj-your_key_here# Optional: Server ConfigurationPORT=3000NODE_ENV=development

⚠️ สำคัญ: ค่าความสูงที่เพิ่มขึ้นด้วยข้อมูลจริงของคุณ:

  • your-store.myshopify.com → ชื่อร้านของคุณ
  • shpat_your_token_here → โทเค็น API หน้าร้านที่สถานที่ไว้
  • sk-proj-your_key_here → คีย์ OpenAI API ที่เนื้อหาไว้

3.4 สร้างไฟล์ .gitignore

 # .gitignorenode_modules/.env.DS_Store*.log

ดำเนินการ 4: เขียนโค้ดตามลำดับ

4.1 สร้างไฟล์ config.js

// config.jsimport dotenv from 'dotenv';dotenv.config();// ตรวจสอบว่ามี environment variables ครบถ้วนconst requiredEnvVars = [ 'SHOPIFY_STORE_DOMAIN', 'SHOPIFY_STOREFRONT_ACCESS_TOKEN', 'OPENAI_API_KEY'];requiredEnvVars.forEach(varName => { if (!process.env[varName]) { throw new Error(`❌ Missing required environment variable: ${varName}`); }} );export const config = { shopify: { storeDomain: process.env.SHOPIFY_STORE_DOMAIN, storefrontAccessToken: process.env.SHOPIFY_STOREFRONT_ACCESS_TOKEN }, openai: { apiKey: process.env.OPENAI_API_KEY }, server: { port: process.env.PORT || 3000, env: process.env.NODE_ENV || 'development' }} ;console.log('✅ Configuration loaded successfully');

4.2 สร้างไฟล์ server.js

// server.jsimport { StorefrontMCPServer } from '@shopify/storefront-mcp-server';import OpenAI from 'openai';import { config } from './config.js';class ShopifyMCPServer {  constructor() {    console.log('🚀 Initializing Shopify MCP Server...');    // สร้าง MCP Server instance    this.mcpServer = new StorefrontMCPServer({      storeDomain: config.shopify.storeDomain,      storefrontAccessToken: config.shopify.storefrontAccessToken    });    // สร้าง OpenAI instance    this.openai = new OpenAI({      apiKey: config.openai.apiKey    });    console.log('✅ Server initialized successfully');  }  async testConnection() {    try {      console.log('🔍 Testing Shopify connection...');      // ทดสอบการเชื่อมต่อกับ Shopify      const shop = await this.mcpServer.getShop();      console.log('✅ Connected to shop:', shop.name);      // ทดสอบการเชื่อมต่อกับ OpenAI      console.log('🔍 Testing OpenAI connection...');      const completion = await this.openai.chat.completions.create({        model: 'gpt-3.5-turbo',        messages: [{ role: 'user', content: 'Hello' }],        max_tokens: 5      });      console.log('✅ OpenAI connection successful');      return true;    } catch (error) {      console.error('❌ Connection test failed:', error.message);      return false;    }  }  async start() {    console.log('\\n🎯 Starting Shopify MCP Server...');    const isConnected = await this.testConnection();    if (isConnected) {      console.log('\\n✨ Server is ready!');      console.log('📍 Store:', config.shopify.storeDomain);      console.log('🤖 OpenAI: Connected');      console.log('\\n💡 You can now use the MCP Server with OpenAI Responses API');    } else {      console.error('\\n❌ Server failed to start. Please check your configuration.');      process.exit(1);    }  }}// เริ่มต้น serverconst server = new ShopifyMCPServer();server.start().catch(console.error);export default ShopifyMCPServer;

4.3 อัปเดตแพ็คเกจ.json

ไม่สามารถ \"type\": \"module\" ใน package.json:

 { \"name\": \"shopify-mcp-server\", \"version\": \"1.0.0\", \"type\": \"module\", \"main\": \"server.js\", \"scripts\": { \"start\": \"node server.js\", \"dev\": \"node --watch server.js\