| name | mcp-transport-websocket-setup |
| description | Configure WebSocket transport for bidirectional MCP communication with connection management and reconnection handling. |
| allowed-tools | Read, Write, Edit, Bash, Glob, Grep |
| graph | {"domains":["domain:software-engineering"],"specializations":["specialization:cli-mcp-development"],"skillAreas":["skill-area:cli-design","skill-area:mcp-server-implementation","skill-area:mcp-sse-transport"],"roles":["role:backend-engineer","role:platform-engineer"],"workflows":["workflow:feature-development"],"topics":["topic:developer-experience"]} |
MCP Transport WebSocket Setup
Configure WebSocket transport for bidirectional MCP communication.
Capabilities
- Configure WebSocket transport for MCP
- Implement connection lifecycle management
- Set up reconnection with backoff
- Handle message framing
- Implement heartbeat/ping-pong
- Configure secure WebSocket (WSS)
Usage
Invoke this skill when you need to:
- Set up bidirectional MCP communication
- Implement WebSocket-based MCP transport
- Configure connection management
- Enable real-time bidirectional messaging
Inputs
| Parameter | Type | Required | Description |
|---|
| language | string | Yes | Target language |
| server | boolean | No | Generate server code (default: true) |
| client | boolean | No | Generate client code (default: false) |
| secure | boolean | No | Use WSS (default: true) |
Generated Patterns
TypeScript WebSocket Server
import { WebSocketServer, WebSocket } from 'ws';
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
interface Connection {
ws: WebSocket;
server: Server;
lastPing: number;
}
const connections = new Map<string, Connection>();
const wss = new WebSocketServer({
port: parseInt(process.env.WS_PORT || '8080'),
path: '/mcp',
});
const HEARTBEAT_INTERVAL = 30000;
wss.on('connection', (ws, req) => {
const connectionId = crypto.randomUUID();
console.log(`New connection: ${connectionId}`);
const server = new Server(
{ name: , : },
{ : { : {}, : {} } }
);
(server);
connections.(connectionId, {
ws,
server,
: .(),
});
ws.(, (data) => {
{
message = .(data.());
(connectionId, message);
} (error) {
.(, error);
ws.(.({
: ,
: { : -, : },
}));
}
});
ws.(, {
.();
connections.(connectionId);
});
ws.(, {
.(, error);
});
ws.(, {
conn = connections.(connectionId);
(conn) conn. = .();
});
});
( {
now = .();
connections.( {
(now - conn. > * ) {
.();
conn..();
connections.(id);
} {
conn..();
}
});
}, );
() {
conn = connections.(connectionId);
(!conn) ;
}
.();
TypeScript WebSocket Client
import WebSocket from 'ws';
interface MCPClientOptions {
url: string;
reconnect?: boolean;
maxRetries?: number;
}
class MCPWebSocketClient {
private ws: WebSocket | null = null;
private reconnectAttempts = 0;
private maxRetries: number;
private reconnectDelay = 1000;
constructor(private options: MCPClientOptions) {
this.maxRetries = options.maxRetries ?? 5;
}
async connect(): Promise<void> {
return new Promise((resolve, reject) => {
this.ws = new WebSocket(this.options.url);
this.ws.(, {
.();
. = ;
. = ;
();
});
..(, {
message = .(data.());
.(message);
});
..(, {
.();
(..) {
.();
}
});
..(, {
.(, error);
(error);
});
});
}
() {
(. >= .) {
.();
;
}
.++;
delay = . * .(, . - );
.();
( {
.().( {
});
}, delay);
}
(: ): <> {
(!. || .. !== .) {
();
}
..(.(message));
}
() {
.(, message);
}
() {
.. = ;
.?.();
}
}
Workflow
- Configure server - WebSocket server setup
- Add handlers - Message processing
- Implement heartbeat - Connection health
- Add reconnection - Client reconnection
- Configure security - WSS setup
- Add monitoring - Connection metrics
Target Processes
- mcp-transport-layer
- mcp-server-bootstrap
- mcp-client-implementation