create static method

Future<StreamableHttpClientTransport> create({
  1. required String baseUrl,
  2. OAuthConfig? oauthConfig,
  3. Map<String, String>? headers,
  4. Duration? timeout,
  5. int? maxConcurrentRequests,
  6. bool? useHttp2,
  7. Client? httpClient,
  8. bool terminateOnClose = true,
})

Create a new Streamable HTTP transport

Implementation

static Future<StreamableHttpClientTransport> create({
  required String baseUrl,
  OAuthConfig? oauthConfig,
  Map<String, String>? headers,
  Duration? timeout,
  int? maxConcurrentRequests,
  bool? useHttp2,
  http.Client? httpClient,
  bool terminateOnClose = true,  // Default: true for backward compatibility
}) async {
  final config = StreamableHttpTransportConfig(
    baseUrl: baseUrl,
    oauthConfig: oauthConfig,
    headers: headers ?? const {},
    timeout: timeout ?? const Duration(seconds: 30),
    maxConcurrentRequests: maxConcurrentRequests ?? 10,
    useHttp2: useHttp2 ?? true,
    terminateOnClose: terminateOnClose,
  );

  final client =
      httpClient ??
      (config.useHttp2
          ? http.Client()
          : // Use default client
          http.Client());

  HttpOAuthClient? oauthClient;
  OAuthTokenManager? tokenManager;

  if (oauthConfig != null) {
    oauthClient = HttpOAuthClient(config: oauthConfig, httpClient: client);
    tokenManager = OAuthTokenManager(oauthClient);
  }

  return StreamableHttpClientTransport._(
    config: config,
    httpClient: client,
    oauthClient: oauthClient,
    tokenManager: tokenManager,
  );
}