auth: DCR registration omits scopes, causing invalid_scope on strict auth servers
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 68/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- go
- Bereich
- authentication
Rechercherichtung
Beginne mit AuthorizationCodeHandler und verfolge, wie requestedScopes relativ zu handleRegistration und RegisterClient berechnet werden. Prüfe, wie DynamicClientRegistrationConfig.Metadata.Scope zwischen vom Aufrufer bereitgestellten Werten unterscheidet, und verifiziere anschließend, dass erkannte Scopes vor der Autorisierung in den DCR-Metadaten vorhanden sind, während explizite Scope-Werte unverändert bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
When using AuthorizationCodeHandler with DynamicClientRegistrationConfig, the SDK registers the DCR client before computing the scopes it will request during authorization. If the caller doesn't set ClientRegistrationMetadata.Scope the client is registered without any scope restriction. Section 2 of RFC 7591 says:
scope:
String containing a space-separated list of scope values (as
described in Section 3.3 of OAuth 2.0 [RFC6749]) that the client
can use when requesting access tokens. The semantics of values in
this list are service specific. If omitted, an authorization
server MAY register a client with a default set of scopes.
I think the important part being that the server MAY register a client with default scopes but for registration endpoints that aren't exclusively used for MCP, it's hard to know what that default set of scopes would be.
To Reproduce
- Configure an AuthorizationCodeHandler with DynamicClientRegistrationConfig, leaving Metadata.Scope empty
- Connect to an MCP server whose auth server enforces scope restrictions on DCR clients (i.e. the authorization endpoint rejects scopes the client wasn't registered for)
- The server's Protected Resource Metadata advertises scopes_supported
- The 401 response does not include a WWW-Authenticate header with a scope parameter
The SDK discovers the PRM scopes, registers the client without them, then requests authorization with them and the auth server rejects the request.
Expected behavior
The SDK should propagate the discovered scopes into DynamicClientRegistrationConfig.Metadata.Scope before calling RegisterClient, so the client is registered for the same scopes it will request. Callers who explicitly set Scope should not be affected.
Logs
Error: calling "initialize": sending "initialize": rejected by transport: authorization error: invalid_scope: OAuth 2.0 Parameter: scope
Additional context
The fix is to move scope computation above handleRegistration, and set the DCR metadata scope when the caller didn't provide one:
if dcrCfg := h.config.DynamicClientRegistrationConfig; dcrCfg != nil && dcrCfg.Metadata.Scope == "" && len(requestedScopes) > 0 {
dcrCfg.Metadata.Scope = strings.Join(requestedScopes, " ")
}
I believe this would also match what is described in the Scope Selection Strategy section of the specification as well
Reproduced on v1.6.1 and v1.7.0-pre.3. I've made a small change locally that seems to fix the issue I'm seeing. I'm happy to put that up as a PR if that'd be helpful but wanted to confirm the behavior with you first. Thanks!
Edit:
It seems like what I'm describing is what happens with the typescript-sdk. Looks like they are resolving the scopes here. Then registering the DCR client here with those scopes. I don't know what the correct behavior is, but I think there's a difference.
- Vorherrschende Sprache
- Go
- Sterne
- 5.4k
- Forks
- 623
- Ø Merge
- 22 Std. 10 Min.
- Gemergte PRs (30 T.)
- 30
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/go-sdk
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
modelcontextprotocol/go-sdk#1557 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Streamable HTTP (2026-07-28): tools/call with an out-of-range number in arguments fails because extractName decodes Arguments into anyEvtl. wieder frei @beiryu hat das vor 10 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/go-sdk#1534 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Expose generic `SendNotification` on `ServerSession` for custom protocol extensionsEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenneeds investigation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
modelcontextprotocol/go-sdk#745 · 13 Kommentare · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 18/100
modelcontextprotocol/go-sdk#1555 ·
Maintainer antworten meist innerhalb von 1 Tag
-
mcp: 2026-07-28 client runs elicitation and sampling handlers for standalone server requestsEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
modelcontextprotocol/go-sdk#1552 ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/go-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
apache/dubbo-admin#1659 ·
Maintainer antworten meist innerhalb von 8 Tagen
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindEvtl. vergeben @arshil42 hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100