* Create a ws.WebSocket client with the MCP protocol. * Bun's ws shim types lack the 3-arg constructor (url, protocols, options) * that the real ws package supports, so we cast the constructor here.
( url: string, options: Record<string, unknown>, )
| 434 | * that the real ws package supports, so we cast the constructor here. |
| 435 | */ |
| 436 | async function createNodeWsClient( |
| 437 | url: string, |
| 438 | options: Record<string, unknown>, |
| 439 | ): Promise<WsClientLike> { |
| 440 | const wsModule = await import('ws') |
| 441 | const WS = wsModule.default as unknown as new ( |
| 442 | url: string, |
| 443 | protocols: string[], |
| 444 | options: Record<string, unknown>, |
| 445 | ) => WsClientLike |
| 446 | return new WS(url, ['mcp'], options) |
| 447 | } |
| 448 | |
| 449 | const IMAGE_MIME_TYPES = new Set([ |
| 450 | 'image/jpeg', |