游标中的 Azure MCP 服务器入门

Azure MCP 服务器使用模型上下文协议(MCP)来标准化 AI 应用与外部工具和数据源之间的集成,使 AI 系统能够执行上下文感知 Azure 资源的作。

本文介绍如何完成以下任务:

  • 安装和向 Azure MCP 服务器进行身份验证
  • 使用 Cursor 的 AI 驱动的开发环境连接到 Azure MCP 服务器
  • 运行提示以测试 Azure MCP 服务器作并与 Azure 资源交互

先决条件

安装 Azure MCP 服务器

若要在 Cursor 中安装和配置 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. 通过按 Ctrl+L 或单击边栏中的聊天图标打开 Cursor 的 AI 聊天界面。

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

    List my Azure storage accounts
    
  3. 如果系统提示你向 Azure 进行身份验证,请运行建议的身份验证工具以通过浏览器登录。

    注释

    如果已通过其他本地工具(如 Azure CLI)进行身份验证,游标不会提示你登录到 Azure。

  4. 游标会提示你运行一个工具来检索存储帐户,例如 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
    

后续步骤