Purpose
This is a Model Context Protocol (MCP) server whose core purpose is to provide access to Azure Resource Graph queries. With this server, users can retrieve detailed information about Azure resources across Azure subscriptions, such as resource ID, name, type, and location. It is suitable for scenarios that require quickly querying and monitoring Azure resources in a development environment.
Main Capabilities
- Query Azure resources using Resource Graph.
- The default query returns resource ID, name, type, and location.
- Supports custom Resource Graph queries.
- Uses Azure DefaultAzureCredential for authentication.
- Provides the tool
query-resources: retrieves resources and their details from Azure Resource Graph. This tool accepts two optional parameters:subscriptionId(optional): Azure subscription ID, defaults to the configured ID.query(optional): custom Resource Graph query, defaults toResources | project id, name, type, location.
Usage
Environment Requirements
- Node.js is installed.
- An Azure subscription is available.
- Azure CLI is installed and signed in, or other Azure credentials are configured.
Running the MCP Server
The MCP server can be run through Cursor IDE or Visual Studio Code.
Option 1: Cursor IDE Integration
- Clone the repository to your local machine (for example
C:\YOUR_WORKSPACE\azure-resource-graph-mcp-server). - Build the project.
- Open Cursor settings (JSON) and add the corresponding configuration (make sure to update the path to match the local repository location).
- Restart Cursor IDE to apply the changes.
Option 2: VS Code Integration
- Clone the repository to your local machine.
- Press
Ctrl+Shift+P, type "Settings (JSON)" and select "Preferences: Open User Settings (JSON)" to open VS Code settings (JSON). - Add the corresponding configuration.
- Save the
settings.jsonfile. - Restart VS Code to apply the changes.
The MCP server can then be used in VS Code through the cursor integration.
Environment Setup
- First make sure you are signed in to Azure CLI by running
az login. This step is critical for local development because DefaultAzureCredential will automatically use Azure CLI credentials. - Set environment variables:
- Copy
.env.exampleto.env. - Update
.envinAZURE_SUBSCRIPTION_IDwith the actual subscription ID. - Other variables (
AZURE_TENANT_ID、AZURE_CLIENT_ID、AZURE_CLIENT_SECRET) are optional when using Azure CLI authentication.
- Copy
- Make sure the correct Azure credentials are configured. The server uses DefaultAzureCredential, which supports:
- Azure CLI
- Managed Identity
- Visual Studio Code credentials
- Environment variables
If using environment variables, set:
AZURE_SUBSCRIPTION_IDAZURE_TENANT_IDAZURE_CLIENT_IDAZURE_CLIENT_SECRET
Development
- Make changes in the
srcdirectory. - Build with
npm run build. - Test changes by running the server.
Applicable Scenarios
- Query Azure resources across subscriptions in Cursor IDE or VS Code.
- Need to quickly obtain Azure resource inventories and properties in the development workflow.
- Perform more granular resource retrieval through custom Resource Graph queries.
Limitations
- Requires a Node.js environment, an Azure subscription, and valid Azure credentials.
- The server includes robust error handling for the following situations: Azure client initialization failure, query execution errors, invalid queries or parameters.
- This project uses the MIT license; for details, please refer to the LICENSE file.
Regarding the specific build commands, configuration JSON content, and installation steps, complete details are not provided in the materials, so they are not provided here.