(ctx context.Context, serverURL string, configCtx map[string]any)
| 236 | } |
| 237 | |
| 238 | func runAuthClient(ctx context.Context, serverURL string, configCtx map[string]any) error { |
| 239 | authConfig := &auth.AuthorizationCodeHandlerConfig{ |
| 240 | RedirectURL: "http://localhost:3000/callback", |
| 241 | AuthorizationCodeFetcher: fetchAuthorizationCodeAndState, |
| 242 | // Try client ID metadata document based registration. |
| 243 | ClientIDMetadataDocumentConfig: &auth.ClientIDMetadataDocumentConfig{ |
| 244 | URL: "https://conformance-test.local/client-metadata.json", |
| 245 | }, |
| 246 | // Try dynamic client registration. |
| 247 | DynamicClientRegistrationConfig: &auth.DynamicClientRegistrationConfig{ |
| 248 | Metadata: &oauthex.ClientRegistrationMetadata{ |
| 249 | RedirectURIs: []string{"http://localhost:3000/callback"}, |
| 250 | }, |
| 251 | }, |
| 252 | } |
| 253 | // Try pre-registered client information if provided in the context. |
| 254 | if clientID, ok := configCtx["client_id"].(string); ok { |
| 255 | if clientSecret, ok := configCtx["client_secret"].(string); ok { |
| 256 | authConfig.PreregisteredClient = &oauthex.ClientCredentials{ |
| 257 | ClientID: clientID, |
| 258 | ClientSecretAuth: &oauthex.ClientSecretAuth{ |
| 259 | ClientSecret: clientSecret, |
| 260 | }, |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | authHandler, err := auth.NewAuthorizationCodeHandler(authConfig) |
| 266 | if err != nil { |
| 267 | return fmt.Errorf("failed to create auth handler: %w", err) |
| 268 | } |
| 269 | |
| 270 | session, err := connectToServer(ctx, serverURL, withOAuthHandler(authHandler)) |
| 271 | if err != nil { |
| 272 | return err |
| 273 | } |
| 274 | defer session.Close() |
| 275 | |
| 276 | if _, err := session.ListTools(ctx, nil); err != nil { |
| 277 | return fmt.Errorf("session.ListTools(): %v", err) |
| 278 | } |
| 279 | |
| 280 | if _, err := session.CallTool(ctx, &mcp.CallToolParams{ |
| 281 | Name: "test-tool", |
| 282 | Arguments: map[string]any{}, |
| 283 | }); err != nil { |
| 284 | return fmt.Errorf("session.CallTool('test-tool'): %v", err) |
| 285 | } |
| 286 | |
| 287 | return nil |
| 288 | } |
| 289 | |
| 290 | // ============================================================================ |
| 291 | // Main entry point |
nothing calls this directly
no test coverage detected
searching dependent graphs…