manage_azure_resources
Execute Azure CLI commands with plan/review workflow for managing resources like Storage, Cosmos DB, and Key Vault, featuring command validation, risk assessment, and audit logging.
Instructions
Primary tool for all Azure operations via CLI.
FLOW: 1) Call with execute_now=false for plan 2) Review risk 3) Call with execute_now=true to execute
SAFETY: Commands validated for injection. Destructive ops flagged HIGH risk.
AUDIT: All ops logged with operator email and correlation ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes | Azure CLI command (e.g., "az aks create ...") | |
| explanation | Yes | Why this command was chosen | |
| execute_now | No | false: plan only, true: execute |
Implementation Reference
- src/tools/azure-manager.ts:61-141 (handler)Main handler function for the 'manage_azure_resources' tool. Validates and sanitizes the Azure CLI command, assesses risk, creates audit context, handles planning (execute_now=false) or execution (execute_now=true), runs the command using executeAzCommand, logs outcomes, and provides detailed responses with error analysis.export async function handleManageAzureResources( input: ManageAzureResourcesInput ): Promise<PlanResponse | ExecutionResponse> { const { command, explanation, execute_now } = input; const operator = getOperatorInfo(); const validation = sanitizeInput(command); if (!validation.isValid) { logger.warn('Command validation failed', { command, error: validation.error }); return { proposed_command: command, risk_level: 'high', summary: 'Validation failed', explanation, status: 'REJECTED', warnings: [validation.error || 'Unknown error'], next_steps: 'Provide a valid Azure CLI command.', operator, }; } const cmd = validation.sanitizedCommand!; const risk = validation.riskLevel; const audit = createAuditContext(cmd, risk, execute_now ? 'execute' : 'plan'); if (!execute_now) { const summary = generateCommandSummary(cmd); const nextSteps = risk === 'high' ? '⚠️ HIGH RISK: Review carefully before execute_now=true' : 'Call again with execute_now=true to execute.'; logger.command('plan', cmd, 'success', { riskLevel: risk, correlationId: audit.correlationId }); return { proposed_command: cmd, risk_level: risk, summary, explanation, status: 'WAITING_FOR_CONFIRMATION', warnings: validation.warnings, next_steps: nextSteps, correlation_id: audit.correlationId, operator, }; } logger.info('Executing', { command: cmd, correlationId: audit.correlationId }); const result: CommandResult = await executeAzCommand(cmd, { applyScope: true, enableRetry: true }); if (result.success) { await audit.logSuccess(); logger.command('execute', cmd, 'success', { correlationId: audit.correlationId }); return { executed_command: cmd, status: 'EXECUTED', success: true, output: result.parsedOutput ?? result.stdout, raw_output: result.stdout, correlation_id: audit.correlationId, operator, }; } const analysis = analyzeError(result.stderr); await audit.logFailure(result.stderr); logger.command('execute', cmd, 'failure', { correlationId: audit.correlationId, error: result.stderr }); return { executed_command: cmd, status: 'FAILED', success: false, error: result.stderr || 'Execution failed', stderr: result.stderr, error_analysis: analysis, correlation_id: audit.correlationId, operator, }; }
- src/tools/azure-manager.ts:10-14 (schema)Zod schema defining the input structure for the manage_azure_resources tool: command, explanation, and execute_now flag.export const ManageAzureResourcesSchema = z.object({ command: z.string().describe('Azure CLI command to execute'), explanation: z.string().describe('Why this command was chosen'), execute_now: z.boolean().default(false).describe('If true, execute; if false, plan only'), });
- src/index.ts:23-27 (registration)Registration of the 'manage_azure_resources' tool in the MCP server registry, linking the tool metadata, schema, and handler.['manage_azure_resources', { tool: manageAzureResourcesTool, schema: ManageAzureResourcesSchema, handler: args => handleManageAzureResources(ManageAzureResourcesSchema.parse(args)) }],
- src/tools/azure-manager.ts:143-161 (helper)Tool metadata object defining name, description, and JSON input schema for MCP protocol compliance.export const manageAzureResourcesTool = { name: 'manage_azure_resources', description: `Primary tool for all Azure operations via CLI. FLOW: 1) Call with execute_now=false for plan 2) Review risk 3) Call with execute_now=true to execute SAFETY: Commands validated for injection. Destructive ops flagged HIGH risk. AUDIT: All ops logged with operator email and correlation ID.`, inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Azure CLI command (e.g., "az aks create ...")' }, explanation: { type: 'string', description: 'Why this command was chosen' }, execute_now: { type: 'boolean', description: 'false: plan only, true: execute', default: false }, }, required: ['command', 'explanation'], }, };