Repository navigation
Add /mcp-prod — a second instance against production Internet Identity (id.ai) - #31
Merged
Merged
Conversation
…dentity Parameterize the server by II instance (new IiInstance: name, ii_url, ii_canister, oauth_prefix, mcp_path) and run two fully isolated instances in one process: - /mcp (unchanged): beta II via II_URL / II_CANISTER_ID, OAuth AS at the root of PUBLIC_URL. - /mcp-prod: production II via II_URL_PROD (default https://id.ai) / II_CANISTER_ID_PROD (default rdmx6-jaaaa-aaaaa-aaadq-cai), with a path-scoped AS under /prod/oauth/* — issuer <PUBLIC_URL>/prod (RFC 8414 path issuer), AS metadata at /.well-known/oauth-authorization-server/prod (plus the OIDC-style alternate) and resource metadata at /.well-known/oauth-protected-resource/mcp-prod. Each instance gets its own Identities + AuthStore, so session keys, pending connects, and bearer tokens never cross instances (verified: beta tokens 401 on /mcp-prod and vice versa; a beta state is rejected by the prod callback). Dynamic client registrations are shared via one SharedClients store, so both AS instances see the same client_ids and the persisted snapshot never loses the other instance's entries. Instance-aware plumbing: II handshake link (per-instance II origin and prefixed callback), finish_url, /oauth/finish retry page, device verification URI/form, discovery documents, and the 401 WWW-Authenticate resource_metadata pointer (root doc for /mcp, path-inserted doc for /mcp-prod). The finish-retry exhaustion error now names the II origin and hints it may not support MCP connect yet (relevant until prod II ships the #4086 feature set). README documents the new instance and env vars. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_014T9N8USDfNK5yzznPGg7Ym
There was a problem hiding this comment.
Pull request overview
This PR adds a second, fully isolated MCP/OAuth instance at /mcp-prod that targets production Internet Identity (id.ai), while keeping the existing /mcp (beta II) behavior unchanged. It introduces an IiInstance abstraction to parameterize II origin/canister and OAuth path scoping, enabling both instances to run in the same process with shared dynamic client registrations.
Changes:
- Add
IiInstanceand per-instanceIdentities/AuthStoreto run/mcp(beta) and/mcp-prod(prod) side-by-side. - Scope prod OAuth issuer/endpoints under
/prodand add discovery docs for both instances (RFC 8414 path issuer + RFC 9728 resource metadata). - Share dynamic client registration storage across instances and update docs/UI to reference the new endpoint.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/main.rs | Boots two II instances and wires separate MCP + OAuth routers for /mcp and /mcp-prod. |
| src/identities.rs | Introduces IiInstance and makes Identities instance-bound to keep sessions isolated. |
| src/auth.rs | Makes OAuth/discovery/device flow instance-aware and shares DCR storage via SharedClients. |
| README.md | Documents the new /mcp-prod instance, its issuer/discovery URLs, and configuration knobs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 & why
Lets users test this MCP server against production Internet Identity (
id.ai) instead ofbeta.id.aiby pointing their connector athttps://mcp.beta.id.ai/mcp-prod— one deploy, one cert, two fully isolated instances.Design
The server is parameterized by an
IiInstance(name,ii_url,ii_canister,oauth_prefix,mcp_path) and runs two of everything in one process:/mcp(unchanged)/mcp-prod(new)II_URL(defaultbeta.id.ai) /II_CANISTER_ID(fgte5-…)II_URL_PROD(defaultid.ai) /II_CANISTER_ID_PROD(rdmx6-jaaaa-aaaaa-aaadq-cai)<PUBLIC_URL>(root)<PUBLIC_URL>/prod(RFC 8414 path issuer)/oauth/*/prod/oauth/*/.well-known/oauth-authorization-server/.well-known/oauth-authorization-server/prod(+ OIDC-style/prod/.well-known/…alternate)/…/mcp/.well-known/oauth-protected-resource/mcp-prod/mcp-proddocIdentities+AuthStore— session keys, pending connects, and bearer tokens never cross. Discovery wires clients to the right AS automatically via the per-resource metadata.SharedClientsmap — oneclient_idworks on both AS instances, and the persistedoauth-clients.jsonsnapshot can't lose the other instance's entries.finish_url, finish retry page, deviceverification_uri+ code form, and the challenge URL.Caveat
/mcp-prodcompletes only once production II carries the #4086 MCP feature set (mcp_register,mcp_prepare_delegation/mcp_get_delegation,finish_url). Until then the connect fails at the II step; the finish-retry exhaustion message now names the II origin and hints it "may not support MCP connect yet".Testing
cargo buildclean (one pre-existing macro warning);cargo test— 35/35 (new: instance-defaults test; updated: challenge/identities tests).<base>/prodand/prod/oauth/*endpoints; prod resource doc correct./prod/oauth/authorize→ II link targetshttps://id.ai/mcp#callback=<base>/prod/oauth/connect/callback…→ key-request returnsfinish_urlwith the/prodprefix → completion →/prod/oauth/finish302 →/prod/oauth/tokenissues a token. Beta flow unchanged (regression-tested)./mcp-prod200,/mcp401; beta token →/mcp200,/mcp-prod401. A betastateon the prod callback → 403.verification_uriis/prod/oauth/device; sharedclient_idregistered once works on both AS instances.🤖 Generated with Claude Code
https://claude.ai/code/session_014T9N8USDfNK5yzznPGg7Ym
Generated by Claude Code