Skip to main content
Glama

list-subscriptions

Retrieve accessible Azure subscriptions for a configured service principal to manage multi-tenant resource access and scoping.

Instructions

List subscriptions accessible to the configured service principal for a tenant.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tenant_nameNoOptional configured tenant name

Implementation Reference

  • Handler for 'list-subscriptions' tool: resolves credentials, enumerates subscriptions via ARM or defaults, prefers MG scope, fetches display names using ARG KQL query (list_subscriptions_kql), formats and returns list.
    if name == "list-subscriptions":
        tenant_name = arguments.get("tenant_name")
        cred, default_subs = AZURE_CONFIG.get_credentials(tenant_name)
        discovered = _enumerate_subscriptions_for_credential(cred)
        mg = AZURE_CONFIG.get_management_group_id(tenant_name)
        subs = discovered or default_subs
        if not subs and not mg:
            return [types.TextContent(type="text", text=(
                "No subscriptions found and no management_group_id configured. Configure management_group_id or ensure the SP has Reader at root."
            ))]
    
        # If we were able to enumerate, we only have IDs. For user-friendly output,
        # run a small ARG query to fetch display names.
        total_count = len(subs)
        scope_line = ""
        try:
            kql = list_subscriptions_kql()
            # If a management group is configured, prefer listing by MG to include all contained subscriptions
            if mg:
                res = execute_kql(cred, None, kql, top=1000, management_groups=[mg])
                scope_line = f"Scope: managementGroup={mg}"
            else:
                res = execute_kql(cred, subs, kql, top=1000)
                scope_line = f"Scope: subscriptions={len(subs)}"
            if res.get("status") == "success" and res.get("results"):
                rows = res["results"]
                lines = [f"- {r.get('name')} ({r.get('subscriptionId')})" for r in rows]
                total_count = len(rows)
            else:
                lines = [f"- {sid}" for sid in subs]
        except Exception:
            lines = [f"- {sid}" for sid in subs]
            scope_line = f"Scope: subscriptions={len(subs)} (fallback)"
    
        body = [
            f"Tenant: {tenant_name or AZURE_CONFIG.get_default_tenant().get('name')}",
            f"Subscriptions: {total_count}",
            scope_line,
            *lines,
        ]
        return [types.TextContent(type="text", text="\n".join(body))]
  • Tool registration including name, description, and input schema for 'list-subscriptions'.
    types.Tool(
        name="list-subscriptions",
        description="List subscriptions accessible to the configured service principal for a tenant.",
        inputSchema={
            "type": "object",
            "properties": {
                "tenant_name": {"type": "string", "description": "Optional configured tenant name"}
            },
            "required": [],
        },
    ),
  • Helper function to enumerate accessible subscription IDs using Azure SubscriptionClient.
    def _enumerate_subscriptions_for_credential(credential) -> List[str]:
        """Return list of subscription IDs accessible by the given credential.
    
        Falls back to empty list if enumeration fails or dependency is missing.
        """
        try:
            from azure.mgmt.subscription import SubscriptionClient  # type: ignore
        except Exception:
            return []
        try:
            client = SubscriptionClient(credential=credential)
            return [s.subscription_id for s in client.subscriptions.list()]
        except Exception:
            return []
  • Helper function providing the KQL query template for listing subscriptions (loaded from kql/list_subscriptions.kql or .md).
    def list_subscriptions_kql() -> str:
        return _tmpl("list_subscriptions")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/andrewstephenson-v1/Azure-Assistant-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server