共用方式為


使用 Visual Studio Code 開始使用 Azure MCP 伺服器

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

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

  • 安裝並驗證 Azure MCP 伺服器
  • 在 Visual Studio Code 中使用 GitHub Copilot 代理程式模式連線到 Azure MCP 伺服器
  • 執行提示以測試 Azure MCP 伺服器作業並與 Azure 資源互動

先決條件

安裝 Azure MCP 伺服器

選取下列其中一個選項,在 Visual Studio Code 中安裝 Azure MCP 伺服器:

  1. 若要安裝 適用於 Visual Studio Code 的 Azure MCP 伺服器延伸模組,請選取下列連結:

    在 Visual Studio Code 中使用 NPX 安裝

    小提示

    若要獲得最佳的 Azure MCP 伺服器體驗, 請安裝適用於 Azure 的 GitHub Copilot,其中包含並使用 Azure MCP 伺服器延伸模組。 適用於 Azure 的 GitHub Copilot 可簡化您的開發工作流程,並提升您在 Azure 平臺上的生產力。

  2. 安裝擴充功能之後,請開啟 GitHub Copilot 並選取 [代理程式模式]。 若要深入瞭解代理程式模式,請瀏覽 Visual Studio Code 檔

  3. 重新整理工具清單,將 Azure MCP 伺服器視為可用的選項:

    將 Azure MCP Server 顯示為 GitHub Copilot 工具的螢幕擷取畫面。

向 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. 開啟 GitHub Copilot 並選取代理程式模式。

  2. 輸入導致代理程式使用 Azure MCP 伺服器工具的提示,例如 列出我的 Azure 資源群組

  3. 為了驗證 Azure MCP 伺服器,Copilot 會提示您使用瀏覽器登入 Azure。

    備註

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

  4. Copilot 會要求許可權以執行您提示所需的 Azure MCP 伺服器作業。 選取 [繼續] ,或使用箭號來選取更具體的行為:

    • 目前工作階段 一律會在目前的 GitHub Copilot 代理程式模式工作階段中執行作業。
    • 目前工作區 一律會針對目前的 Visual Studio Code 工作區執行命令。
    • 一律允許, 將操作設為始終在任何 GitHub Copilot 代理程式模式工作階段或任何 Visual Studio Code 工作區中執行。

    螢幕擷取畫面顯示可用來執行 Azure MCP 伺服器作業的選項。

    上一個提示的輸出應類似於以下文本:

    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`)
    14. **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
    

後續步驟