list-tenants
Retrieve all Azure tenants accessible through the Azure MCP Server for tenant selection and management.
Instructions
List all available Azure tenants
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list-tenants"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/AzureServer.ts:530-570 (handler)The handleListTenants method implements the core logic for the 'list-tenants' tool. It creates a SubscriptionClient with DefaultAzureCredential to list all accessible tenants using client.tenants.list() and subscriptions using client.subscriptions.list(), then returns a JSON object containing both lists.
private async handleListTenants() { try { const creds = new DefaultAzureCredential(); const client = new SubscriptionClient(creds); const [tenants, subscriptions] = await Promise.all([ this.executeWithRetry(async () => { const items = []; for await (const tenant of client.tenants.list()) { items.push({ id: tenant.tenantId, name: tenant.displayName, }); } return items; }), this.executeWithRetry(async () => { const items = []; for await (const sub of client.subscriptions.list()) { items.push({ id: sub.subscriptionId, name: sub.displayName, state: sub.state, }); } return items; }), ]); return this.createTextResponse( JSON.stringify({ tenants, subscriptions }) ); } catch (error) { this.logWithContext("error", `Error listing tenants: ${error}`, { error, }); throw new AzureAuthenticationError( `Failed to list tenants and subscriptions: ${error}` ); } } - src/AzureServer.ts:325-333 (registration)Registers the 'list-tenants' tool in the handleListTools response, providing name, description, and input schema (empty object, no required parameters).
{ name: "list-tenants", description: "List all available Azure tenants", inputSchema: { type: "object", properties: {}, required: [], }, }, - src/AzureServer.ts:438-440 (registration)In the handleCallTool switch statement, the 'list-tenants' case delegates execution to the handleListTenants handler method.
case "list-tenants": result = await this.handleListTenants(); break; - src/AzureServer.ts:328-332 (schema)Input schema for 'list-tenants' tool: an empty object with no properties or required fields.
inputSchema: { type: "object", properties: {}, required: [], },