Repository navigation
feat(http): /mcp as an OAuth protected resource, metadata and challenge (ADR-0022 slice 15b) - #787
Merged
Merged
Conversation
ajianaz
force-pushed
the
feat/principal-aware-policy
branch
2 times, most recently
from
December 5, 2026 01:28
db16e81 to
c7b9ad3
Compare
…ge (ADR-0022 slice 15b) An agent that calls /mcp with no usable credential is now told where to authenticate. With MELDFRAME_PUBLIC_ORIGIN and MELDFRAME_OIDC_ISSUER set, the server serves the RFC 9728 document at /.well-known/oauth-protected-resource/mcp and at the root form, and a 401 of /mcp carries WWW-Authenticate: Bearer resource_metadata="...". A request with no bearer credential to judge gets no error parameter; a token that was read and refused gets error="invalid_token". With the tiers required the scope parameter asks for offline_access and the three tier words. The address and the document are built once from the configuration, so no Host or forwarded header can change them. A 503, a 429 and a path outside /mcp carry no metadata challenge. With nothing set there is no resource and the 401 keeps the bare Bearer; a half or bad configuration stops the start and names the variable. whoami gains kind (person or agent) and tiers (read, change, delete held). docs/mcp-tools.json and the skill follow. Nothing validates a bearer token yet (slice 15c). Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
…dential Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
ajianaz
force-pushed
the
feat/agent-metadata-challenge
branch
from
December 5, 2026 08:37
101a30b to
0e75af3
Compare
…d one Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
ADR-0022 slice 15b.
/mcpbecomes an OAuth protected resource. With a public origin and an issuer configured, the server serves the RFC 9728 metadata document at/.well-known/oauth-protected-resource/mcp(and at the root form), and a 401 of/mcpcarriesWWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp".whoamigainskindandtiers. Stacked on #783 (slice 15a): the base isfeat/principal-aware-policy.Why
An agent that calls
/mcpwith no credential has to be told where to authenticate (RFC 9728 and RFC 6750), or an MCP client cannot start the OAuth flow. This is the second third of ADR-0022 slice 15; 15c adds the bearer resolver, so nothing here validates a token yet.whoamisays which kind of principal the credential is and which risk tiers it holds, so an agent can tell what the server will let it do before it calls a tool.The rules that write each byte (the document, the challenges, the quoting, the scope words) are the functions of
meldframe-oidcfrom slice 6-3. This slice builds them once at start from three variables and serves what they wrote, so no request header can change them.Decisions where the ADR was silent:
Access-Control-*header and a preflight is a 405 (Claude Code is not a browser, as for/mcp).public, max-age=300withnosniffand no validator. A HEAD is a GET without a body; every other method is 405 withAllow: GET,HEAD. It spends the per-address budget, and a 429 is never a challenge.error; a token that was read and refused getserror="invalid_token". The body is the same for both.requiredthe challenge asks foroffline_accessand the three tier words; withoffnoscopeis written./mcpcarry no metadata challenge. The gate of/mcpis also the fallback of the merged router, so a path no route has is refused by it (401 with no credential, 404 with one) and has been since before this slice; those keep the bareBearer.Bearer. One variable without the other, an empty value, or a value that is not valid stops the start and names the variable without repeating the value. A build without themcpfeature does not read the variables.Protected::insufficient_scopewrites the 403 challenge and nothing calls it: a refusal of a tool travels inside a 200 of MCP, and 15c decides where a status can carry it.whoamisaysagentand all three tiers for it, a token nameduser:beaincluded: the kind is the credential's, and only a session makes a person.Changes
meldframe-http-agents:Protected(protected.rs: the resource, the document, both challenges and the two routes) and the reading ofMELDFRAME_PUBLIC_ORIGIN,MELDFRAME_OIDC_ISSUERandMELDFRAME_TIER_SCOPES(settings.rs). It now depends onmeldframe-http,meldframe-oidc,meldframe-authandaxum.meldframe-http:ChallengerandUnauthenticated(challenge.rs),McpConfig::challenge, and the 401 split in two (Reply::unauthenticated()andReply::token_refused()) so the gate can tell the two challenges apart. Status and body do not change.meldframe-principal:Kind::as_str,Tiers::iterandTiers::names.whoamiaddskindandtiers;docs/mcp-tools.jsonis regenerated andskills/meldframe/SKILL.mdfollows.apps/server:main.rsreads the configuration, passes the challenger to/mcpand merges the two routes, and printsmcp resourceandmcp metadata. Five new test files, two shared helper modules, goldens undertests/golden/agent/, and the test world of slice 15a takes aWiringwith the protected resource, an authenticator and a config.docs/epics.mdstatus,docs/operations.md(three variables),docs/architecture.md,AGENTS.md.Testing
Run with
CARGO_INCREMENTAL=0and a target directory of its own (the disk was short, so the test executables were cleared between runs):cargo test -p meldframe-server: 115 binaries, 777 passed, 0 failed, 1 ignored. New:agent_metadata_routes(12),agent_challenge(9),agent_whoami(5),agent_metadata_env(4, the real binary), and thewhoamiassertions ofsurface.rs.cargo test -p meldframe-server --no-default-features: 53 binaries, 358 passed, 0 failed (agent_metadata_off, 2, runs only there: no route, nothing printed, variables not read).cargo test -p meldframe-principal -p meldframe-http -p meldframe-http-agents -p meldframe-mcp-defs -p meldframe-oidc -p meldframe-auth: 40 binaries, 302 passed, 0 failed. New:protected.rs(16), principal (2),auth.rsunit tests (3)./mcp; hostileHost,X-Forwarded-*andForwardedheaders; no CORS header for any origin or preflight; HEAD, 405 and the per-address budget;whoamifor a person and five agents of different caps, called at the same time; the real binary's environment and 18 bad configurations; the golden documents and exchanges.cargo fmt --all --check,cargo clippy -p meldframe-principal -p meldframe-http -p meldframe-http-agents -p meldframe-server -p meldframe-mcp-defs --all-targets -- -D warnings(also with--no-default-features),cargo xtask deps-check,mm-check(also with--base),size-check(also with--base),sh scripts/ci/principal-mint.sh,sh scripts/ci/selftest.sh: clean.tools/check-protocol.shwas not run: no protocol type changed./mcp, the document built fromHost, the document built fromX-Forwarded-Host, the challenge built fromX-Forwarded-Host, andwhoamilisting every tier to everyone.git log origin/feat/principal-aware-policy..HEAD --format=%B | sh scripts/ci/message-patterns.sh: clean.Cora (agent, local): not run as an agent review.
cora review --base feat/principal-aware-policy --no-llmfound one critical (a static scanner read a doc comment that said "access token: ..." as a hardcoded secret), I reworded the comment in the second commit, and the rerun found no issues (49 files, 4 chunks).cora mcpstarts and lists its tools, butcora.review_prepareon the 175 KB diff did not answer within 150 seconds, and no independent reviewer is available here, so no agent review was obtained. The CI Cora review runs on this pull request.Not covered: nothing validates a bearer token yet (15c); no real client followed the challenge (the rmcp client of the tests only fails to connect, and what Claude Code does with the header is not tested, so E2.2 stays open); no real Gatehouse (the issuer is written into the document and never fetched); the public origin is the operator's word and is not compared with the address the server is reached at; no TLS or HTTP/2 was run;
Protected::insufficient_scopehas no caller; Postgres and the live sockets were not run through the new seam.