MCP Healthcare Reference
Workforce path · Claude Code → internal tier → first-party MCP server

Anatomy of a tool call: every token, from birth to expiry

What actually happens when an engineer's Claude Code calls the scheduling server: which tokens get created, where each one lives, how long it survives, how refresh works — and what the engineer sees, which is almost nothing.

Stage one

First connect — the only visible moment

The engineer adds the server once. The first tool call goes out with no token, and the machinery self-assembles.

1

Discovery, not configuration

The MCP server answers 401 with a pointer to its Protected Resource Metadata (/.well-known/oauth-protected-resource/mcp). Claude Code fetches it and learns which authorization server to talk to — the engineer never types an auth URL.

2

One corporate login

Claude Code is a pre-registered public client — no client secret; PKCE binds the flow. It opens the browser once: Keycloak brokers to the workforce IdP for SSO + MFA, then redirects back to a loopback listener (localhost:8765) Claude Code runs just for this moment.

3

Code for tokens

On the callback Claude Code validates the RFC 9207 iss parameter (mix-up defense), then swaps the single-use authorization code + PKCE verifier for tokens at Keycloak's token endpoint.

UX: one browser tab, corporate login, "you can close this window." No API keys, nothing to paste.

Stage two

The token inventory

Five artifacts exist after login. Only one of them ever touches the MCP plane.

TokenIssued byLives whereLifetime
IdP identity token (brokering leg) Workforce IdP Consumed by Keycloak during login, then gone — it never reaches Claude Code or the MCP plane (single-issuer invariant) seconds
Authorization code Keycloak In flight only, single use ~1 minute
Access token (JWT, PS256) Keycloak Claude Code's local credential store (macOS Keychain). Keycloak keeps no copy — it's a stateless JWT 5 minutes (lab realm; contract target 10 min interactive)
Refresh token (opaque) Keycloak Same credential store; validity anchored to the server-side SSO session in Keycloak's database as long as the SSO session (~30 min idle / 10 h max by default)
SSO cookie Keycloak The browser only same session limits

The access token's claims are the whole story.

aud = mcp://tier/internal plus the server audiences the client may reach · azp = the client · idp_origin = where the human authenticated · groups and amr (the MFA fact travels in the token) · mcp_contract version pin · a unique jti that keys every audit record.

Stage three

Every tool call, for the next five minutes

No session exists anywhere on this path. Every request is self-contained — which is why killing a server replica mid-conversation is a non-event.

On the sender-constrained variant of this path (the workforce-dpop client), every one of these calls also carries a DPoP proof header — a fresh signature over the method, URL, timestamp, and a hash of this exact access token, made with a key only that client holds. The gateway checks the proof and its single-use ID, the server re-verifies the signature, and a replayed proof dies at the gateway. On that path, the token alone authorizes nothing.

Stage four

Expiry and refresh — invisible until it isn't

5m

Access token expires

The next call gets a 401. Claude Code silently POSTs the refresh token to Keycloak — no browser, no prompt — and retries with a fresh JWT. The engineer notices nothing. A leaked access token is useful for at most five minutes; that is the entire point.

10h

The session dies, and the refresh token with it

At session idle (~30 min unused) or absolute max (~10 h), the refresh token stops working because the SSO session behind it is gone. Claude Code re-runs the browser flow. If the IdP session is still alive it's a browser tab that completes itself; otherwise it's a real re-login.

UX: one silent refresh every five minutes, one browser bounce a day.

Stage five

Step-up — when a tool needs more than the floor

The default token authorizes floor tools only. Sensitive tools (confirm a booking, read a full patient record) require optional scopes. Calling one under-scoped returns a single-shot 403 insufficient_scope naming the scope that tool requires; Claude Code re-runs the authorization flow requesting exactly those scopes — usually a blink, since the SSO session exists. The elevated token is scoped to what was asked, the escalation is consented and audited, and clinical scopes additionally require the mfa mark the IdP stamped at login — the servers check amr for the scopes in MCP_MFA_SCOPES (by default the FHIR full-record scope) and answers 401 insufficient_user_authentication (RFC 9470) without it. This is the platform's minimum-necessary mechanism, not a UX accident.

Stage six

Protecting the tokens at rest

The local credential store is the one place tokens sit still, so it gets defense in depth from both sides: make theft hard, and make stolen tokens nearly worthless.

In place

Worthless quickly

5-minute access tokens; refresh anchored to a revocable server-side session. Stealing the store buys minutes, not months.

In place

Worthless elsewhere

Tier + server audiences mean an internal token is cryptographically useless at the external tier or against a server it wasn't minted for — and the internal tier is only reachable over the VPN anyway.

In place

Floor by default

The standing token holds floor scopes only; anything sensitive needs a fresh, consented, audited step-up.

In place

One kill switch

Revoking the user's Keycloak SSO session (offboarding, incident) kills every refresh token instantly; access tokens age out within minutes.

In place

Keychain, not files

Tokens live in the OS keychain with per-app ACLs — encrypted at rest, locked with the screen, not greppable in dotfiles or env vars.

In place

Sender-constraining

Bearer tokens are replayable by whoever holds one — so the workforce-dpop client key-binds its tokens (DPoP, RFC 9449, cnf.jkt), exactly as traced in stage three: a lifted token is inert without the key. The mTLS path (cnf.x5t#S256) does the same for workloads; claude-code stays bearer until the client ships proof support.

Strengthen

Anomaly detection

The audit spine can flag a jti reused from two network paths, or an internal-tier token appearing off-VPN — theft becomes visible even when it succeeds.

Strengthen

Device posture

FileVault, screen-lock keychain relock, MDM posture as a VPN precondition, EDR on the endpoint: a stolen laptop shouldn't mean a live credential store.