MCPcopy Create free account
hub / github.com/echoVic/blade-code / connectWebSocket

Method connectWebSocket

src/mcp/client/MCPClient.ts:239–265  ·  view source on GitHub ↗

* WebSocket 连接

(config: MCPConnectionConfig)

Source from the content-addressed store, hash-verified

237 * WebSocket 连接
238 */
239 private async connectWebSocket(config: MCPConnectionConfig): Promise<WebSocket> {
240 if (!config.endpoint) {
241 throw new Error('WebSocket endpoint is required');
242 }
243
244 const ws = new WebSocket(config.endpoint);
245
246 return new Promise((resolve, reject) => {
247 const timeout = setTimeout(() => {
248 reject(new Error('Connection timeout'));
249 }, config.timeout || 10000);
250
251 ws.on('open', () => {
252 clearTimeout(timeout);
253 resolve(ws);
254 });
255
256 ws.on('error', (error: Error) => {
257 clearTimeout(timeout);
258 reject(error);
259 });
260
261 ws.on('message', (data: Buffer) => {
262 this.handleMessage(data.toString());
263 });
264 });
265 }
266
267 /**
268 * Stdio 连接

Callers 1

connectMethod · 0.95

Calls 2

handleMessageMethod · 0.95
onMethod · 0.45

Tested by

no test coverage detected