@@ -17,6 +17,7 @@ import (
1717 mcpsdk "github.com/modelcontextprotocol/go-sdk/mcp"
1818 "golang.org/x/oauth2"
1919
20+ "github.com/docker/docker-agent/pkg/config/latest"
2021 "github.com/docker/docker-agent/pkg/tools"
2122)
2223
@@ -135,7 +136,8 @@ func validateAndFillDefaults(metadata *AuthorizationServerMetadata, authServerUR
135136
136137 metadata .AuthorizationEndpoint = cmp .Or (metadata .AuthorizationEndpoint , authServerURL + "/authorize" )
137138 metadata .TokenEndpoint = cmp .Or (metadata .TokenEndpoint , authServerURL + "/token" )
138- metadata .RegistrationEndpoint = cmp .Or (metadata .RegistrationEndpoint , authServerURL + "/register" )
139+ // Do NOT fabricate a registration_endpoint — if the server doesn't
140+ // advertise one, dynamic client registration is not supported.
139141
140142 return metadata
141143}
@@ -146,7 +148,6 @@ func createDefaultMetadata(authServerURL string) *AuthorizationServerMetadata {
146148 Issuer : authServerURL ,
147149 AuthorizationEndpoint : authServerURL + "/authorize" ,
148150 TokenEndpoint : authServerURL + "/token" ,
149- RegistrationEndpoint : authServerURL + "/register" ,
150151 ResponseTypesSupported : []string {"code" },
151152 ResponseModesSupported : []string {"query" , "fragment" },
152153 GrantTypesSupported : []string {"authorization_code" },
@@ -168,10 +169,11 @@ func resourceMetadataFromWWWAuth(wwwAuth string) string {
168169type oauthTransport struct {
169170 base http.RoundTripper
170171 // TODO(rumpl): remove client reference, we need to find a better way to send elicitation requests
171- client * remoteMCPClient
172- tokenStore OAuthTokenStore
173- baseURL string
174- managed bool
172+ client * remoteMCPClient
173+ tokenStore OAuthTokenStore
174+ baseURL string
175+ managed bool
176+ oauthConfig * latest.RemoteOAuthConfig
175177
176178 // mu protects refreshFailedAt from concurrent access.
177179 mu sync.Mutex
@@ -331,7 +333,11 @@ func (t *oauthTransport) handleManagedOAuthFlow(ctx context.Context, authServer,
331333 }
332334
333335 slog .Debug ("Creating OAuth callback server" )
334- callbackServer , err := NewCallbackServer ()
336+ var callbackPort int
337+ if t .oauthConfig != nil {
338+ callbackPort = t .oauthConfig .CallbackPort
339+ }
340+ callbackServer , err := NewCallbackServerOnPort (callbackPort )
335341 if err != nil {
336342 return fmt .Errorf ("failed to create callback server: %w" , err )
337343 }
@@ -352,18 +358,26 @@ func (t *oauthTransport) handleManagedOAuthFlow(ctx context.Context, authServer,
352358
353359 var clientID string
354360 var clientSecret string
355-
356- if authServerMetadata .RegistrationEndpoint != "" {
361+ var scopes []string
362+
363+ switch {
364+ case t .oauthConfig != nil && t .oauthConfig .ClientID != "" :
365+ // Use explicit credentials from config
366+ slog .Debug ("Using explicit OAuth credentials from config" )
367+ clientID = t .oauthConfig .ClientID
368+ clientSecret = t .oauthConfig .ClientSecret
369+ scopes = t .oauthConfig .Scopes
370+ case authServerMetadata .RegistrationEndpoint != "" :
357371 slog .Debug ("Attempting dynamic client registration" )
358372 clientID , clientSecret , err = RegisterClient (ctx , authServerMetadata , redirectURI , nil )
359373 if err != nil {
360374 slog .Debug ("Dynamic registration failed" , "error" , err )
361375 // TODO(rumpl): fall back to requesting client ID from user
362376 return err
363377 }
364- } else {
378+ default :
365379 // TODO(rumpl): fall back to requesting client ID from user
366- return errors .New ("authorization server does not support dynamic client registration" )
380+ return errors .New ("authorization server does not support dynamic client registration and no explicit OAuth credentials configured " )
367381 }
368382
369383 state , err := GenerateState ()
@@ -381,6 +395,7 @@ func (t *oauthTransport) handleManagedOAuthFlow(ctx context.Context, authServer,
381395 state ,
382396 oauth2 .S256ChallengeFromVerifier (verifier ),
383397 t .baseURL ,
398+ scopes ,
384399 )
385400
386401 result , err := t .client .requestElicitation (ctx , & mcpsdk.ElicitParams {
0 commit comments