Azure MCP 伺服器會使用模型內容通訊協定 (MCP) 來標準化 AI 應用程式與外部工具和資料來源之間的整合,讓 AI 系統能夠執行內容感知 Azure 資源的作業。
在本文中,您將瞭解如何完成下列工作:
- 安裝並驗證 Azure MCP 伺服器。
- 在 Visual Studio 中使用 GitHub Copilot 代理程式模式連線到 Azure MCP Server。
- 執行提示來測試 Azure MCP 伺服器作業,並與 Azure 資源互動。
先決條件
- 具有作用中訂用帳戶的 Azure 帳戶
- Visual Studio
- .NET 10 或已安裝 Node.js LTS
安裝 Azure MCP 伺服器
Visual Studio 會使用名為的 mcp.json 檔案來檢查 MCP 伺服器設定,包括其他開發環境所設定的設定。 MCP 伺服器組態會依下列順序從下列目錄讀取:
-
%USERPROFILE%\.mcp.json:作為特定使用者的全域 MCP 伺服器配置。 在此處新增 MCP 伺服器,使其載入所有 Visual Studio 解決方案。 -
<SOLUTIONDIR>\.vs\mcp.json:特定於 Visual Studio,且只會針對指定的解決方案,載入特定使用者的指定 MCP 伺服器。 -
<SOLUTIONDIR>\.mcp.json:解決方案層級 MCP 組態,您可以在存放庫的原始檔控制中追蹤。 -
<SOLUTIONDIR>\.vscode\mcp.json:範圍限定為存放庫/解決方案,通常不包含在原始檔控制中。 -
<SOLUTIONDIR>\.cursor\mcp.json:範圍限定為存放庫/解決方案,通常不包含在原始檔控制中。
備註
其中一些位置需要 .mcp.json 而另一些則需要 mcp.json。
Azure MCP 伺服器可作為 NuGet 套件或 NPM 套件使用。 下列選項示範從 Visual Studio 連線到 Azure MCP 伺服器的兩種最常見方法。
備註
或者,你也可以使用 GitHub Copilot for Azure 擴充套件來安裝 Azure MCP
完成下列步驟,為特定目錄安裝 Azure MCP 伺服器:
在解決方案
.mcp.json的根目錄中建立名為 的新檔案。 使用 Visual Studio 編輯此檔案,以便自動套用其 JSON 結構描述。在
.mcp.json檔案中,為您偏好的套件新增下列 JSON:NuGet:
{ "servers": { "Azure MCP Server": { "command": "dnx", "args": [ "Azure.Mcp", "--source", "https://api.nuget.org/v3/index.json", "--yes", "--", "azmcp", "server", "start" ], "type": "stdio" } } }NPM:
{ "servers": { "Azure MCP Server": { "command": "npx", "args": [ "-y", "@azure/mcp@latest", "server", "start" ] } } }儲存您的變更。
開啟 GitHub Copilot 並選取代理程式模式。
選取工具圖示以檢視可用的工具。 搜尋 Azure MCP 伺服器 以篩選結果。
Visual Studio 2026 包含 Azure MCP Server 工具,搭配 Azure 與 AI 開發工作負載。 要讓它們可用:
打開 Visual Studio 安裝工具。
選擇 修改 以查看可用工作負載。
在 Workloads 標籤中,選擇 Azure 與 AI 開發。
在 安裝細節 面板中,確認已選擇 GitHub Copilot ,該選項包含以下元件:
- GitHub Copilot
- 適用於 Azure 的 GitHub Copilot
- Azure MCP 伺服器
下載 時選擇安裝 即可完成安裝流程。
向 Azure 驗證
Azure MCP 伺服器會使用 Azure 帳戶和 Microsoft Entra ID 提供順暢的驗證體驗。 若要使用 Azure MCP 伺服器,您必須先使用本機開發工具 (例如 Azure CLI、Azure 開發人員 CLI、Visual Studio 或 Visual Studio Code) 向 Azure 進行驗證。 Azure MCP 伺服器會自動從這些工具探索您的認證,並使用它們向 Azure 服務進行驗證。
例如,若要使用 Azure CLI 登入:
az login執行下列命令來驗證您的驗證狀態,以查看您目前登入的帳戶和訂用帳戶:
az account show請確定您的使用者帳戶具有您想要互動之 Azure 服務的適當角色指派。 您想要使用 Azure MCP 伺服器存取的 Azure 資源必須已存在於您的 Azure 訂用帳戶中。 例如,常見的角色指派包括:
- Blob 儲存體資料貢獻者 - 讀取和寫入儲存體帳戶中的 Blob 資料。
- 儲存體帳戶參與者 - 管理儲存體帳戶設定。
- 貢獻者 - 跨訂用帳戶的全面資源管理。
- 讀取者 - Azure 資源的唯讀存取權。
如需角色指派和本機開發驗證的詳細資訊,請參閱 在本機開發期間向 Azure 服務驗證 .NET 應用程式。
使用提示來測試 Azure MCP 伺服器
開啟 GitHub Copilot 並選取代理程式模式。
輸入導致代理程式使用 Azure MCP 伺服器工具的提示,例如 列出我的 Azure 資源群組。
為了驗證 Azure MCP 伺服器,Copilot 會提示您使用瀏覽器登入 Azure。
備註
如果您已透過其他本機工具 (例如 Azure CLI) 進行驗證,Copilot 不會提示您登入 Azure。
Copilot 會要求針對提示執行必要 Azure MCP 伺服器作業的許可權。 選取 [允許此時間] ,或使用箭號選取更具體的行為:
- 一律允許 將 作業設定為一律針對任何 GitHub Copilot 代理程式模式工作階段或任何 Visual Studio Code 工作區執行。
- 在此工作階段中允許一 律會在目前的 GitHub Copilot 代理程式模式工作階段中執行作業。
上一個提示的輸出應類似於以下文本:
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!使用其他相關提示探索和測試 Azure MCP 作業,例如:
List all of the storage accounts in my subscription Get the available tables in my storage accounts