# Delegated or application permissions for an MCP server in Entra, and what /.default really asks for

> One MCP server in Entra, with delegated and app-only callers. Asking for less did not narrow the token. Narrowing the grant did, but an old token kept writing.

- URL: https://iamops.dev/entra-mcp-delegated-vs-app-permissions/
- Language: en
- Author: Argo
- Published: 2026-11-25
- Category: Labs
- Depth: Deep dive
- Audience: Researchers and builders
- Time: 30 min
- Topics: Microsoft Entra, MCP, OAuth, Permissions, AI agents

## TL;DR

- Asking for one delegated scope did not narrow the token. The client asked for [Mcp.Tools.Read](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#both-paths) and got every scope the admin had consented, including Mcp.Tools.Write.
- Client credentials accept only [/.default](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#contrast-cases). A single app role by name was refused, and /.default returned every role granted to the caller.
- A naive Model Context Protocol (MCP) server that calls Graph with its own app token [changed a group for a user who could not](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#contrast-cases). Every tool call ran with the widest permission the server held.
- Narrowing the grant shrank new tokens within [4 to 13 seconds](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#fix-and-re-run) in this small tenant, though answers flapped for about half a minute. A token issued before the change [still wrote to the group seven minutes later](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#fix-and-re-run).
- The fix that held was a [per-tool check in the server](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#fix-and-re-run), on-behalf-of (OBO) for user calls, and narrow grants. Conditional Access for workload identities was [not tested](https://iamops.dev/entra-mcp-delegated-vs-app-permissions/#what-was-not-run).

A reader asked why teams building Model Context Protocol (<abbr title="Model Context Protocol">MCP</abbr>) servers in Entra default to `/.default` and never narrow it. I wanted to see what Entra actually puts in the token, so I built one MCP server identity, a public MCP client, an autonomous agent, and a deliberately naive tool dispatcher that calls Microsoft Graph with one app token for every tool.

Then I asked Entra for less than the grant, for something never consented, and for `/.default`, on both the delegated and the application path. The short answer: in Entra the grant decides what a token carries, not the request. Even delegated tokens behaved that way. So the fix is in the grants and in the server, not in the scope string.

**The question, answered first.** Delegated or application permissions for an MCP server identity? Use delegated scopes with on-behalf-of (OBO) for every tool that acts for a person, so Graph enforces that person's own rights. Use application roles only for work nobody is signed in for, and keep each role narrow. `/.default` is not a choice you can skip on the application path: it is the only value Entra accepts there. So "narrow it" means narrowing the grant, which is what the lab does.

Every test below is an `az` or `curl` command you run yourself. One file, [entra_lab.py](https://iamops.dev/lab-files/entra-mcp-delegated-vs-app-permissions/entra_lab.py), does the two jobs that need code: the setup (three apps, a user, a group and the grants) and the small MCP server for the naive and fixed runs. Several things I did not test, including Conditional Access and an interactive consent page, are listed at the end.

## Setup

You need a throwaway Entra tenant where you are Global Administrator, never a work or production tenant. The setup creates three app registrations, one user, one group, and admin-consent grants, including `Group.ReadWrite.All` as an application permission. Sign in with the <abbr title="Azure command-line interface">Azure <abbr title="command-line interface">CLI</abbr></abbr>, set `TENANT_ID` and a secrets folder, and run the setup. Download [entra_lab.py](https://iamops.dev/lab-files/entra-mcp-delegated-vs-app-permissions/entra_lab.py) into an empty folder first. You need Python 3.10 or newer with `PyJWT` and its crypto extra, the Azure CLI, `curl`, `jq` and `openssl`:

```bash
export TENANT_ID="<TENANT_ID>"
export LAB_SECRETS=~/.lab-mcp-perm
az login --tenant "$TENANT_ID" --allow-no-subscriptions
python3 -m pip install "pyjwt[crypto]"
python3 entra_lab.py setup
source "$LAB_SECRETS/lab.env"
```

The setup keeps the server's client secret, the test user's password and the agent's private key in files in `$LAB_SECRETS`, readable only by you, and never prints them. `lab.env` holds only the identifiers the commands below use. Two shell helpers keep those commands short: `claims` prints the permission claims of a token and nothing else, and `b64url` is for the agent's signed request further down.

```bash
TOKEN_URL="https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token"
GRAPH=https://graph.microsoft.com/v1.0
claims() { jq -c -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | {scp, roles, idtyp}'; }
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
```

Before any token, check the tenant's <abbr title="OpenID Connect">OIDC</abbr> discovery document with the iamops.dev [OIDC discovery tool](https://iamops.dev/tools/oidc-discovery/). It shows the issuer `https://login.microsoftonline.com/<TENANT_ID>/v2.0`, the token endpoint, and the `jwks_uri` the server uses to verify tokens.

![iamops.dev OIDC discovery tool with the tenant v2.0 issuer: issuer, token endpoint and jwks_uri, with the tenant ID replaced by a label](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/tool-oidc-entra-tenant.webp)

*The tenant's discovery document. The tenant ID is replaced by a label. The tool also flags two findings about the tenant's advertised flows, which this lab does not test.*

`setup` registers `lab-mcp-perm-server` with three delegated scopes (`Mcp.Tools.Read`, `Mcp.Tools.Write`, `Mcp.Admin`) and two app roles (`Mcp.Tools.Read.All`, `Mcp.Tools.Write.All`). It then grants what an admin would click through: a delegated grant from the client for Read and Write but not Admin, both app roles for the agent, and for the server itself a broad Graph grant with `User.Read.All`, `Group.ReadWrite.All` and `Application.Read.All` as application permissions, plus `User.Read` and `Group.ReadWrite.All` delegated.

![Entra admin center, lab-mcp-perm-server, API permissions: five Microsoft Graph permissions, Application.Read.All, Group.ReadWrite.All delegated and application, User.Read and User.Read.All, all granted](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/portal-p03-server-api-permissions.webp)

*The broad grant after setup. Five Graph permissions, all granted. This is the state the next tests start from.*

The test user is a plain member who does not own the group. That matters for the delegated tests.

## Both paths

One run of each path gives the contrast cases something to compare with. The delegated path uses a signed-in user, the client asks Entra for a token, and the server swaps it for a Graph token with on-behalf-of (OBO). The test user signs in with the password grant, which is acceptable only for a throwaway user:

```bash
USER_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Tools.Read" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r .access_token)
claims <<< "$USER_TOKEN"
OBO_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  -d client_id="$SERVER_APP" --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d assertion="$USER_TOKEN" -d requested_token_use=on_behalf_of \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
claims <<< "$OBO_TOKEN"
```

The client asked for `api://server/Mcp.Tools.Read` only. The token came back with `scp Mcp.Tools.Read Mcp.Tools.Write`, because both were consented. The <abbr title="JSON Web Token">JWT</abbr> tool confirms the signature, issuer and audience, and shows `scp` with both scopes.

![iamops.dev JWT tool: signature valid, issuer and audience as expected, scp Mcp.Tools.Read Mcp.Tools.Write, user object ID and UPN replaced by labels](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/tool-jwt-user-broad.webp)

*The delegated token, decoded. The scopes are the consented ones, not the requested one. The claims are from a real token; I replaced every identifier with a label and re-signed it with a throwaway key so the tool could run its checks, so the green signature line only shows that the tool works.*

![Terminal output: the delegated run, D1 asks for one scope and the token carries two](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/02-delegated-client.webp)

*The delegated run. D1 asked for one scope. D3, the never-consented scope, was refused with AADSTS65001.*

The application path has no user. The agent asks for a client credentials token with its certificate. Instead of a secret it sends a short <abbr title="JSON Web Token">JWT</abbr> signed with the certificate's private key, the client assertion. `assertion` builds a new one, valid for 10 minutes, each time it runs:

```bash
X5T=$(openssl x509 -in "$LAB_SECRETS/agent.crt" -outform DER | openssl dgst -sha1 -binary | b64url)
assertion() {
  local now hdr pay
  now=$(date +%s)
  hdr=$(printf '{"alg":"RS256","typ":"JWT","x5t":"%s"}' "$X5T" | b64url)
  pay=$(printf '{"aud":"%s","iss":"%s","sub":"%s","jti":"%s","nbf":%d,"exp":%d}' \
    "$TOKEN_URL" "$AGENT_APP" "$AGENT_APP" "$(uuidgen)" "$now" "$((now + 600))" | b64url)
  printf '%s.%s.%s' "$hdr" "$pay" "$(printf %s "$hdr.$pay" | openssl dgst -sha256 -sign "$LAB_SECRETS/agent.key" | b64url)"
}
AGENT_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$AGENT_APP" \
  -d scope="api://$SERVER_APP/.default" \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$(assertion)" | jq -r .access_token)
claims <<< "$AGENT_TOKEN"
```

The token has `roles`, not `scp`, and `has_user` is false. The agent got `Mcp.Tools.Read.All` and `Mcp.Tools.Write.All`, the two roles it was assigned.

![iamops.dev JWT tool: agent token, signature valid, roles Mcp.Tools.Read.All and Mcp.Tools.Write.All, no scp](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/tool-jwt-agent-broad.webp)

*The application token. Roles, no scp and no user. The agent gets every role granted to it.*

## Contrast cases

**Ask for a scope nobody consented.** The client asked for `Mcp.Admin`, which is exposed but was never consented. Entra refused it with `400 invalid_grant`, `AADSTS65001`. The server's OBO request for Graph `Mail.Read`, which it never had, was refused the same way. Without an interactive consent prompt this is a hard stop. With an interactive client the user would see a consent page instead, and what they may accept depends on the tenant's user consent policy, which I did not test.

```bash
curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Admin" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r '.error, .error_description[0:60]'
curl -s "$TOKEN_URL" -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  -d client_id="$SERVER_APP" --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d assertion="$USER_TOKEN" -d requested_token_use=on_behalf_of \
  -d scope=https://graph.microsoft.com/Mail.Read | jq -r '.error, .error_description[0:60]'
```

**Ask for `/.default` on the delegated path.** The client asked for `api://server/.default` and got the same two scopes as the named request. The server's OBO request for Graph `/.default` returned `Group.ReadWrite.All User.Read email openid profile`. On the delegated path `/.default` and a named scope ended up the same, because the grant decides.

```bash
curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/.default" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r .access_token | claims
```

**Ask client credentials for one app role by name.** The agent asked for `api://server/Mcp.Tools.Read.All`, and the server asked Graph for `User.Read.All`. Both were refused with `400 invalid_scope`, `AADSTS1002012`: client credentials must use `/.default` with the resource identifier. That is why app-only servers use `/.default`. It is the only accepted value, so the only place to narrow is the grant.

```bash
curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$AGENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Tools.Read.All" \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$(assertion)" | jq -r '.error, .error_description[0:60]'
curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/User.Read.All | jq -r '.error, .error_description[0:60]'
```

![Sequence diagram: the agent asks for a named app role and is refused with AADSTS1002012; it asks for /.default and receives every assigned role; the server asks Graph for /.default and receives every granted role.](https://iamops.dev/img/entra-mcp-delegated-vs-app-permissions-app.svg)

*Client credentials cannot ask for less. A named app role is refused. /.default returns every role granted to the caller.*

**The user's own rights still apply on the delegated path.** The OBO Graph token carried `Group.ReadWrite.All` in `scp`. The user could read the lab group, but when they tried to change a group they do not own, Graph returned `403 Authorization_RequestDenied`. The delegated token is the consented scopes intersected with what the user may do. A broad delegated grant is less dangerous than the same application permission.

```bash
curl -s -o /dev/null -w '%{http_code}\n' "$GRAPH/groups/$GROUP_ID?\$select=displayName" \
  -H "Authorization: Bearer $OBO_TOKEN"
curl -s -X PATCH "$GRAPH/groups/$GROUP_ID" -H "Authorization: Bearer $OBO_TOKEN" \
  -H "Content-Type: application/json" -d '{"description":"changed by the user token"}' | jq -r .error.code
```

**The server asks Graph for `/.default` after the broad grant.** Now the server asks for its own Graph token, as an app. The same group change that failed for the user went through with `204`. The app token listed `Application.Read.All`, `Group.ReadWrite.All` and `User.Read.All` as roles, `idtyp app`, and no user.

```bash
GRAPH_APP_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
claims <<< "$GRAPH_APP_TOKEN"
curl -s -o /dev/null -w '%{http_code}\n' -X PATCH "$GRAPH/groups/$GROUP_ID" \
  -H "Authorization: Bearer $GRAPH_APP_TOKEN" -H "Content-Type: application/json" \
  -d '{"description":"changed by the server app token"}'
```

![iamops.dev JWT tool: Graph app token for the MCP server, decoded, roles Application.Read.All, Group.ReadWrite.All and User.Read.All, idtyp app](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/tool-jwt-graph-app-broad.webp)

*The token that changed the group. Decoded only, with no key pasted. Graph tokens are meant for Graph to verify.*

**A naive MCP server over-privileges every tool call.** The naive server accepts any valid token for its audience, then runs every tool with its own Graph `/.default` token. The client's user token asked only for `Mcp.Tools.Read`, but `update_group_description` ran with the server's app token and got `204`. The agent's call also went through. The `/me` call failed with `400`, because the server had lost the user: `/me` needs a delegated flow.

Start the naive server in the background, then send each of its three tools a `tools/call` with the user token and with the agent token. `call_tools` is just that loop of `curl` calls:

```bash
python3 entra_lab.py serve naive > server.log 2>&1 &
SERVER_PID=$!
call_tools() {
  for t in "$USER_TOKEN" "$AGENT_TOKEN"; do
    for tool in update_group_description list_groups get_profile; do
      curl -s http://127.0.0.1:9300/mcp -H "Authorization: Bearer $t" -H "Content-Type: application/json" \
        -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"$tool\"}}"; echo
    done
  done
}
call_tools
```

Tokens last about an hour. If a call answers `invalid token`, get fresh ones with the commands from the start of this section.

![Terminal output: the naive server, every tool call runs with the app token](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/05-naive-server.webp)

*The naive server. The write tool returned Graph status 204 for the user and for the agent. In the output, token_type names the caller's token (user or app), not the one sent to Graph: the naive server always calls Graph with its own app token.*

![Sequence diagram: the MCP client sends a tools/call; the naive server, with no per-tool check, takes a Graph app token with Group.ReadWrite.All and PATCHes the group with it; Graph returns 204.](https://iamops.dev/img/entra-mcp-delegated-vs-app-permissions-naive.svg)

*The over-privileged tool call. The naive server swaps a read-scoped user call for its own broad app token.*

## Fix and re-run

**Narrow every grant and watch fresh tokens shrink.** First keep a Graph app token from before the change for a later test. Then cut the client grant to `Mcp.Tools.Read`, remove `Mcp.Tools.Write.All` from the agent, and narrow the server's Graph grants to `User.Read.All` and `Group.Read.All` (application) and `User.Read Group.Read.All` (delegated):

```bash
OLD_GRAPH_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
az rest --method patch --uri "$GRAPH/oauth2PermissionGrants/$CLIENT_GRANT" --body '{"scope":"Mcp.Tools.Read"}'
az rest --method delete --uri "$GRAPH/servicePrincipals/$AGENT_SP/appRoleAssignments/$AGENT_WRITE_ASSIGN"
az rest --method delete --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments/$SERVER_APPREAD_ASSIGN"
az rest --method delete --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments/$SERVER_GROUPRW_ASSIGN"
az rest --method post --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments" \
  --body "{\"principalId\":\"$SERVER_SP\",\"resourceId\":\"$GRAPH_SP\",\"appRoleId\":\"$GRAPH_GROUP_READ_ALL_ROLE\"}" \
  --query appRoleId -o tsv
az rest --method patch --uri "$GRAPH/oauth2PermissionGrants/$SERVER_GRAPH_GRANT" --body '{"scope":"User.Read Group.Read.All"}'
```

Then ask for a fresh server token every two seconds and watch the roles:

```bash
for i in $(seq 1 30); do
  curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
    --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
    -d scope=https://graph.microsoft.com/.default | jq -r .access_token | claims
  sleep 2
done
```

In my run a script made the same changes and polled all three callers. In this run the change took 4 seconds. The first fresh token with the narrowed claims came 4 seconds after the change started for the user and the server, and 13 seconds for the agent. The answers were not stable yet: in an earlier run the agent flipped back to its old roles between calls. So I waited for eight narrowed answers in a row for all three callers, and that took 33 seconds. Plan for a longer delay in a bigger tenant. Microsoft does not promise this timing, and eventual consistency is the likely reason for the flapping.

![Entra admin center, lab-mcp-perm-server, API permissions after narrowing: Application.Read.All and Group.ReadWrite.All show Not granted, User.Read and User.Read.All granted](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/portal-p07-server-api-permissions-narrowed.webp)

*The portal after narrowing. Two of the five permissions now show Not granted. Group.Read.All is granted but not listed, which I come back to below.*

![Terminal output: narrow, the grants change in 4 seconds](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/06-narrow-run.webp)

*The narrow step. The timings are the ones quoted in the text.*

**Old tokens keep the old permissions.** The Graph app token issued before the change still changed the group seven minutes later (status 204), with 53 minutes of lifetime left. A token requested at that moment was refused with `403 Authorization_RequestDenied`. An app that caches its token keeps it. In the <abbr title="Microsoft Authentication Library">MSAL</abbr> test, the second call came from `token_source: cache`. Removing a grant is therefore not an emergency stop for tokens already issued. Restart the server or clear its cache after a change. I did not find or test a way to revoke an app-only access token.

```bash
curl -s -o /dev/null -w '%{http_code}\n' -X PATCH "$GRAPH/groups/$GROUP_ID" \
  -H "Authorization: Bearer $OLD_GRAPH_TOKEN" -H "Content-Type: application/json" \
  -d '{"description":"written with the token issued before narrowing"}'
```

**The naive server after narrowing.** Same naive server, same calls: get a fresh user token and agent token as above, then run `call_tools` again. Graph now refuses the write for both callers with `403 Authorization_RequestDenied`. Narrow grants limit the damage, but the server still runs every tool as itself and still loses the user.

**The fixed server: one scope or app role per tool, OBO for users.** In fixed mode the server checks the scope (user tokens) or app role (app tokens) that each tool needs before any downstream call. User calls go to Graph with OBO, so Graph sees the user. The write tool was refused with `403` before any Graph call, for both callers. The read tools worked: the user's profile came back through OBO, and the agent's group list came back with the app token.

```bash
kill "$SERVER_PID"
python3 entra_lab.py serve fixed > server.log 2>&1 &
SERVER_PID=$!
call_tools
```

![Terminal output: the fixed server refuses the write tool with 403 for both callers](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/09-fixed-server.webp)

*The fixed server. Both write calls were refused with 403 before any Graph call.*

![Sequence diagram: the client calls a write tool and the fixed server refuses it with 403 because the token has only Mcp.Tools.Read; a read tool with a user token goes through OBO to Graph as the user.](https://iamops.dev/img/entra-mcp-delegated-vs-app-permissions-fixed.svg)

*A check before every tool. The server refuses the write, and the read goes through OBO so Graph sees the user.*

**Consent hygiene.** Make each registration request only what it was granted, then list what each service principal actually holds:

```bash
az rest --method patch --uri "$GRAPH/applications(appId='$CLIENT_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$SERVER_APP\",\"resourceAccess\":[{\"id\":\"$MCP_READ_SCOPE\",\"type\":\"Scope\"}]}]}"
az rest --method patch --uri "$GRAPH/applications(appId='$AGENT_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$SERVER_APP\",\"resourceAccess\":[{\"id\":\"$MCP_READ_ROLE\",\"type\":\"Role\"}]}]}"
az rest --method patch --uri "$GRAPH/applications(appId='$SERVER_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$GRAPH_APP_ID\",\"resourceAccess\":[
  {\"id\":\"$GRAPH_USER_READ_ALL_ROLE\",\"type\":\"Role\"},{\"id\":\"$GRAPH_GROUP_READ_ALL_ROLE\",\"type\":\"Role\"},
  {\"id\":\"$GRAPH_USER_READ_SCOPE\",\"type\":\"Scope\"},{\"id\":\"$GRAPH_GROUP_READ_ALL_SCOPE\",\"type\":\"Scope\"}]}]}"
for sp in "$CLIENT_SP" "$SERVER_SP" "$AGENT_SP"; do
  az rest --method get --uri "$GRAPH/oauth2PermissionGrants?\$filter=clientId eq '$sp'" --query "value[].scope" -o tsv
  az rest --method get --uri "$GRAPH/servicePrincipals/$sp/appRoleAssignments" \
    --query "value[].[resourceDisplayName, appRoleId]" -o tsv
done
```

 The audit showed the trimmed state: the client requested one permission, the server four, the agent one, and the delegated and application grants matched. Read the grants on the service principal, not the registration. The <abbr title="application programming interface">API</abbr> permissions page of the registration showed the requested permissions and their status, but did not list `Group.Read.All` at all after the narrowing added it. Only after the trim did the page list it as granted.

![Entra admin center, lab-mcp-perm-server, API permissions after the trim: Group.Read.All delegated and application, User.Read and User.Read.All, all granted](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/portal-p10-server-api-permissions-trimmed.webp)

*After the trim. The registration now requests only what is granted.*

**Conditional Access for workload identities: not tested.** A policy that blocks the agent or the MCP server service principal outside a known network would be the next layer. Microsoft documents that creating or changing such policies needs Workload Identities Premium. A read-only call showed that this tenant has no subscribed licence plans (<abbr title="stock keeping unit">SKUs</abbr>), so I left it out and changed no policy.

## Cleanup

Stop the server, delete the user, the group and the three apps (with the apps, their grants go too), remove them from the deleted items so nothing stays restorable, and delete the local keys and state. Then count what is left. In my run the script's cleanup did the same after the screenshots and reported no lab apps.

```bash
kill "$SERVER_PID"
az rest --method delete --uri "$GRAPH/users/$USER_ID"
az rest --method delete --uri "$GRAPH/groups/$GROUP_ID"
for obj in "$SERVER_OBJ" "$CLIENT_OBJ" "$AGENT_OBJ"; do
  az rest --method delete --uri "$GRAPH/applications/$obj"
  az rest --method delete --uri "$GRAPH/directory/deletedItems/$obj"
done
rm -rf "$LAB_SECRETS" server.log
az rest --method get --query 'length(value)' \
  --uri "$GRAPH/applications?\$filter=startswith(displayName,'lab-mcp-perm')"
```

![Terminal output: cleanup reports zero lab apps left](https://iamops.dev/media/entra-mcp-delegated-vs-app-permissions/11-cleanup-output.webp)

*Nothing left behind. The three lab apps are gone.*

## What I would do with this

1. Keep a list for each MCP server of the tools, the scope or app role each tool needs, the Graph permissions behind them, and an owner.
2. Check the scope or role per tool in the server before any downstream call. Use OBO for user calls so Graph enforces the user's own rights.
3. Narrow the grants, then restart or clear the cache of every server that holds a token, and expect old tokens to work until they expire.
4. Trim registrations to what is granted, and audit the service principals, not the registration page.

## What was not run

Conditional Access for workload identities. The tenant has no subscribed licence plans, and Microsoft documents that such policies need Workload Identities Premium. I did not buy a licence or change any policy.

An interactive consent page and an authorization code flow with <abbr title="Proof Key for Code Exchange">PKCE</abbr>. The user tokens here came from the password grant for a throwaway user, so I did not test what a user can consent to on their own.

The full MCP transport, protected resource metadata and an MCP <abbr title="software development kit">SDK</abbr>. The server speaks MCP-shaped <abbr title="JavaScript Object Notation">JSON</abbr>-RPC `tools/call` over <abbr title="Hypertext Transfer Protocol">HTTP</abbr> on localhost.

Entra Agent ID blueprints and agent identities. The agent here is a plain app registration with a certificate.

A large tenant, or a long wait for propagation. The longest delay I saw was 33 seconds until the answers stopped flapping.

Revoking an app-only access token, and continuous access evaluation for workload identities.

*Written by Argo. The terminal output and the three Entra admin center screenshots come from one run on 25 November 2026 in a throwaway tenant, with a fresh set of apps and a user. That run sent the same token requests and Graph calls through one lab script (through <abbr title="Microsoft Authentication Library">MSAL</abbr> for the agent), and the script printed the result lines in the terminal figures, so your `curl` output will look different. This page lists those requests one by one as commands. `entra_lab.py` keeps the script's setup and its MCP server, unchanged. The command sequence as written here has not been run in a tenant. The admin center screenshots are cropped to hide the signed-in account and directory name, and the identifiers in the decoded tokens are replaced by labels. Tenant, app and object IDs and the signed-in account are replaced by labels. Every app, user and grant created by the lab was deleted the same evening.*

## Repeat this lab

This lab needs a throwaway Entra tenant where you are Global Administrator, the Azure CLI, curl, jq, openssl, Python 3.10 or newer with PyJWT (crypto extra), and entra_lab.py from https://iamops.dev/lab-files/entra-mcp-delegated-vs-app-permissions/entra_lab.py for the setup and the MCP server. Every test is an az or curl command. It creates three app registrations, one user, one group and admin-consent grants, then deletes them. About 30 minutes. Never use a production tenant.

Every value in angle brackets is a placeholder for your own test environment. Nothing on this page is a real identifier or secret.

**Set your variables once** `env.sh` (bash)

```bash
export TENANT_ID=<TENANT_ID>
export LAB_SECRETS=~/.lab-mcp-perm
```

### Step 1: Create the apps, grants, user and group

**Goal.** Run the setup step: it creates the MCP server, client and agent, and the broad Graph grant.

**Prerequisites**

- Throwaway tenant with Global Administrator
- Azure CLI, Python 3.10+ with PyJWT, curl, jq and openssl

`setup.sh` (bash)

```bash
az login --tenant "$TENANT_ID" --allow-no-subscriptions
python3 -m pip install "pyjwt[crypto]"
python3 entra_lab.py setup
source "$LAB_SECRETS/lab.env"
```

`helpers.sh` (bash)

```bash
TOKEN_URL="https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token"
GRAPH=https://graph.microsoft.com/v1.0
claims() { jq -c -R 'split(".")[1] | gsub("-";"+") | gsub("_";"/") | @base64d | fromjson | {scp, roles, idtyp}'; }
b64url() { openssl base64 -A | tr '+/' '-_' | tr -d '='; }
```

**Expected output**

```text
created: lab-mcp-perm-server, lab-mcp-perm-client, lab-mcp-perm-agent, lab-mcp-perm user, lab-mcp-perm-group
server Graph app roles granted: User.Read.All, Group.ReadWrite.All, Application.Read.All
client delegated grant on the server: Mcp.Tools.Read Mcp.Tools.Write (Mcp.Admin not consented)
agent app roles on the server: Mcp.Tools.Read.All, Mcp.Tools.Write.All
IDs written to ~/.lab-mcp-perm/lab.env; run: source "$LAB_SECRETS/lab.env"
```

### Step 2: Ask for one scope on the delegated path

**Goal.** The client asks for Mcp.Tools.Read only, and the token still carries the consented scopes.

**Prerequisites**

- The setup step has completed

`delegated.sh` (bash)

```bash
USER_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Tools.Read" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r .access_token)
claims <<< "$USER_TOKEN"
OBO_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  -d client_id="$SERVER_APP" --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d assertion="$USER_TOKEN" -d requested_token_use=on_behalf_of \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
claims <<< "$OBO_TOKEN"
```

`unconsented.sh` (bash)

```bash
curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Admin" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r '.error, .error_description[0:60]'
curl -s "$TOKEN_URL" -d grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer \
  -d client_id="$SERVER_APP" --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d assertion="$USER_TOKEN" -d requested_token_use=on_behalf_of \
  -d scope=https://graph.microsoft.com/Mail.Read | jq -r '.error, .error_description[0:60]'
```

`default.sh` (bash)

```bash
curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/.default" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r .access_token | claims
```

`user-group.sh` (bash)

```bash
curl -s -o /dev/null -w '%{http_code}\n' "$GRAPH/groups/$GROUP_ID?\$select=displayName" \
  -H "Authorization: Bearer $OBO_TOKEN"
curl -s -X PATCH "$GRAPH/groups/$GROUP_ID" -H "Authorization: Bearer $OBO_TOKEN" \
  -H "Content-Type: application/json" -d '{"description":"changed by the user token"}' | jq -r .error.code
```

**Expected output**

```text
{"scp":"Mcp.Tools.Read Mcp.Tools.Write",...}   # asked for one scope, got the consented two
{"scp":"Group.ReadWrite.All User.Read email openid profile",...}   # OBO to Graph /.default
invalid_grant / AADSTS65001 (Mcp.Admin, never consented; the same for Graph Mail.Read)
{"scp":"Mcp.Tools.Read Mcp.Tools.Write",...}   # /.default: same as the named scope
200   # the user reads the group
Authorization_RequestDenied   # the user cannot change a group they do not own
```

### Step 3: Ask client credentials for one app role

**Goal.** A named app role is refused, /.default returns every assigned role.

**Prerequisites**

- The setup step has completed

`agent-token.sh` (bash)

```bash
X5T=$(openssl x509 -in "$LAB_SECRETS/agent.crt" -outform DER | openssl dgst -sha1 -binary | b64url)
assertion() {
  local now hdr pay
  now=$(date +%s)
  hdr=$(printf '{"alg":"RS256","typ":"JWT","x5t":"%s"}' "$X5T" | b64url)
  pay=$(printf '{"aud":"%s","iss":"%s","sub":"%s","jti":"%s","nbf":%d,"exp":%d}' \
    "$TOKEN_URL" "$AGENT_APP" "$AGENT_APP" "$(uuidgen)" "$now" "$((now + 600))" | b64url)
  printf '%s.%s.%s' "$hdr" "$pay" "$(printf %s "$hdr.$pay" | openssl dgst -sha256 -sign "$LAB_SECRETS/agent.key" | b64url)"
}
AGENT_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$AGENT_APP" \
  -d scope="api://$SERVER_APP/.default" \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$(assertion)" | jq -r .access_token)
claims <<< "$AGENT_TOKEN"
```

`named-role.sh` (bash)

```bash
curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$AGENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Tools.Read.All" \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$(assertion)" | jq -r '.error, .error_description[0:60]'
curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/User.Read.All | jq -r '.error, .error_description[0:60]'
```

`server-app-token.sh` (bash)

```bash
GRAPH_APP_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
claims <<< "$GRAPH_APP_TOKEN"
curl -s -o /dev/null -w '%{http_code}\n' -X PATCH "$GRAPH/groups/$GROUP_ID" \
  -H "Authorization: Bearer $GRAPH_APP_TOKEN" -H "Content-Type: application/json" \
  -d '{"description":"changed by the server app token"}'
```

**Expected output**

```text
{"scp":null,"roles":["Mcp.Tools.Write.All","Mcp.Tools.Read.All"],...}
invalid_scope / AADSTS1002012 (a named app role; the same for Graph User.Read.All)
{"scp":null,"roles":["Application.Read.All","Group.ReadWrite.All","User.Read.All"],"idtyp":"app"}
204   # the same group change, now with the server app token
```

### Step 4: Call tools through the naive server

**Goal.** Call the tools as the user and as the agent and watch which token each downstream call uses. In the output, token_type names the caller's token (user or app), not the one sent to Graph: the naive server always calls Graph with its own app token.

**Prerequisites**

- The earlier steps have completed

`naive.sh` (bash)

```bash
python3 entra_lab.py serve naive > server.log 2>&1 &
SERVER_PID=$!
call_tools() {
  for t in "$USER_TOKEN" "$AGENT_TOKEN"; do
    for tool in update_group_description list_groups get_profile; do
      curl -s http://127.0.0.1:9300/mcp -H "Authorization: Bearer $t" -H "Content-Type: application/json" \
        -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"$tool\"}}"; echo
    done
  done
}
call_tools
```

**Expected output**

```text
{"graph_status": 204, "graph_error": "", "token_type": "user"}   # update_group_description
{"graph_status": 200, "graph_error": "", "token_type": "user"}   # list_groups
... the get_profile call fails with graph_status 400: /me needs a user
... the same three results for the agent token
```

### Step 5: Narrow the grants and check the token

**Goal.** Fresh tokens shrink, then the naive server is called again and the write is refused by Graph.

**Prerequisites**

- The naive server step has completed

`narrow.sh` (bash)

```bash
OLD_GRAPH_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
  --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
  -d scope=https://graph.microsoft.com/.default | jq -r .access_token)
az rest --method patch --uri "$GRAPH/oauth2PermissionGrants/$CLIENT_GRANT" --body '{"scope":"Mcp.Tools.Read"}'
az rest --method delete --uri "$GRAPH/servicePrincipals/$AGENT_SP/appRoleAssignments/$AGENT_WRITE_ASSIGN"
az rest --method delete --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments/$SERVER_APPREAD_ASSIGN"
az rest --method delete --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments/$SERVER_GROUPRW_ASSIGN"
az rest --method post --uri "$GRAPH/servicePrincipals/$SERVER_SP/appRoleAssignments" \
  --body "{\"principalId\":\"$SERVER_SP\",\"resourceId\":\"$GRAPH_SP\",\"appRoleId\":\"$GRAPH_GROUP_READ_ALL_ROLE\"}" \
  --query appRoleId -o tsv
az rest --method patch --uri "$GRAPH/oauth2PermissionGrants/$SERVER_GRAPH_GRANT" --body '{"scope":"User.Read Group.Read.All"}'
```

`poll.sh` (bash)

```bash
for i in $(seq 1 30); do
  curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$SERVER_APP" \
    --data-urlencode "client_secret@$LAB_SECRETS/server.secret" \
    -d scope=https://graph.microsoft.com/.default | jq -r .access_token | claims
  sleep 2
done
```

`old-token.sh` (bash)

```bash
curl -s -o /dev/null -w '%{http_code}\n' -X PATCH "$GRAPH/groups/$GROUP_ID" \
  -H "Authorization: Bearer $OLD_GRAPH_TOKEN" -H "Content-Type: application/json" \
  -d '{"description":"written with the token issued before narrowing"}'
```

`naive-again.sh` (bash)

```bash
USER_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=password -d client_id="$CLIENT_APP" \
  -d scope="api://$SERVER_APP/Mcp.Tools.Read" --data-urlencode username="$LAB_UPN" \
  --data-urlencode "password@$LAB_SECRETS/user.password" | jq -r .access_token)
AGENT_TOKEN=$(curl -s "$TOKEN_URL" -d grant_type=client_credentials -d client_id="$AGENT_APP" \
  -d scope="api://$SERVER_APP/.default" \
  -d client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer \
  -d client_assertion="$(assertion)" | jq -r .access_token)
call_tools
```

**Expected output**

```text
{"scp":null,"roles":["Application.Read.All","Group.ReadWrite.All","User.Read.All"],"idtyp":"app"}   # first polls
{"scp":null,"roles":["Group.Read.All","User.Read.All"],"idtyp":"app"}   # after a few seconds; it can flip back at first
204   # the token issued before the change still writes
{"graph_status": 403, "graph_error": "Authorization_RequestDenied", ...}   # naive server, write tool, both callers
```

### Step 6: Run the fixed server

**Goal.** One scope or app role per tool, OBO for user calls. The write tool is refused before any Graph call.

**Prerequisites**

- The narrow step has completed

`fixed.sh` (bash)

```bash
kill "$SERVER_PID"
python3 entra_lab.py serve fixed > server.log 2>&1 &
SERVER_PID=$!
call_tools
```

**Expected output**

```text
fixed server, user token scp: Mcp.Tools.Read | agent token roles: ['Mcp.Tools.Read.All']
   user  update_group_description   -> HTTP 403 {"error": "update_group_description needs Mcp.Tools.Write; the token has Mcp.Tools.Read"}
   user  list_groups                -> HTTP 200 {"graph_status": 200, "graph_error": "", "token_type": "user"}
   user  get_profile                -> HTTP 200 {"graph_status": 200, "graph_error": "", "token_type": "user"}
   agent update_group_description   -> HTTP 403 {"error": "update_group_description needs Mcp.Tools.Write.All; the token has Mcp.Tools.Read.All"}
   agent list_groups                -> HTTP 200 {"graph_status": 200, "graph_error": "", "token_type": "app"}
   agent get_profile                -> HTTP 400 {"graph_status": 400, "graph_error": "BadRequest", "token_type": "app"}
```

### Step 7: Trim the registrations and audit the grants

**Goal.** Each registration requests only what it was granted, then the service principals are listed.

**Prerequisites**

- The narrow step has completed

`trim-audit.sh` (bash)

```bash
az rest --method patch --uri "$GRAPH/applications(appId='$CLIENT_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$SERVER_APP\",\"resourceAccess\":[{\"id\":\"$MCP_READ_SCOPE\",\"type\":\"Scope\"}]}]}"
az rest --method patch --uri "$GRAPH/applications(appId='$AGENT_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$SERVER_APP\",\"resourceAccess\":[{\"id\":\"$MCP_READ_ROLE\",\"type\":\"Role\"}]}]}"
az rest --method patch --uri "$GRAPH/applications(appId='$SERVER_APP')" --body "{\"requiredResourceAccess\":[{\"resourceAppId\":\"$GRAPH_APP_ID\",\"resourceAccess\":[
  {\"id\":\"$GRAPH_USER_READ_ALL_ROLE\",\"type\":\"Role\"},{\"id\":\"$GRAPH_GROUP_READ_ALL_ROLE\",\"type\":\"Role\"},
  {\"id\":\"$GRAPH_USER_READ_SCOPE\",\"type\":\"Scope\"},{\"id\":\"$GRAPH_GROUP_READ_ALL_SCOPE\",\"type\":\"Scope\"}]}]}"
for sp in "$CLIENT_SP" "$SERVER_SP" "$AGENT_SP"; do
  az rest --method get --uri "$GRAPH/oauth2PermissionGrants?\$filter=clientId eq '$sp'" --query "value[].scope" -o tsv
  az rest --method get --uri "$GRAPH/servicePrincipals/$sp/appRoleAssignments" \
    --query "value[].[resourceDisplayName, appRoleId]" -o tsv
done
```

**Expected output**

```text
Mcp.Tools.Read   # client: one delegated grant
User.Read Group.Read.All   # server: delegated grant
Microsoft Graph  <role id>   # server: two Graph app roles
lab-mcp-perm-server  <role id>   # agent: one app role
```

### Step 8: Clean up

**Goal.** Delete the grants, the three apps, the user and the group, then the local keys and state.

**Prerequisites**

- Nothing else uses the lab objects

`cleanup.sh` (bash)

```bash
kill "$SERVER_PID"
az rest --method delete --uri "$GRAPH/users/$USER_ID"
az rest --method delete --uri "$GRAPH/groups/$GROUP_ID"
for obj in "$SERVER_OBJ" "$CLIENT_OBJ" "$AGENT_OBJ"; do
  az rest --method delete --uri "$GRAPH/applications/$obj"
  az rest --method delete --uri "$GRAPH/directory/deletedItems/$obj"
done
rm -rf "$LAB_SECRETS" server.log
az rest --method get --query 'length(value)' \
  --uri "$GRAPH/applications?\$filter=startswith(displayName,'lab-mcp-perm')"
```

**Expected output**

```text
0   # no lab-mcp-perm app registrations left
```


## Sources

- [Scopes and permissions, including the .default scope](https://learn.microsoft.com/en-us/entra/identity-platform/scopes-oidc)
- [OAuth 2.0 client credentials flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow)
- [OAuth 2.0 on-behalf-of flow](https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-on-behalf-of-flow)
- [Add app roles and get them from a token](https://learn.microsoft.com/en-us/entra/identity-platform/howto-add-app-roles-in-apps)
- [Verify scopes and app roles in a protected web API](https://learn.microsoft.com/en-us/entra/identity-platform/scenario-protected-web-api-verification-scope-app-roles)
- [Secure an MCP server with Microsoft Entra ID](https://learn.microsoft.com/en-us/entra/agent-id/secure-mcp-server-with-entra-id)
- [Conditional Access for workload identities](https://learn.microsoft.com/en-us/entra/identity/conditional-access/workload-identity)
- [Access token claims reference](https://learn.microsoft.com/en-us/entra/identity-platform/access-token-claims-reference)

Discuss: [X](https://x.com/iamopsdev) | [LinkedIn](https://www.linkedin.com/company/iamops-dev/)
