mcp_io_websocket

WebSocket adapter for mcp_io — bidirectional text / binary streams with RFC 6455 close codes, heartbeat, and exponential-backoff reconnect.

Capability matrix

Area Support
Frames Text (UTF-8), binary, ping, pong, close (fragmentation handled by the underlying transport)
Transport Pluggable WebSocketTransport; ws:// (80) / wss:// (443) supplied by host project
Heartbeat Optional Heartbeat (pingInterval + pongTimeout) — fires onPing callback at interval, fires close on missing pong
Reconnect Optional Reconnector — exponential backoff + jitter, maxBackoff cap, manual cancel()
Close codes RFC 6455 1000..1015 standard + 4000..4999 application range, mapped to IoError
Capabilities ws.send_text, ws.send_binary, ws.subscribe (legacy send retained for BC)

Quick start

import 'package:mcp_io_websocket/mcp_io_websocket.dart';

final adapter = WebSocketIoAdapter(
  deviceId: 'ws-1',
  endpoint: Uri.parse('wss://stream.example.com'),
  transport: InMemoryWebSocketTransport(), // production: dart:io WebSocket wrapper
  heartbeat: Heartbeat(
    pingInterval: const Duration(seconds: 30),
    pongTimeout: const Duration(seconds: 10),
    onPing: () {/* transport.sendPing() */},
  ),
  reconnector: Reconnector(
    maxAttempts: 5,
    initialBackoff: const Duration(seconds: 1),
    maxBackoff: const Duration(seconds: 30),
  ),
);
await adapter.connect();

await adapter.execute(const Command(
  action: 'ws.send_text',
  target: '',
  args: {'message': 'hello'},
));

final stream = adapter.subscribe(const TopicSpec(uri: '*'));
stream.listen((env) => print(env.payload.value));

License

MIT — see LICENSE.

Libraries

mcp_io_websocket
WebSocket adapter for mcp_io.