create static method
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,
);
}