Skip to content

Add /mcp-prod — a second instance against production Internet Identity (id.ai) - #31

Merged
aterga merged 1 commit into
mainfrom
claude/mcp-spec-compliance-9202ka
Jul 4, 2026
Merged

aterga merged 1 commit into
mainfrom
claude/mcp-spec-compliance-9202ka

Conversation

@aterga

@aterga aterga commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

What & why

Lets users test this MCP server against production Internet Identity (id.ai) instead of beta.id.ai by pointing their connector at https://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)
Internet Identity II_URL (default beta.id.ai) / II_CANISTER_ID (fgte5-…) II_URL_PROD (default id.ai) / II_CANISTER_ID_PROD (rdmx6-jaaaa-aaaaa-aaadq-cai)
OAuth AS issuer <PUBLIC_URL> (root) <PUBLIC_URL>/prod (RFC 8414 path issuer)
AS endpoints /oauth/* /prod/oauth/*
AS metadata /.well-known/oauth-authorization-server /.well-known/oauth-authorization-server/prod (+ OIDC-style /prod/.well-known/… alternate)
Resource metadata root doc + /…/mcp /.well-known/oauth-protected-resource/mcp-prod
401 challenge points at root resource doc the path-inserted /mcp-prod doc
  • Isolation: each instance has its own Identities + AuthStore — session keys, pending connects, and bearer tokens never cross. Discovery wires clients to the right AS automatically via the per-resource metadata.
  • Shared DCR: client registrations are II-agnostic (redirect allow-list only), so both stores share one SharedClients map — one client_id works on both AS instances, and the persisted oauth-clients.json snapshot can't lose the other instance's entries.
  • Instance-aware plumbing: II handshake link (per-instance II origin, prefixed callback), finish_url, finish retry page, device verification_uri + code form, and the challenge URL.
  • II trust is by origin (shared by both instances): users enable this server's origin as their trusted MCP server in their id.ai settings — a separate identity from their beta anchor.

Caveat

/mcp-prod completes 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 build clean (one pre-existing macro warning); cargo test — 35/35 (new: instance-defaults test; updated: challenge/identities tests).
  • Local two-instance smoke (no live II needed):
    • Discovery: beta root docs unchanged; prod AS doc at both path-inserted and OIDC-alternate URLs with issuer <base>/prod and /prod/oauth/* endpoints; prod resource doc correct.
    • Full prod auth-code flow: /prod/oauth/authorize → II link targets https://id.ai/mcp#callback=<base>/prod/oauth/connect/callback… → key-request returns finish_url with the /prod prefix → completion → /prod/oauth/finish 302 → /prod/oauth/token issues a token. Beta flow unchanged (regression-tested).
    • Token isolation matrix: prod token → /mcp-prod 200, /mcp 401; beta token → /mcp 200, /mcp-prod 401. A beta state on the prod callback → 403.
    • Per-instance 401 challenges point at the correct resource-metadata URLs; prod device flow's verification_uri is /prod/oauth/device; shared client_id registered once works on both AS instances.

🤖 Generated with Claude Code

https://claude.ai/code/session_014T9N8USDfNK5yzznPGg7Ym


Generated by Claude Code

…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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 IiInstance and per-instance Identities/AuthStore to run /mcp (beta) and /mcp-prod (prod) side-by-side.
  • Scope prod OAuth issuer/endpoints under /prod and 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.

Comment thread src/auth.rs Resolved
Comment thread src/auth.rs Resolved
Comment thread src/main.rs Resolved
Comment thread src/identities.rs Resolved
Comment thread src/identities.rs Resolved
@aterga
aterga marked this pull request as ready for review July 4, 2026 20:57
@aterga
aterga merged commit 0742b58 into main Jul 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants