Showing posts with label mcp. Show all posts
Showing posts with label mcp. Show all posts

Sunday, September 13, 2026

[OpenCode] คู่มือตั้งค่า MCP Server ใน OpenCode ฉบับเข้าใจง่าย

สำหรับสาย Developer ที่เริ่มย้ายมาใช้ OpenCode (AI Coding Assistant ตัวแรง) แล้วอยากเพิ่มเครื่องมือเสริมผ่าน MCP (Model Context Protocol) อาจจะเคยเจอการสั่งงานล้มเหลวเพราะ Copy ค่า Config มาจากตัวอื่น เช่น Claude Code หรือ Cursor ตรงๆ ไม่ได้

สาเหตุเพราะ OpenCode มีรูปแบบการตั้งค่า MCP เฉพาะตัวที่ต่างจากเจ้าอื่น วันนี้เราจะพามาดูจุดแตกต่าง พร้อมโครงสร้างแบบครบๆ ทั้ง Local และ Remote ครับ!


ความแตกต่าง: Standard Format vs OpenCode Format

บอทและ CLI ส่วนใหญ่ (เช่น Claude Code, Cursor) จะใช้ key คำว่า mcpServers และแยกคำสั่งหลักกับ Parameter ออกจากกันใน args:

แบบ Standard (ที่ใช้ใน Cursor / Claude Code):

{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": [
        "@playwright/mcp@latest"
      ]
    }
  }
}

แบบ OpenCode (Local MCP Server):

ใน OpenCode จะเปลี่ยน Key หลักเป็น mcp รวมเอาทั้ง command กับ args มาไว้ใน Array เดียวกัน และต้องระบุประเภทเป็น "type": "local":

{
  "mcp": {
    "playwright": {
      "type": "local",
      "command": ["npx", "-y", "@playwright/mcp@latest"],
      "enabled": true
    }
  }
}