list-role-assignments
View Azure role assignments at subscription, resource group, or resource level to manage access control and permissions.
Instructions
List role assignments for the subscription or resource group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scope | No | Scope for role assignments (subscription, resource group, or resource ID). Leave empty for subscription level. |
Implementation Reference
- src/AzureServer.ts:252-267 (registration)Tool registration including name, description, and input schema definition in handleListTools() method.
{ name: "list-role-assignments", description: "List role assignments for the subscription or resource group", inputSchema: { type: "object", properties: { scope: { type: "string", description: "Scope for role assignments (subscription, resource group, or resource ID). Leave empty for subscription level.", }, }, required: [], }, }, - src/AzureServer.ts:688-728 (handler)Main handler function that parses input, lists role assignments using Azure AuthorizationManagementClient.roleAssignments.listForScope, and returns formatted results.
private async handleListRoleAssignments(args: any) { const { scope } = z .object({ scope: z.string().optional(), }) .parse(args); if (!this.context.authorizationClient) { throw new AzureMCPError( "Authorization client not initialized", "NO_CLIENT" ); } try { const roleAssignments = []; const assignmentScope = scope || `/subscriptions/${this.context.selectedSubscription}`; for await (const assignment of this.context.authorizationClient.roleAssignments.listForScope( assignmentScope )) { roleAssignments.push({ id: assignment.id, principalId: assignment.principalId, principalType: assignment.principalType, roleDefinitionId: assignment.roleDefinitionId, scope: assignment.scope, createdOn: assignment.createdOn, createdBy: assignment.createdBy, }); } return { roleAssignments, total: roleAssignments.length }; } catch (error) { this.logWithContext("error", `Error listing role assignments: ${error}`, { error, }); throw new AzureResourceError(`Failed to list role assignments: ${error}`); } } - src/AzureServer.ts:454-456 (registration)Dispatch case in handleCallTool switch statement that routes to the handler.
case "list-role-assignments": result = await this.handleListRoleAssignments(args); break; - src/AzureServer.ts:689-693 (schema)Input schema validation using Zod in the handler function.
const { scope } = z .object({ scope: z.string().optional(), }) .parse(args);