createStreamableHttpTransportAsync static method
Create a StreamableHTTP transport with the given configuration
Implementation
static Future<Result<StreamableHttpServerTransport, Exception>> createStreamableHttpTransportAsync(
int port, {
String endpoint = '/mcp',
String host = 'localhost',
List<int>? fallbackPorts,
bool isJsonResponseEnabled = false,
String? sessionId,
String? authToken,
}) async {
try {
final transport = StreamableHttpServerTransport(
config: StreamableHttpServerConfig(
endpoint: endpoint,
port: port,
host: host,
fallbackPorts: fallbackPorts ?? [port + 1, port + 2, port + 3],
isJsonResponseEnabled: isJsonResponseEnabled,
authToken: authToken,
),
);
// Start the server and wait for it to be ready
await transport.start();
return Result.success(transport);
} catch (e) {
return Result.failure(Exception('Failed to create StreamableHTTP transport: $e'));
}
}