Azure Resource Graph MCP Server

by hardik-id
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Uses environment variables loaded from .env files to configure the Azure Resource Graph MCP server, particularly for setting up authentication credentials.

  • Serves as the runtime environment for the Azure Resource Graph MCP server, allowing it to execute Azure Resource Graph queries from within Cursor IDE or VS Code.

  • Used for package management and build process for the Azure Resource Graph MCP server.

演示

流动

Azure Resource Graph MCP 服务器

这是一个模型上下文协议 (MCP) 服务器,提供对 Azure Resource Graph 查询的访问权限。它允许您使用 Resource Graph 查询检索跨订阅的 Azure 资源信息。

特征

  • 使用 Resource Graph 查询来查询 Azure 资源
  • 默认查询返回资源 ID、名称、类型和位置
  • 支持自定义资源图查询
  • 使用 Azure DefaultAzureCredential 进行身份验证

先决条件

  • Node.js 已安装
  • Azure 订阅
  • 已安装并登录 Azure CLI,或已配置其他 Azure 凭据

运行 MCP 服务器

您可以使用 Cursor IDE 或 Visual Studio Code 运行 MCP 服务器。

选项 1:Cursor IDE 集成

要将 MCP 服务器与 Cursor IDE 集成:

  1. 将此存储库克隆到您的本地计算机(例如, C:\YOUR_WORKSPACE\azure-resource-graph-mcp-server
  2. 构建项目:
npm install npm run build
  1. 打开游标设置(JSON)并添加以下配置:
{ "mcpServers": { "azure-resource-graph-mcp-server": { "command": "node", "args": [ "C:\\YOUR_WORKSPACE\\azure-resource-graph-mcp-server\\build\\index.js" ], "env": { "SUBSCRIPTION_ID": "xxxxxx-xx-xx-xx-xxxxxx" }, } } }

注意:确保更新路径以匹配您的本地存储库位置。

  1. 重新启动 Cursor IDE 以应用更改

选项 2:VS Code 集成

要将 MCP 服务器与 Visual Studio Code 集成:

  1. 将此存储库克隆到本地计算机
  2. 构建项目:
npm install npm run build
  1. Ctrl+Shift+P打开 VS Code 设置(JSON),输入“设置(JSON)”,然后选择“首选项:打开用户设置(JSON)”
  2. 添加以下配置:
{ "mcp": { "servers": { "azure-resource-graph": { "type": "stdio", "command": "node", "args": [ "C:\\YOUR_WORKSPACE\\azure-resource-graph-mcp-server\\build\\index.js" ], "env": { "SUBSCRIPTION_ID": "xxxxxx-xx-xx-xx-xxxxxx" }, } } } }

注意:确保更新路径以匹配您的本地存储库位置。

  1. 保存settings.json文件
  2. 重新启动 VS Code 以应用更改

现在可以在 VS Code 中使用带有光标集成的 MCP 服务器。

用法

服务器提供以下工具:

查询资源

从 Azure Resource Graph 中检索资源及其详细信息。

参数:

  • subscriptionId (可选):Azure 订阅 ID(默认为配置的 ID)
  • query (可选):自定义资源图查询(默认为“资源|项目 ID、名称、类型、位置”)

环境设置

  1. 首先,通过运行以下命令确保您已登录到 Azure CLI:
    az login
    此步骤对于本地开发至关重要,因为 DefaultAzureCredential 将自动使用您的 Azure CLI 凭据。
  2. 设置环境变量:
    • .env.example复制到.env
    • 使用您的实际订阅 ID 更新.env中的AZURE_SUBSCRIPTION_ID
    • 使用 Azure CLI 身份验证时,其他变量( AZURE_TENANT_IDAZURE_CLIENT_IDAZURE_CLIENT_SECRET )是可选的
  3. 确保已配置正确的 Azure 凭据。服务器使用 DefaultAzureCredential,它支持:
    • Azure CLI
    • 托管标识
    • Visual Studio Code 凭据
    • 环境变量
  4. 如果使用环境变量,请设置:
    • AZURE_SUBSCRIPTION_ID
    • AZURE_TENANT_ID
    • AZURE_CLIENT_ID
    • AZURE_CLIENT_SECRET

错误处理

该服务器包括强大的错误处理功能:

  • Azure 客户端初始化失败
  • 查询执行错误
  • 无效的查询或参数

发展

从事此项目:

  1. src目录中进行更改
  2. 使用npm run build进行构建
  3. 通过运行服务器来测试您的更改

执照

本项目遵循 MIT 许可证。详情请参阅LICENSE文件。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

模型上下文协议服务器,用于使用 Azure 资源图大规模查询和分析 Azure 资源,使 AI 助手能够探索和监控 Azure 基础设施。

  1. Flow
    1. Azure Resource Graph MCP Server
      1. Features
      2. Prerequisites
      3. Running the MCP Server
      4. Usage
      5. Environment Setup
      6. Error Handling
      7. Development
      8. License
    ID: 94rcudrvyv