query-resources
Search, filter, and analyze Azure resources across subscriptions using Azure Resource Graph. Write KQL queries to find resources by type, location, tags, or properties. Use for infrastructure auditing, compliance checks, and resource inventory management.
Instructions
Retrieves resources and their details from Azure Resource Graph. Use this tool to search, filter, and analyze Azure resources across subscriptions. It supports Kusto Query Language (KQL) for complex queries to find resources by type, location, tags, or properties. Useful for infrastructure auditing, resource inventory, compliance checking, and understanding your Azure environment's current state.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Resource Graph query, defaults to listing all resources | |
| subscriptionId | No | Azure subscription ID |
Input Schema (JSON Schema)
Implementation Reference
- src/index.ts:50-81 (handler)The handler function that executes the tool logic: queries Azure Resource Graph with the provided KQL query (or default), returns JSON-formatted resources or an error response.async ({ subscriptionId, query }) => { try { const defaultQuery = "Resources | project id, name, type, location"; const queryToUse = query || defaultQuery; const resources = await rgClient.resources({ subscriptions: [subscriptionId], query: queryToUse, }); return { content: [ { type: "text", text: JSON.stringify(resources, null, 2), }, ], }; } catch (err) { return { content: [ { type: "text", text: `Error querying resources: ${ err instanceof Error ? err.message : String(err) }`, }, ], isError: true, }; } }
- src/index.ts:40-49 (schema)Input schema defined using Zod for the tool parameters: subscriptionId (string, default from env) and optional query (string).{ subscriptionId: z .string() .describe("Azure subscription ID") .default(process.env.SUBSCRIPTION_ID || ""), query: z .string() .optional() .describe("Resource Graph query, defaults to listing all resources"), },
- src/index.ts:37-82 (registration)Registration of the 'query-resources' tool on the MCP server, including name, description, input schema, and inline handler.server.tool( "query-resources", "Retrieves resources and their details from Azure Resource Graph. Use this tool to search, filter, and analyze Azure resources across subscriptions. It supports Kusto Query Language (KQL) for complex queries to find resources by type, location, tags, or properties. Useful for infrastructure auditing, resource inventory, compliance checking, and understanding your Azure environment's current state.", { subscriptionId: z .string() .describe("Azure subscription ID") .default(process.env.SUBSCRIPTION_ID || ""), query: z .string() .optional() .describe("Resource Graph query, defaults to listing all resources"), }, async ({ subscriptionId, query }) => { try { const defaultQuery = "Resources | project id, name, type, location"; const queryToUse = query || defaultQuery; const resources = await rgClient.resources({ subscriptions: [subscriptionId], query: queryToUse, }); return { content: [ { type: "text", text: JSON.stringify(resources, null, 2), }, ], }; } catch (err) { return { content: [ { type: "text", text: `Error querying resources: ${ err instanceof Error ? err.message : String(err) }`, }, ], isError: true, }; } } );