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

Method performHandshake

src/mcp/client/MCPClient.ts:318–361  ·  view source on GitHub ↗

* 执行握手

(sessionId: string)

Source from the content-addressed store, hash-verified

316 * 执行握手
317 */
318 private async performHandshake(sessionId: string): Promise<void> {
319 try {
320 const response = await this.sendRequest(sessionId, {
321 method: 'initialize',
322 params: {
323 protocolVersion: '2024-11-05',
324 capabilities: this.clientInfo.capabilities,
325 clientInfo: {
326 name: this.clientInfo.name,
327 version: this.clientInfo.version,
328 },
329 },
330 });
331
332 const session = this.sessions.get(sessionId);
333 if (session) {
334 session.serverInfo = {
335 name: response.serverInfo?.name || 'Unknown',
336 version: response.serverInfo?.version || '0.0.0',
337 capabilities: response.capabilities || {},
338 };
339 }
340
341 // 发送初始化完成通知
342 const connection = this.connections.get(sessionId);
343 if (connection instanceof WebSocket) {
344 connection.send(
345 JSON.stringify({
346 jsonrpc: '2.0',
347 method: 'notifications/initialized',
348 })
349 );
350 } else {
351 connection.stdin?.write(
352 JSON.stringify({
353 jsonrpc: '2.0',
354 method: 'notifications/initialized',
355 }) + '\n'
356 );
357 }
358 } catch (error) {
359 throw new Error(`Handshake failed: ${error}`);
360 }
361 }
362}

Callers 1

connectMethod · 0.95

Calls 2

sendRequestMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected