Skip to content

Commit 638d404

Browse files
all: stabilize client OAuth support (#861)
Also fix lint errors that were hidden because of the build tag.
1 parent c1a12cf commit 638d404

34 files changed

+387
-915
lines changed

.github/workflows/conformance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
uses: modelcontextprotocol/conformance@a2855b03582a6c0b31065ad4d9af248316ce61a3 # v0.1.15
5151
with:
5252
mode: client
53-
command: go run -tags mcp_go_client_oauth ./conformance/everything-client
53+
command: go run ./conformance/everything-client
5454
suite: core
5555
expected-failures: ./conformance/baseline.yml
5656
node-version: 22

auth/authorization_code.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by the license
33
// that can be found in the LICENSE file.
44

5-
//go:build mcp_go_client_oauth
6-
75
package auth
86

97
import (
@@ -142,7 +140,7 @@ func NewAuthorizationCodeHandler(config *AuthorizationCodeHandlerConfig) (*Autho
142140
dCfg := config.DynamicClientRegistrationConfig
143141
if dCfg != nil {
144142
if dCfg.Metadata == nil {
145-
return nil, errors.New("Metadata is required for dynamic client registration")
143+
return nil, errors.New("dynamic client registration requires non-nil Metadata")
146144
}
147145
if len(dCfg.Metadata.RedirectURIs) == 0 {
148146
return nil, errors.New("Metadata.RedirectURIs is required for dynamic client registration")
@@ -283,17 +281,14 @@ func errorFromChallenges(cs []oauthex.Challenge) string {
283281
// If no metadata was found or the fetched metadata fails security checks,
284282
// it returns an error.
285283
func (h *AuthorizationCodeHandler) getProtectedResourceMetadata(ctx context.Context, wwwChallenges []oauthex.Challenge, mcpServerURL string) (*oauthex.ProtectedResourceMetadata, error) {
286-
var errs []error
287284
// Use MCP server URL as the resource URI per
288285
// https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization#canonical-server-uri.
289286
for _, url := range protectedResourceMetadataURLs(resourceMetadataURLFromChallenges(wwwChallenges), mcpServerURL) {
290287
prm, err := oauthex.GetProtectedResourceMetadata(ctx, url.URL, url.Resource, h.config.Client)
291288
if err != nil {
292-
errs = append(errs, err)
293289
continue
294290
}
295291
if prm == nil {
296-
errs = append(errs, fmt.Errorf("protected resource metadata is nil"))
297292
continue
298293
}
299294
if len(prm.AuthorizationServers) == 0 {

auth/authorization_code_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by the license
33
// that can be found in the LICENSE file.
44

5-
//go:build mcp_go_client_oauth
6-
75
package auth
86

97
import (

auth/client_private.go

Lines changed: 0 additions & 135 deletions
This file was deleted.

auth/client_test.go

Lines changed: 0 additions & 153 deletions
This file was deleted.

auth/extauth/enterprise_handler.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Package extauth provides OAuth handler implementations for MCP authorization extensions.
66
// This package implements Enterprise Managed Authorization as defined in SEP-990.
77

8-
//go:build mcp_go_client_oauth
9-
108
package extauth
119

1210
import (

auth/extauth/enterprise_handler_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// Use of this source code is governed by an MIT-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build mcp_go_client_oauth
6-
75
package extauth
86

97
import (

auth/extauth/oidc_login.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// as part of Enterprise Managed Authorization (SEP-990).
77
// See https://openid.net/specs/openid-connect-core-1_0.html
88

9-
//go:build mcp_go_client_oauth
10-
119
package extauth
1210

1311
import (
@@ -121,11 +119,11 @@ func initiateOIDCLogin(
121119
return nil, nil, fmt.Errorf("RedirectURL is required")
122120
}
123121
if len(config.Scopes) == 0 {
124-
return nil, nil, fmt.Errorf("Scopes is required (must include 'openid')")
122+
return nil, nil, fmt.Errorf("at least one scope is required (must include 'openid')")
125123
}
126124

127125
if !slices.Contains(config.Scopes, "openid") {
128-
return nil, nil, fmt.Errorf("Scopes must include 'openid' for OIDC")
126+
return nil, nil, fmt.Errorf("the 'openid' scope is required for OIDC")
129127
}
130128

131129
if err := checkURLScheme(config.IssuerURL); err != nil {

0 commit comments

Comments
 (0)