Skip to main content
Glama

list-subscriptions

Retrieve Azure subscriptions available to the configured service principal for a tenant to manage access and scope queries.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tenant_nameNoOptional configured tenant name

Implementation Reference

  • Main handler logic for 'list-subscriptions' tool within the call_tool function. Retrieves tenant credentials, enumerates subscriptions, prefers MG scope for ARG query to list subs with names.
    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 in list_tools() function using MCP types.Tool, defining name, description, and input schema.
    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 to enumerate subscription IDs using Azure SubscriptionClient for the credential, crucial for subscription discovery.
    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 for listing subscriptions by loading the template from kql/list_subscriptions.
    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