Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2306fb8
feat(oauth): opt-in switch and default-off gate for browser login (Sp…
Dumbris Nov 22, 2026
e0dc9b9
fix(oauth): refuse browser login in every server-edition build (Spec …
Dumbris Nov 22, 2026
bfcc550
feat(oauth): protocol logic for browser login (Spec 132 PR-1b)
Dumbris Nov 22, 2026
1251d0a
fix(oauth): tighten redirect matching and bound in-memory state (Spec…
Dumbris Nov 22, 2026
fb7d861
fix(oauth): align code and request expiry, make limiter admission ato…
Dumbris Nov 22, 2026
8f51f22
feat(oauth): storage for browser logins and one binding writer (Spec …
Dumbris Nov 22, 2026
6d74c98
test(oauth): scope the no-storage check to browser-login state (Spec …
Dumbris Nov 22, 2026
143494c
fix(oauth): harden browser-login storage after review (Spec 132 PR-1c)
Dumbris Nov 22, 2026
8ecda0a
fix(oauth): validate bindings only where a browser-login copy exists …
Dumbris Nov 22, 2026
5716d19
fix(oauth): restore pins by binding incarnation, keep connect snapsho…
Dumbris Nov 22, 2026
3bd6cdd
Merge remote-tracking branch 'origin/feat/client-oauth-login-switch' …
Dumbris Nov 22, 2026
f51b746
feat(oauth): browser-login service, client views and guard (Spec 132 …
Dumbris Nov 22, 2026
a592315
fix(oauth): close cancellation, token-endpoint and client-view gaps (…
Dumbris Nov 22, 2026
4981623
fix(oauth): close exchange/approve races and rollback guard gap (Spec…
Dumbris Nov 22, 2026
17c9397
fix(oauth): fence the exchange with config commits, atomic key creati…
Dumbris Nov 22, 2026
0761328
fix(oauth): fence refresh with config commits, complete key-file fall…
Dumbris Nov 22, 2026
dc01d1a
feat(oauth): browser-login endpoints and access-token auth (Spec 132 …
Dumbris Nov 22, 2026
6c66382
fix(oauth): close stream, cross-site and contract gaps after review (…
Dumbris Nov 23, 2026
f08df21
fix(oauth): end blocked streams on revoke, cancel across quick off/on…
Dumbris Nov 23, 2026
b89b95d
fix(oauth): order the disable epoch, per-run stream tracking (Spec 13…
Dumbris Nov 23, 2026
3f8eacb
fix(oauth): bump the disable epoch only on publish, bind streams to a…
Dumbris Nov 23, 2026
5bba11c
Merge origin/main into feat/client-oauth-login-storage
Dumbris Nov 23, 2026
2f17cd2
Merge storage slice and main into feat/client-oauth-login-runtime
Dumbris Nov 23, 2026
7c19092
test(oauth): fixture credential expiry follows the real clock (Spec 1…
Dumbris Nov 23, 2026
5b20ad1
Merge origin/main into feat/client-oauth-login-runtime
Dumbris Nov 23, 2026
a133327
Merge runtime slice and main into feat/client-oauth-login-http
Dumbris Nov 23, 2026
05e5080
test(auth): skip the key-file mode check on Windows (Spec 132 PR-1d)
Dumbris Nov 23, 2026
b90a6f8
test(storage): repin order test no longer depends on hash luck (Spec …
Dumbris Nov 23, 2026
54653b3
Merge runtime slice into feat/client-oauth-login-http
Dumbris Nov 23, 2026
41a51a6
Merge origin/main into feat/client-oauth-login-http
Dumbris Nov 23, 2026
1c10156
fix(server): a stopped run no longer stops or unmarks the next run (S…
Dumbris Nov 23, 2026
bc5ae6f
fix(server): a stop in progress leaves a newly started run alone (Spe…
Dumbris Nov 23, 2026
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
28 changes: 28 additions & 0 deletions docs/api/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,34 @@ profile, anonymous is required`, `400 use client=<id> for a client credential`
(a `client-` token name), `400 access/explain covers upstream tools (server:tool)
only`, `404` for an unknown client, token or profile.

### Browser login for MCP clients (personal edition, opt-in)

Off by default (`mcp_oauth_enabled`). With it off and never used none of this
exists and every payload is unchanged. All routes are administrator-only (an
agent token or a client credential gets `403`); with the feature off the
sign-in request routes answer `404` with `code: feature_disabled`. Full
reference: the Spec 132 contracts.

- `GET /api/v1/oauth/authorizations`, `GET /api/v1/oauth/authorizations/{id}`:
pending sign-in requests and the data the consent view needs. One uniform `404`
for an unknown, expired, decided or cancelled id.
- `POST /api/v1/oauth/authorizations/{id}/preview`: read-only verdict for a
proposed client, profile and mode. `POST .../approve` and `POST .../deny` answer
`{redirect_url}`; approve refuses with `409 already_decided`, `409 binding_changed`,
`409 binding_bypassable_without_auth`, `422 profile_required`, `client_fixed`,
`identity_exists`, `reserved_identity` and `404 profile_not_found`.
- `GET /api/v1/clients` and `GET /api/v1/clients/{client}` gain `credentials[]`
(the API key and each browser login: `kind`, `prefix`, `grant_id`, `state`,
times, `reported_name`, `redirect_host`, `observed_name`, `name_mismatch`) and
`browser_login_disabled` once browser login was used.
- `DELETE /api/v1/clients/{client}/logins/{grant_id}` revokes one login (also
while the feature is off after use); `DELETE /api/v1/clients/{client}/api-key`
revokes the API key alone.

The public OAuth endpoints (`/oauth/register`, `/oauth/authorize`,
`/oauth/token`, `/.well-known/oauth-*`, `/mcp/oauth[/<client>]`) are loopback-only
and are not part of the `/api/v1` API.

### Tokens

`GET /api/v1/tokens` rows add `kind` (`agent` or `client`), `client_id`,
Expand Down
18 changes: 10 additions & 8 deletions internal/httpapi/binding_guard_coverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ var guardedRoutes = map[string]string{

// exemptRoutes: why each cannot change a binding's reach.
var exemptRoutes = map[string]string{
"POST /api/v1/clients/{client}/rotate": "keeps the binding; only swaps the secret",
"POST /api/v1/clients/{client}/rotate/finalize": "promotes a pending secret; the binding is untouched",
"DELETE /api/v1/clients/{client}": "revokes a credential: a binding can only disappear",
"DELETE /api/v1/connect/{client}": "removes a config entry; never grants",
"POST /api/v1/connect/{client}/undo": "restores the previous entry and only revokes a credential the restored config no longer holds",
"POST /api/v1/profiles/try": "nothing is written: a draft is searched, not stored",
"PUT /api/v1/profiles/active": "a UI default only; never enforcement (a live session's selection and every credential's binding are separate)",
"POST /api/v1/config/validate": "validation only; nothing is written",
"POST /api/v1/clients/{client}/rotate": "keeps the binding; only swaps the secret",
"POST /api/v1/clients/{client}/rotate/finalize": "promotes a pending secret; the binding is untouched",
"DELETE /api/v1/clients/{client}": "revokes a credential: a binding can only disappear",
"DELETE /api/v1/clients/{client}/api-key": "revokes the API key alone: the browser logins and the binding stay (Spec 132)",
"DELETE /api/v1/clients/{client}/logins/{grant_id}": "revokes one browser login: a login can only disappear (Spec 132)",
"DELETE /api/v1/connect/{client}": "removes a config entry; never grants",
"POST /api/v1/connect/{client}/undo": "restores the previous entry and only revokes a credential the restored config no longer holds",
"POST /api/v1/profiles/try": "nothing is written: a draft is searched, not stored",
"PUT /api/v1/profiles/active": "a UI default only; never enforcement (a live session's selection and every credential's binding are separate)",
"POST /api/v1/config/validate": "validation only; nothing is written",
}

func inGuardedFamily(route string) bool {
Expand Down
13 changes: 13 additions & 0 deletions internal/httpapi/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ type clientPresence struct {
Lease bool `json:"lease,omitempty"`
ProfileState string `json:"profile_state,omitempty"`

// Spec 132: the client's credentials (API key and browser logins) and
// whether browser login is off right now. Both exist only once browser
// login was used on this install; until then a row is exactly what it was.
//
// Credentials is a pointer so that once the feature was used a row with no
// credential serialises "credentials": [] instead of omitting the field.
Credentials *[]ClientCredential `json:"credentials,omitempty"`
BrowserLoginDisabled *bool `json:"browser_login_disabled,omitempty"`

// resolvedCredential is the classification of the on-demand config read of a
// detail request; never serialised.
resolvedCredential profile.CredentialState
Expand Down Expand Up @@ -271,6 +280,10 @@ func (s *Server) clientRows(ctx context.Context, withSessions bool, detailID str
}

rows = s.decorateClientRows(rows, records, pctx, stats, cfg, now, withSessions, detailID)
rows, err = s.decorateBrowserLogins(rows, cfg)
if err != nil {
return nil, nil, err
}

var warnings []internalRuntime.Warning
if s.clientsService != nil {
Expand Down
172 changes: 172 additions & 0 deletions internal/httpapi/clients_logins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
//go:build !server

package httpapi

import (
"sort"
"time"

"github.com/smart-mcp-proxy/mcpproxy-go/internal/auth"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/config"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/contracts"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/profile"
internalRuntime "github.com/smart-mcp-proxy/mcpproxy-go/internal/runtime"
)

// ClientCredential is one credential of a client in the Clients payloads
// (Spec 132, contracts/rest-admin.md): its API key or one browser login. A
// secret, a hash or a token never appears here, only the display prefix.
type ClientCredential struct {
// Kind is api_key or browser_login.
Kind string `json:"kind"`
Prefix string `json:"prefix,omitempty"`
// GrantID names a browser login.
GrantID string `json:"grant_id,omitempty"`
// State is active|expired|revoked for an API key and active|lapsed|revoked
// for a login.
State string `json:"state"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
ApprovedAt *time.Time `json:"approved_at,omitempty"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
ReportedName string `json:"reported_name,omitempty"`
RedirectHost string `json:"redirect_host,omitempty"`
// ObservedName is the name the client sent at initialize (advisory).
ObservedName string `json:"observed_name,omitempty"`
NameMismatch *bool `json:"name_mismatch,omitempty"`
}

func clientCredentials(in []internalRuntime.ClientCredentialEntry) []ClientCredential {
if in == nil {
return nil
}
out := make([]ClientCredential, 0, len(in))
for i := range in {
e := &in[i]
out = append(out, ClientCredential{
Kind: e.Kind, Prefix: e.Prefix, GrantID: e.GrantID, State: e.State, ExpiresAt: e.ExpiresAt,
ApprovedAt: e.ApprovedAt, LastUsedAt: e.LastUsedAt, ReportedName: e.ReportedName,
RedirectHost: e.RedirectHost, ObservedName: e.ObservedName, NameMismatch: e.NameMismatch,
})
}
return out
}

// decorateBrowserLogins adds the Spec 132 credentials list and
// browser_login_disabled to the client rows, and one row for every client that
// has browser logins but neither a registry entry nor an API-key record. It is
// a no-op until browser login was used on this install (the service returns
// views without credentials then), so a never-used install keeps exactly its
// previous payload.
func (s *Server) decorateBrowserLogins(rows []clientPresence, cfg *config.Config) ([]clientPresence, error) {
if s.clientsService == nil {
return rows, nil
}
views, err := s.clientsService.List()
if err != nil {
return nil, err
}
// Used = the runtime decorated the views (it does so only once the feature
// was used); the flag is the same install-wide value on every view.
var disabled *bool
for i := range views {
if views[i].BrowserLoginDisabled != nil {
disabled = views[i].BrowserLoginDisabled
break
}
}
if disabled == nil {
if len(views) > 0 || !s.browserLoginUsed() {
return rows, nil
}
off := !s.oauthLoginService.Enabled()
disabled = &off
}
titleOf := func(name string) string {
if cfg != nil {
for i := range cfg.Profiles {
if cfg.Profiles[i].Name == name {
return cfg.Profiles[i].Title
}
}
}
return ""
}
profileMissing := func(name string) bool {
if name == "" || cfg == nil {
return false
}
for i := range cfg.Profiles {
if cfg.Profiles[i].Name == name {
return false
}
}
return true
}
source := func(mode string) string {
if mode == auth.ProfileModeLocked {
return string(profile.SourcePin)
}
return string(profile.SourceBinding)
}

seen := map[string]bool{}
for i := range rows {
seen[rows[i].ID] = true
}
ids := make([]string, 0, len(views))
byID := map[string]int{}
for i := range views {
if views[i].Credentials == nil {
continue
}
byID[views[i].ID] = i
ids = append(ids, views[i].ID)
}
sort.Strings(ids)

for i := range rows {
// Every row carries both fields once the feature was used.
empty := []ClientCredential{}
rows[i].Credentials = &empty
rows[i].BrowserLoginDisabled = disabled
vi, ok := byID[rows[i].ID]
if !ok {
continue
}
v := &views[vi]
creds := clientCredentials(v.Credentials)
rows[i].Credentials = &creds
if rows[i].TokenName == "" {
// No API-key record: the binding the row shows is the browser login's.
rows[i].Profile, rows[i].ProfileMode = v.Profile, v.Mode
rows[i].ProfileTitle = titleOf(v.Profile)
rows[i].ProfileMissing = profileMissing(v.Profile)
rows[i].ProfileSource = source(v.Mode)
}
}
for _, id := range ids {
if seen[id] {
continue
}
v := &views[byID[id]]
creds := clientCredentials(v.Credentials)
name := v.DisplayName
if name == "" {
name = id
}
rows = append(rows, clientPresence{
ID: id, DisplayName: name, Kind: "custom", State: contracts.ClientPresenceOther,
CredentialState: profile.CredentialStateNone,
Profile: v.Profile, ProfileMode: v.Mode, ProfileTitle: titleOf(v.Profile),
ProfileMissing: profileMissing(v.Profile), ProfileSource: source(v.Mode),
Credentials: &creds, BrowserLoginDisabled: disabled,
})
}
return rows, nil
}

// browserLoginUsed reports whether browser login was ever used (fail closed on
// an unreadable marker).
func (s *Server) browserLoginUsed() bool {
return s.oauthLoginService != nil && s.oauthLoginService.EverUsed()
}
5 changes: 5 additions & 0 deletions internal/httpapi/clients_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ func (s *Server) registerClientRoutes(r chi.Router) {
r.Post("/clients/{client}/rotate", admin(s.handleRotateClient))
r.Post("/clients/{client}/rotate/finalize", admin(s.handleFinalizeClientRotation))
r.Delete("/clients/{client}", admin(s.handleForgetClient))
// exempt: a revoke only removes access (Spec 132); both work while browser
// login is on and while it is off after use.
r.Delete("/clients/{client}/logins/{grant_id}", admin(s.handleRevokeClientLogin))
r.Delete("/clients/{client}/api-key", admin(s.handleRevokeClientAPIKey))
s.registerOAuthLoginAdminRoutes(r)
}
Loading
Loading