MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / runAuthClient

Function runAuthClient

conformance/everything-client/main.go:238–288  ·  view source on GitHub ↗
(ctx context.Context, serverURL string, configCtx map[string]any)

Source from the content-addressed store, hash-verified

236}
237
238func 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

Callers

nothing calls this directly

Calls 6

connectToServerFunction · 0.85
withOAuthHandlerFunction · 0.85
ListToolsMethod · 0.80
CallToolMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…