(port: string)
| 369 | } |
| 370 | |
| 371 | private async establishConnection(port: string): Promise<boolean> { |
| 372 | let transport: StreamableHTTPClientTransport | undefined; |
| 373 | try { |
| 374 | this.client = new Client({ |
| 375 | name: 'streamable-http-client', |
| 376 | // TODO(#3487): use the CLI version here. |
| 377 | version: '1.0.0', |
| 378 | }); |
| 379 | transport = new StreamableHTTPClientTransport( |
| 380 | new URL(`http://${getIdeServerHost()}:${port}/mcp`), |
| 381 | ); |
| 382 | await this.client.connect(transport); |
| 383 | this.registerClientHandlers(); |
| 384 | this.setState(IDEConnectionStatus.Connected); |
| 385 | return true; |
| 386 | } catch (_error) { |
| 387 | if (transport) { |
| 388 | try { |
| 389 | await transport.close(); |
| 390 | } catch (closeError) { |
| 391 | logger.debug('Failed to close transport:', closeError); |
| 392 | } |
| 393 | } |
| 394 | logger.error(`Failed to connect: ${_error}`); |
| 395 | return false; |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | function getIdeServerHost() { |
no test coverage detected