GitHub Copilot Coding Agent Playwright MCP 外部主機存取設定教學

4 分鐘閱讀

琳 avatar

when using github coding agent, how to allow playwright MCP to get access to external hosts such as CDN? I don't mind allowing * although it may have security issue. Please guide me do the setup on GitHub.

ChatGPT avatar
ChatGPT

可以的!

重點做法是:在你的 GitHub 儲存庫裡為 Copilot coding agent 加上一個自訂的 Playwright MCP 設定,並在參數裡加上 --allowed-hosts *(或列出你要允許的網域清單),讓瀏覽器可以連到外部主機/ CDN。

下面一步一步帶你在 GitHub 上完成設定。

為 Playwright MCP 開外網存取(含萬用字元)

  1. 到儲存庫設定頁新增 MCP 設定
    在 GitHub 儲存庫的 Settings Copilot Coding agent 頁面,找到 MCP configuration 區塊,貼上這段 JSON,然後儲存: 1
{
  "mcpServers": {
    "playwright": {
      "type": "local",
      "command": "npx",
      "args": ["@playwright/mcp@latest", "--allowed-hosts", "*"],
      "tools": ["*"]
    }
  }
}

說明:

為什麼要自己加這段?因為預設的 Playwright MCP 只看得到 localhost / 127.0.0.1,要連外部主機就要自行加上如上設定。 3

  1. (選用)精準允許特定外站
    如果你不想用萬用字元,而是只開特定 CDN,可以改成:
{
  "mcpServers": {
    "playwright": {
      "type": "local",
      "command": "npx",
      "args": [
        "@playwright/mcp@latest",
        "--allowed-hosts", "cdn.jsdelivr.net,unpkg.com,static.cloudflareinsights.com",
        "--allowed-origins", "https://cdn.jsdelivr.net;https://unpkg.com;https://*.cloudflare.com"
      ],
      "tools": ["*"]
    }
  }
}
  1. 驗證是否生效
    建立一個 Issue 指派給 Copilot,等它開好 PR 之後,點進 View session 檢查「Start MCP Servers」步驟的日誌,應能看到你的 Playwright MCP 工具已啟動。 1

和防火牆、組織政策的關係(重要)


常見加強與除錯

  1. Extending GitHub Copilot coding agent with the Model Context Protocol (MCP) - GitHub Docs ↩2 ↩3

  2. GitHub - microsoft/playwright-mcp: Playwright MCP server ↩2 ↩3 ↩4

  3. Model Context Protocol (MCP) and GitHub Copilot coding agent - GitHub Docs

  4. Customizing or disabling the firewall for GitHub Copilot coding agent - GitHub Docs

  5. Configure MCP server access for your organization or enterprise - GitHub Docs