m365_tenant
Discover Microsoft 365 tenant information including tenant ID, region, and OpenID configuration endpoints for a specified domain.
Instructions
Discover Microsoft 365 tenant information for a domain. Returns tenant ID, region, and OpenID configuration endpoints.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| domain | Yes | Domain to check for M365 tenant |
Implementation Reference
- src/m365/index.ts:24-53 (handler)The m365Tenant function performs the core logic for the 'm365_tenant' tool by fetching OpenID configuration from Microsoft's servers.
export async function m365Tenant(domain: string): Promise<M365TenantResult> { try { const res = await fetch( `https://login.microsoftonline.com/${encodeURIComponent(domain)}/v2.0/.well-known/openid-configuration`, ); if (!res.ok) return { domain, found: false }; const data = await res.json(); const issuer: string = data.issuer ?? ""; // Extract tenant ID from issuer URL: https://login.microsoftonline.com/{tenant-id}/v2.0 const tenantMatch = issuer.match(/\/([0-9a-f-]{36})\//); const tenantId = tenantMatch?.[1]; // Extract region from tenant_region_scope const region = data.tenant_region_scope; return { domain, found: true, tenantId, issuer, authorizationEndpoint: data.authorization_endpoint, tokenEndpoint: data.token_endpoint, region, }; } catch { return { domain, found: false }; } } - src/m365/index.ts:3-11 (schema)The M365TenantResult interface defines the output structure for the 'm365_tenant' tool.
interface M365TenantResult { domain: string; found: boolean; tenantId?: string; issuer?: string; authorizationEndpoint?: string; tokenEndpoint?: string; region?: string; } - src/protocol/tools.ts:439-446 (registration)The 'm365_tenant' tool is registered in src/protocol/tools.ts, mapping the name and schema to the implementation.
const m365TenantTool: ToolDef = { name: "m365_tenant", description: "Discover Microsoft 365 tenant information for a domain. Returns tenant ID, region, and OpenID configuration endpoints.", schema: { domain: z.string().describe("Domain to check for M365 tenant"), }, execute: async (args) => json(await m365Tenant(args.domain as string)), };