共用方式為


開始使用 Cursor 中的 Azure MCP 伺服器

Azure MCP 伺服器會使用模型內容通訊協定 (MCP) 來標準化 AI 應用程式與外部工具和資料來源之間的整合,讓 AI 系統能夠執行內容感知 Azure 資源的作業。

在本文中,您將瞭解如何完成下列工作:

  • 安裝並驗證 Azure MCP 伺服器
  • 使用 Cursor 的 AI 支援開發環境連線到 Azure MCP 伺服器
  • 執行提示以測試 Azure MCP 伺服器作業並與 Azure 資源互動

先決條件

安裝 Azure MCP 伺服器

若要在游標中安裝和設定 Azure MCP 伺服器:

  1. 導覽至 檔案 > 偏好設定 > 游標設定

  2. 從左側導覽中選取 工具與整合

  3. 在頁面的 MCP 工具 區段中,選取 新增 MCP 伺服器 以開啟 mcp.json 檔案進行編輯。

    螢幕擷取畫面,顯示如何在 Cursor 中設定 MCP 伺服器。

  4. 將下列組態新增至 mcpServers JSON 物件:

    "Azure MCP Server": {
      "command": "npx",
      "args": [
        "-y",
        "@azure/mcp@latest",
        "server",
        "start"
      ]
    }
    

向 Azure 驗證

Azure MCP 伺服器會使用 Azure 帳戶和 Microsoft Entra ID 提供順暢的驗證體驗。 若要使用 Azure MCP 伺服器,您必須先使用本機開發工具 (例如 Azure CLI、Azure 開發人員 CLI、Visual Studio 或 Visual Studio Code) 向 Azure 進行驗證。 Azure MCP 伺服器會自動從這些工具探索您的認證,並使用它們向 Azure 服務進行驗證。

  1. 例如,若要使用 Azure CLI 登入:

    az login
    
  2. 執行下列命令來驗證您的驗證狀態,以查看您目前登入的帳戶和訂用帳戶:

    az account show
    
  3. 請確定您的使用者帳戶具有您想要互動之 Azure 服務的適當角色指派。 您想要使用 Azure MCP 伺服器存取的 Azure 資源必須已存在於您的 Azure 訂用帳戶中。 例如,常見的角色指派包括:

    • Blob 儲存體資料貢獻者 - 讀取和寫入儲存體帳戶中的 Blob 資料。
    • 儲存體帳戶參與者 - 管理儲存體帳戶設定。
    • 貢獻者 - 跨訂用帳戶的全面資源管理。
    • 讀取者 - Azure 資源的唯讀存取權。

    如需角色指派和本機開發驗證的詳細資訊,請參閱 在本機開發期間向 Azure 服務驗證 .NET 應用程式

使用提示來測試 Azure MCP 伺服器

  1. 打開 Cursor 的 AI 聊天界面,通過按 Ctrl+L 或單擊側邊欄中的聊天圖標。

  2. 輸入使用 Azure MCP 伺服器功能的提示,例如:

    List my Azure storage accounts
    
  3. 如果系統提示您向 Azure 進行驗證,請執行建議的驗證工具,以透過瀏覽器登入。

    備註

    如果您已透過其他本機工具 (例如 Azure CLI) 進行驗證,Cursor 不會提示您登入 Azure。

  4. Cursor 會提示您執行工具來擷取儲存體帳戶,例如 storage account list。 選取 [執行工具] 以繼續。

    輸出應類似下列文字:

    The following resource groups are available for your subscription:
    
    1. **DefaultResourceGroup-EUS** (Location: `eastus`)
    2. **rg-testing** (Location: `centralus`)
    3. **rg-azd** (Location: `eastus2`)
    4. **msdocs-sample** (Location: `southcentralus`)
    5. **ai-testing** (Location: `eastus2`)
    
    Let me know if you need further details or actions related to any of these resource groups!
    
  5. 使用其他相關提示探索更多 Azure MCP 作業,例如:

    List all of the storage accounts in my subscription
    Get the available tables in my storage accounts
    Show me the configuration of my App Service instances
    

後續步驟