get_azure_context
Retrieve Azure environment context including subscriptions, resource groups, or resources using Kusto Query Language queries to manage and analyze Azure infrastructure.
Instructions
Retrieves Azure environment context.
TYPES: subscriptions, resource_groups, resources, custom (KQL)
CACHING: 5min default, bypass_cache=true for fresh data
EXAMPLES:
Find VMs: custom_query = "Resources | where type == 'microsoft.compute/virtualmachines'"
Find by tag: custom_query = "Resources | where tags.env == 'prod'"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query_type | Yes | ||
| subscription_id | No | Optional subscription scope | |
| resource_group | No | Optional resource group filter | |
| custom_query | No | KQL query for Resource Graph | |
| bypass_cache | No | Force fresh data |
Implementation Reference
- src/tools/context-retriever.ts:116-141 (handler)The main handler function that executes the get_azure_context tool logic. It handles input validation implicitly via type, audits the operation, dispatches to specific query handlers based on query_type (subscriptions, resource_groups, resources, custom), adds metadata, and logs the result.export async function handleGetAzureContext(input: GetAzureContextInput): Promise<ContextResponse> { const { query_type } = input; const operator = getOperatorInfo(); const audit = createAuditContext(`context:${query_type}`, 'low', 'query'); logger.debug('Context query', { query_type, subscription: input.subscription_id, rg: input.resource_group }); const handler = queryHandlers.get(query_type); if (!handler) { return { query_type, success: false, error: `Unknown query type: ${query_type}` }; } const response = await handler(input); response.correlation_id = audit.correlationId; response.operator = operator; if (response.success) { await audit.logSuccess(); logger.info('Context query succeeded', { query_type, count: response.count, cached: response.cached }); } else { await audit.logFailure(response.error || 'Unknown'); logger.warn('Context query failed', { query_type, error: response.error }); } return response; }
- src/tools/context-retriever.ts:10-16 (schema)Zod schema defining the input parameters for the get_azure_context tool, used for parsing and validation in the handler wrapper.export const GetAzureContextSchema = z.object({ query_type: z.enum(['subscriptions', 'resource_groups', 'resources', 'custom']).describe('Type of context query'), subscription_id: z.string().optional().describe('Subscription to scope query'), resource_group: z.string().optional().describe('Resource group filter'), custom_query: z.string().optional().describe('KQL query for Resource Graph'), bypass_cache: z.boolean().optional().default(false).describe('Force fresh data'), });
- src/index.ts:28-32 (registration)Registration of the get_azure_context tool in the central toolRegistry Map, providing the tool metadata, Zod schema for input parsing, and a wrapper handler that parses args before calling the main handler.['get_azure_context', { tool: getAzureContextTool, schema: GetAzureContextSchema, handler: args => handleGetAzureContext(GetAzureContextSchema.parse(args)) }],
- MCP-compatible tool definition object including name, description, and JSON schema for input validation, used for tool listing and discovery.export const getAzureContextTool = { name: 'get_azure_context', description: `Retrieves Azure environment context. TYPES: subscriptions, resource_groups, resources, custom (KQL) CACHING: 5min default, bypass_cache=true for fresh data EXAMPLES: - Find VMs: custom_query = "Resources | where type == 'microsoft.compute/virtualmachines'" - Find by tag: custom_query = "Resources | where tags.env == 'prod'"`, inputSchema: { type: 'object', properties: { query_type: { type: 'string', enum: ['subscriptions', 'resource_groups', 'resources', 'custom'] }, subscription_id: { type: 'string', description: 'Optional subscription scope' }, resource_group: { type: 'string', description: 'Optional resource group filter' }, custom_query: { type: 'string', description: 'KQL query for Resource Graph' }, bypass_cache: { type: 'boolean', description: 'Force fresh data', default: false }, }, required: ['query_type'], }, };