Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -1445,3 +1445,4 @@ Legend: `shipped` ≥95% checked · `in-flight` 1–94% · `drafted` 0% · `—`
| [129-per-user-upstream-credentials](./specs/129-per-user-upstream-credentials/) | — | — |
| [130-skills-review-ux](./specs/130-skills-review-ux/) | `shipped` | 9/9 (100%) |
| [131-skills-card-ux](./specs/131-skills-card-ux/) | `shipped` | 7/7 (100%) |
| [132-client-oauth-login](./specs/132-client-oauth-login/) | `drafted` | 0/72 (0%) |
35 changes: 35 additions & 0 deletions specs/132-client-oauth-login/checklists/requirements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Specification Quality Checklist: Browser login for MCP clients (opt-in OAuth)

**Purpose**: Validate specification completeness and quality before proceeding to planning
**Created**: 2026-11-22
**Feature**: [spec.md](../spec.md)

## Content Quality

- [x] No implementation details (languages, frameworks, APIs)
- [x] Focused on user value and business needs
- [x] Written for non-technical stakeholders
- [x] All mandatory sections completed

## Requirement Completeness

- [x] No [NEEDS CLARIFICATION] markers remain
- [x] Requirements are testable and unambiguous
- [x] Success criteria are measurable
- [x] Success criteria are technology-agnostic (no implementation details)
- [x] All acceptance scenarios are defined
- [x] Edge cases are identified
- [x] Scope is clearly bounded
- [x] Dependencies and assumptions identified

## Feature Readiness

- [x] All functional requirements have clear acceptance criteria
- [x] User scenarios cover primary flows
- [x] Feature meets measurable outcomes defined in Success Criteria
- [x] No implementation details leak into specification

## Notes

- The spec names `require_mcp_auth`, the `credentials` tool and the Clients hub because they are existing product surfaces the user sees. Protocol shapes, storage and token formats stay in design.md.
- Decisions come from design.md ("Decided by Algis", "Calls made here"), cross-reviewed in three rounds (opencode gpt-6.1-sol, round 3 clean).
111 changes: 111 additions & 0 deletions specs/132-client-oauth-login/contracts/oauth-endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Contract: public OAuth endpoints

`<origin>` is the scheme and host of the request. All endpoints below answer only when the feature is on, the peer and the Host are loopback, and the build is the personal edition. Otherwise see "Gate".

## Gate

| Feature | Ever used | `/mcp/oauth*` | `/oauth/*`, `/.well-known/oauth-*` |
|---|---|---|---|
| off | no | previous behaviour (the `/mcp/` catch-all) | previous behaviour (the root handler) |
| off | yes | `404` | `404` |
| on | any | served | served |

Non-loopback peer or Host, or server edition, with the feature on: `404`.

## Protected resource

`ANY /mcp/oauth` and `ANY /mcp/oauth/{client}` — the MCP endpoint, same surface as `/mcp`.

- No or invalid bearer token → `401`, `WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp/oauth[/{client}]"`.
- `{client}` not a known client id → `404` (also on its metadata).
- Accepts only `Authorization: Bearer mcp_oat_…`. `X-API-Key`, `?apikey=`, `mcp_cli_`, `mcp_agt_` and the admin key → `401`.
- Token for another resource or origin → `401`.

## `GET /.well-known/oauth-protected-resource/mcp/oauth[/{client}]`

```json
{
"resource": "<origin>/mcp/oauth/cursor",
"authorization_servers": ["<origin>"],
"bearer_methods_supported": ["header"]
}
```

## `GET /.well-known/oauth-authorization-server`

```json
{
"issuer": "<origin>",
"authorization_endpoint": "<origin>/oauth/authorize",
"token_endpoint": "<origin>/oauth/token",
"registration_endpoint": "<origin>/oauth/register",
"response_types_supported": ["code"],
"grant_types_supported": ["authorization_code", "refresh_token"],
"code_challenge_methods_supported": ["S256"],
"token_endpoint_auth_methods_supported": ["none"]
}
```

## `POST /oauth/register` (RFC 7591)

Request (JSON, at most 16 KiB): `redirect_uris` (required), `client_name`, `software_id`, `software_version`, optional `token_endpoint_auth_method`, `grant_types`, `response_types`.

- `201`: `client_id`, `client_id_issued_at`, `redirect_uris`, `client_name` (sanitised), `token_endpoint_auth_method: "none"`, `grant_types: ["authorization_code","refresh_token"]`, `response_types: ["code"]`. No `client_secret`.
- `400 invalid_redirect_uri`: not loopback `http` and not `https`, has a fragment, more than 5.
- `400 invalid_client_metadata`: an auth method other than `none`, a grant type or response type outside the lists above.
- `429` with `Retry-After`.

## `GET /oauth/authorize`

Query: `response_type=code`, `client_id`, `redirect_uri`, `code_challenge`, `code_challenge_method=S256`, `resource`, `state` (optional), `scope` (ignored).

- Unknown `client_id` or `redirect_uri` not registered (loopback port ignored) → `400` HTML error page, **no redirect**.
- `resource` is `<origin>/mcp/oauth/{client}` with a client id that does not exist → `404` HTML page, **no redirect** (FR-015). Checked before the general `resource` rule.
- Other errors → redirect to `redirect_uri` with `error` (`invalid_request`, `unsupported_response_type`, `invalid_target`, `temporarily_unavailable`) and `state`.
- Any other `resource` that is not `<origin>/mcp/oauth` or `<origin>/mcp/oauth/{known client}` → `invalid_target`.
- Success → `302` to `<origin>/ui/authorize?request=<id>`. Headers on every answer: `Cache-Control: no-store`, `Referrer-Policy: no-referrer`.

After the administrator decides (admin REST), the browser is sent to:

- approve: the stored redirect URI with `code` added
- deny: the stored redirect URI with `error=access_denied` added

Every redirect (these two and the error redirects above) is built by parsing the stored redirect URI, keeping its existing query, and appending percent-encoded parameters. `state` is added only if the client sent one, with its value unchanged.

## `POST /oauth/token`

Form-encoded, at most 16 KiB. Answers carry `Cache-Control: no-store`.

The origin of the token request must equal the issuer stored with the code or the grant. This is checked first, for both grant types: on a mismatch the answer is `invalid_grant` and nothing is consumed, rotated or revoked.

The authorization-code exchange is where the login is stored (data-model, research R15). If the client's binding changed since approval, or the binding guard now refuses it, the answer is `invalid_grant` and nothing is stored.

**`grant_type=authorization_code`**: `code`, `redirect_uri`, `client_id`, `code_verifier`, `resource` (optional; if present must equal the approved one).

**`grant_type=refresh_token`**: `refresh_token`, `client_id`, `resource` (optional, same rule).

`200`:

```json
{ "access_token": "mcp_oat_…", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "mcp_ort_…" }
```

Errors (`400` JSON `{error, error_description}`):

| Case | `error` | Side effect |
|---|---|---|
| unknown, expired or already used code; wrong verifier, client or redirect URI | `invalid_grant` | a code reused within 10 minutes revokes the grant it produced |
| request origin differs from the stored issuer | `invalid_grant` | none |
| binding changed or guard refuses at exchange | `invalid_grant` | none; `deny` activity row |
| request cancelled after approval (client revoked or forgotten, feature turned off) | `invalid_grant` | none |
| registration no longer exists, or the new client id chosen at approval now exists | `invalid_grant` | none |
| refresh token malformed, bad MAC, unknown, revoked or expired grant, wrong `client_id` | `invalid_grant` | **none**; all indistinguishable; an expired login is never extended |
| authentic refresh token that is not the current one | `invalid_grant` | grant revoked (`replay`) |
| `resource` differs from the approved one | `invalid_target` | none |
| other grant type | `unsupported_grant_type` | none |
| over the rate limit | `429` + `Retry-After` | none |

## Token formats

- Access: `mcp_oat_<43 base64url chars>`; lifetime 3600 s.
- Refresh: `mcp_ort_<grant id>_<secret>_<mac>`; lifetime 30 days from last rotation.
121 changes: 121 additions & 0 deletions specs/132-client-oauth-login/contracts/rest-admin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Contract: administrator surfaces

All REST routes are under `/api/v1`, use the standard `{success, data}` envelope, require administrator credentials (admin API key or tray socket) and answer `403` to agent tokens and client credentials. With the feature off the sign-in request routes answer `404 feature_disabled`. Client payloads depend on whether the feature was ever used: never used → exactly today's payload, no new fields; used → the new fields are present and logins are listed. `browser_login_disabled` reflects only whether the feature is off right now: `false` while on, `true` while off after use. Revoking a login works in both on and off-after-use states.

## Sign-in requests

### `GET /oauth/authorizations`

Pending requests, newest first: `[{id, client_label, created_at, expires_at}]`. Used by the tray and by Home.

### `GET /oauth/authorizations/{id}`

```jsonc
{
"id": "…",
"status": "pending",
"expires_at": "…",
"reported_name": "Cursor IDE", // unverified, sanitised
"redirect_uri": "http://127.0.0.1:54321/callback",
"resource": "http://127.0.0.1:8080/mcp/oauth/cursor",
"address_kind": "client", // "client" | "generic"
"client": { // present when address_kind = client
"id": "cursor", "display_name": "Cursor", "exists": true,
"has_api_key": true, "logins": 1,
"binding": { "profile": "dev-readonly", "mode": "locked", "revision": "b1f3…" }
},
"existing_clients": [ /* address_kind = generic: {id, display_name, binding} */ ],
"suggested_new_client": { "id": "acme-agent", "display_name": "Acme Agent" },
"suggested_client": { "id": "cursor", "matched": "display_name" }, // generic only; present when the reported name equals exactly one entry of existing_clients (matched: id | display_name | known_name); absent otherwise
"profiles": [ { "name": "dev-readonly" } ],
"profile_required": true, // profiles exist and the client has no binding
"previous_login": { "grant_id": "…", "approved_at": "…" }, // same registration signed in before
"guard": null // only when the address fixes a client that has a binding; else absent, use preview
}
```

`404` for an unknown, expired, decided or cancelled id (one uniform answer).

`suggested_client` is advice for the page only. It is computed on read from the sanitised reported name (trimmed, compared without regard to case) against each entry of `existing_clients`: its id, its display name and, for a connect-registry client, its known client names. The whole name is tried and, when it ends with a parenthesised suffix, also the part before it. Matches are collected over all fields and counted by distinct client id; exactly one distinct client → present, none or several → absent. `matched` names the first field that matched in the order `id`, `display_name`, `known_name`. Preview and approve take the client from their own body and never fall back to the suggestion: on the generic address, preview without a client answers `200 {"complete": false}` with no `access` and no `guard`, and approve without a client answers `422 client_required`.

### `POST /oauth/authorizations/{id}/preview`

Read-only. Body: the same `client`, `profile`, `mode` as approve. Answer:

```jsonc
{ "complete": true,
"access": { "client": "cursor", "profile": "dev-readonly", "mode": "locked", "same_access_as_existing_client": true },
"guard": null } // or { "code": "binding_bypassable_without_auth", "bindings": [...], "fixes": [...] }
```

`complete: false` (and no verdict) while a required choice is missing. Same `422` codes as approve for an invalid choice. Writes nothing.

### `POST /oauth/authorizations/{id}/approve`

Records the decision and issues the code. The login itself is stored when the client exchanges the code.

```jsonc
{
"client": { "id": "cursor" }, // generic address: existing id, or
// "client": { "new": { "id": "acme-agent", "display_name": "Acme Agent" } },
"profile": "dev-readonly", // "" = All servers; ignored when the client has a binding
"mode": "locked",
"binding_revision": "b1f3…", // required when the client has a binding
"replace_grant": "…" // optional: the previous_login grant id
}
```

- `200 {redirect_url}`: the page navigates there.
- `409 already_decided`.
- `409 binding_changed`: the binding differs from `binding_revision`; reload.
- `409 binding_bypassable_without_auth`: body as the existing guard refusal.
- `422 client_required` (generic address, no client in the body), `422 profile_required`, `422 client_fixed` (a client other than the one in the address), `422 identity_exists` / `reserved_identity` for a new client id, `404 profile_not_found`.

### `POST /oauth/authorizations/{id}/deny`

`200 {redirect_url}` (carries `error=access_denied`). `409 already_decided`.

## Logins on clients

- `GET /clients` and `GET /clients/{client}`: each client gains

```jsonc
"credentials": [
{ "kind": "api_key", "prefix": "mcp_cli_ab12", "state": "active", "expires_at": "…", "last_used_at": "…" },
{ "kind": "browser_login", "grant_id": "…", "state": "active", // active | lapsed | revoked
"approved_at": "…", "last_used_at": "…", "reported_name": "Cursor IDE", "redirect_host": "127.0.0.1",
"observed_name": "cursor-vscode", "name_mismatch": false }
],
"browser_login_disabled": false
```

- `DELETE /clients/{client}/logins/{grant_id}`: revoke one login. `200 {changed}`; `404` unknown.
- `DELETE /clients/{client}/api-key`: revoke the API key alone; the client's logins and binding stay. `404` when the client has no API key.
- Existing `DELETE /clients/{client}` (forget) and the revoke path: cascade to all logins.
- `PUT /clients/{client}/binding`, `POST /clients/bulk-assign`: work for clients that have only browser logins.

## SSE (admin-only)

- `oauth.authorization_pending` `{request_id, client_id, client_label}`
- `oauth.authorization_decided` `{request_id, status}`
- `credentials.changed` (existing) with `kind: "browser_login"`, `change: issue | revoke | replay_revoke`

## Activity

`profile_change` rows with `change` = `approve` | `deny` | `issue` | `revoke` | `replay_revoke`, metadata `client_id`, `request_id` (rows written before a login exists: `approve`, `deny`), `grant_id` (rows about a stored login: `issue`, `revoke`, `replay_revoke`), `profile`, `actor_kind`, `actor_name`, `surface`. `approve`, `revoke` and a `deny` clicked on the page name the administrator who made the request. Rows written on the public token endpoint (`issue`, `replay_revoke`, and a `deny` caused by the re-check at exchange) name the administrator who approved (`approved_by`) and add `trigger: "client"`. Tool-call rows of a browser login carry `client_id` and `metadata.grant_id`, credential kind `oauth`.

## MCP `credentials` tool

- `list` (`kind` gains `browser_login`), `get client=<id>`: include logins with the fields above.
- `revoke client=<id>`: everything under the client. `revoke client=<id> grant=<grant_id>`: one login.
- No operation creates a login.

## CLI

- `mcpproxy client show <id>`: lists credentials.
- `mcpproxy client revoke-login <id> <grant-id>`.
- `mcpproxy connect <client> --auth key|oauth` (PR-3); `oauth` is refused with a clear message when the feature is off or the client is not marked as supporting it.

## Config

`mcp_oauth_enabled` (bool, default false, hot), env `MCPPROXY_MCP_OAUTH_ENABLED`.
Loading
Loading