# IdP setup: Microsoft Entra ID The steps below walk through configuring Microsoft Entra ID so it can issue and validate tokens for the MCP server, for the `entra` inbound auth mode. `entra` warrants its own `KX_MCP_AUTH` mode, rather than simply pointing `oidc_proxy` at Entra’s endpoints, because Entra has particulars a generic OIDC proxy cannot account for, notably its tenant-scoped issuer URL and the v1/v2 token-version split (Step 4). FastMCP addresses these through a dedicated `AzureProvider`. Beyond that, it is the same OAuth proxy pattern as `oidc_proxy`: since Entra has no open dynamic client registration, you pre-register **one** app and the MCP server brokers the browser login on its behalf. Everything downstream of a successful login is identical across `jwks`, `oidc_proxy`, and `entra`. Prerequisites: * An Entra tenant where you have **Global Administrator** or **Application Administrator** access. * The MCP server’s public URL as clients will reach it (e.g. `http://localhost:8000` for local use, or your deployment’s external URL). You will need this before registering the app, since the redirect URI is derived from it. ## Step 1: Register an application 1. In the Azure portal (`entra.microsoft.com` → **App registrations** → **+ New registration**). 2. Enter a **Name** (e.g. `onetick-mcp-entra`). 3. Under **Supported account types**, select **Accounts in this organizational directory only** (single tenant). 4. Under **Redirect URI**, select platform **Web** and enter your resource URL with `/auth/callback` appended, e.g. `http://localhost:8000/auth/callback`. This must match `KX_MCP_AUTH_RESOURCE_URL` exactly (see Step 5); a mismatch fails login with `AADSTS50011`. 5. Click **Register**. Note the **Application (client) ID** and **Directory (tenant) ID** from the Overview page; you will need both. ## Step 2: Expose a scope `KX_MCP_AUTH_REQUIRED_SCOPES` is mandatory in `entra` mode; the MCP server refuses to start without it. 1. In the app registration, go to **Expose an API**. 2. Click **+ Add a scope**. If no **Application ID URI** is set yet, Entra first prompts you to set one: accept the default (`api://`) and click **Save and continue**. 3. Set: * **Scope name**: `access` * **Who can consent**: **Admins and users** * **Admin consent display name / description**: any descriptive text (e.g. “Access the MCP server”) * **State**: **Enabled** 4. Click **Add scope**. ## Step 3: Create a client secret Unlike `jwks` (validate-only), `entra` mode authenticates *to* Entra as a confidential client: the MCP server needs a client ID and secret (its “client credentials”) to broker the login. 1. Go to **Certificates & secrets** → **+ New client secret**. 2. Add a description and expiry, then click **Add**. 3. Copy the secret’s **Value** immediately; Entra shows it only once. If you lose it, delete it and create a new one; there is no way to retrieve an existing value later. ## Step 4: Confirm the token version Entra issues v1 or v2 tokens depending on the app’s token version setting (`requestedAccessTokenVersion` in the current manifest, `accessTokenAcceptedVersion` in the legacy one), and the `iss`/`aud` claims differ between them: | Version | `iss` | `aud` | |-------------------------------------|------------------------------------------------------|---------------------------| | v2 (required) | `https://login.microsoftonline.com//v2.0` | `` (bare GUID) | | v1 (legacy default on some tenants) | `https://sts.windows.net//` | `api://` | `AzureProvider` requires v2 tokens. If your app registration does not already default to v2, set it explicitly: **Manifest** → find `"requestedAccessTokenVersion"` (under `"api"`) → set it to `2` → **Save**. ## Step 5: Configure the MCP server Add the following to your `.env` file, using the values collected above and restart the MCP server: ``` KX_MCP_AUTH=entra # This MCP server's own public URL, as MCP clients connect to it. Must match the # redirect URI registered in Step 1, minus the /auth/callback suffix. KX_MCP_AUTH_RESOURCE_URL=http://localhost:8000 KX_MCP_AUTH_CLIENT_ID= KX_MCP_AUTH_CLIENT_SECRET= KX_MCP_AUTH_TENANT_ID= # The scope name from Step 2, unprefixed. Required for entra mode. KX_MCP_AUTH_REQUIRED_SCOPES=access ``` #### NOTE These examples use `localhost` URLs. For a deployment other machines can reach, see `Exposing the MCP server beyond localhost`; the redirect URI registered with the IdP must change too. #### NOTE `AZURE_CLIENT_ID` / `AZURE_CLIENT_SECRET` / `AZURE_TENANT_ID` are also accepted, so an existing Azure-app `.env` works unchanged. ## Verify Connect with an MCP client (e.g. Claude Code; see `MCP Client setup`). The client should report that authentication is required and open a browser window to the Entra login page. After signing in, the MCP server accepts the connection and the tools become available. #### WARNING By default, **every user in your tenant can sign in to this app**, and the MCP server does not check who the user is. Restrict access according to your organization’s policy before using the MCP server with real data. In Entra, the app’s **Assignment required?** setting (under **Enterprise applications** → **Properties**) limits sign-in to assigned users and groups. ### Common pitfalls Redirect URI mismatch : `AADSTS50011`. The redirect URI registered on the app must equal `KX_MCP_AUTH_RESOURCE_URL` + `/auth/callback`, exactly, including the port. Login silently reuses a cached Microsoft session : If a browser already has an active Microsoft session (e.g. from provisioning the app), Entra can skip the account picker and sign the user in as whatever account is cached. Even though the login appears to succeed, tool calls behave as an identity with no expected access. Force a fresh login by signing out of the cached session first (an incognito window, or visiting `https://login.microsoftonline.com/common/oauth2/v2.0/logout`) before authenticating. `401` after a successful-looking login : Usually the app issues v1 tokens: check that `requestedAccessTokenVersion` is `2` (see Step 4). If you gave the app a custom **Application ID URI**, set `KX_MCP_AUTH_IDENTIFIER_URI` to match it. Decoding the token your MCP client holds will not help here: in `entra` mode it is minted by the MCP server, not by Entra, and `entra` mode ignores `KX_MCP_AUTH_ISSUER` and `KX_MCP_AUTH_AUDIENCE`. For a `jwks` server used by machine callers (below), decode the Entra token at `jwt.ms` or with `kx auth introspect --json` and compare its `iss`/`aud` against `KX_MCP_AUTH_ISSUER`/`KX_MCP_AUTH_AUDIENCE`. ## ``Client credentials (machine-to-machine, no browser)`` Everything above brokers an **interactive** login: a human in a browser. For a caller with no human present (a CI job, a scheduled task, another service acting on its own behalf), use the OAuth2 **client credentials** grant instead, against an MCP server running `jwks`, not `entra`. See `Combining a proxy mode with machine callers` for why, and for how to run both alongside each other. 1. Register a second app (or reuse the one from Step 1) to represent the calling service. 2. On the app the MCP server protects (the one from Step 1), go to **App roles** → **Create app role**. Set **Allowed member types** to **Applications**, give it a name (e.g. `mcp.access`), and enable it. 3. On the calling app, go to **API permissions** → **Add a permission** → **My APIs** → select the protected app → **Application permissions** → check the role from Step 2 → **Add permissions** → **Grant admin consent**. (This is a different consent path from Step 2 above: application permissions require admin consent and are separate from the delegated `access` scope, which only applies to interactive user logins.) 4. Create a client secret on the calling app (**Certificates & secrets**, same as Step 3 above). 5. The caller requests a token directly from Entra, with no browser involved: ``` curl -s -X POST \ "https://login.microsoftonline.com//oauth2/v2.0/token" \ -d "grant_type=client_credentials" \ -d "client_id=" \ -d "client_secret=" \ -d "scope=api:///.default" ``` 6. Configure the MCP server with `jwks`, pointed at Entra directly: ``` KX_MCP_AUTH=jwks KX_MCP_AUTH_JWKS_URI=https://login.microsoftonline.com//discovery/v2.0/keys KX_MCP_AUTH_ISSUER=https://login.microsoftonline.com//v2.0 KX_MCP_AUTH_AUDIENCE= # Leave KX_MCP_AUTH_REQUIRED_SCOPES unset. A client-credentials token carries the granted # app roles in a `roles` claim, not `scope`/`scp`. The MCP server only ever checks # `scope`/`scp`, so setting REQUIRED_SCOPES here would reject every such token. ``` 7. The caller sends the token from step 5 as a normal bearer: no discovery, no redirect, no consent screen. #### WARNING By default Entra issues a client-credentials token for the protected app to **any** app in your tenant, without the app role from step 2, and the MCP server does not check app roles. To limit machine callers to the apps you granted the role, turn on **Assignment required?** for the protected app (**Enterprise applications** → your app → **Properties**). This is the same setting that limits interactive sign-in, so assign your users and groups too if the same app serves `entra` mode.