* Sends a JSON-RPC message over the WebSocket connection.
(message: JSONRPCMessage)
| 171 | * Sends a JSON-RPC message over the WebSocket connection. |
| 172 | */ |
| 173 | async send(message: JSONRPCMessage): Promise<void> { |
| 174 | if (this.ws.readyState !== WS_OPEN) { |
| 175 | logForDiagnosticsNoPII('error', 'mcp_websocket_send_not_opened') |
| 176 | throw new Error('WebSocket is not open. Cannot send message.') |
| 177 | } |
| 178 | const json = jsonStringify(message) |
| 179 | |
| 180 | try { |
| 181 | if (this.isBun) { |
| 182 | // Native WebSocket.send() is synchronous (no callback) |
| 183 | this.ws.send(json) |
| 184 | } else { |
| 185 | await new Promise<void>((resolve, reject) => { |
| 186 | ;(this.ws as unknown as WsWebSocket).send(json, error => { |
| 187 | if (error) { |
| 188 | reject(error) |
| 189 | } else { |
| 190 | resolve() |
| 191 | } |
| 192 | }) |
| 193 | }) |
| 194 | } |
| 195 | } catch (error) { |
| 196 | this.handleError(error) |
| 197 | throw error |
| 198 | } |
| 199 | } |
| 200 | } |
nothing calls this directly
no test coverage detected