createStreamableHttpTransportAsync static method

Future<Result<StreamableHttpServerTransport, Exception>> createStreamableHttpTransportAsync(
  1. int port, {
  2. String endpoint = '/mcp',
  3. String host = 'localhost',
  4. List<int>? fallbackPorts,
  5. bool isJsonResponseEnabled = false,
  6. String? sessionId,
  7. String? authToken,
})

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'));
  }
}