summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorShreya Keshive <[email protected]>2025-07-25 21:57:34 -0400
committerGitHub <[email protected]>2025-07-26 01:57:34 +0000
commit771cb229abc89a5bfd225d5f80e58eb47f824086 (patch)
tree75bb52b82854f91671f277953aa452218ddd3e8c /packages/core/src
parentca5dd28ab60d78f42150460cbe9d4ed58d40afe4 (diff)
fix: Clean up transport on IDE connection failure (#4902)
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/ide/ide-client.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/packages/core/src/ide/ide-client.ts b/packages/core/src/ide/ide-client.ts
index eeed60b2..3f91f386 100644
--- a/packages/core/src/ide/ide-client.ts
+++ b/packages/core/src/ide/ide-client.ts
@@ -10,8 +10,7 @@ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/
const logger = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
- debug: (...args: any[]) =>
- console.debug('[DEBUG] [ImportProcessor]', ...args),
+ debug: (...args: any[]) => console.debug('[DEBUG] [IDEClient]', ...args),
};
export type IDEConnectionState = {
@@ -37,6 +36,7 @@ export class IdeClient {
logger.debug('Failed to initialize IdeClient:', err);
});
}
+
getConnectionStatus(): {
status: IDEConnectionStatus;
details?: string;
@@ -64,16 +64,18 @@ export class IdeClient {
return;
}
+ let transport: StreamableHTTPClientTransport | undefined;
try {
this.client = new Client({
name: 'streamable-http-client',
// TODO(#3487): use the CLI version here.
version: '1.0.0',
});
- const transport = new StreamableHTTPClientTransport(
+ transport = new StreamableHTTPClientTransport(
new URL(`http://localhost:${idePort}/mcp`),
);
await this.client.connect(transport);
+
this.client.setNotificationHandler(
OpenFilesNotificationSchema,
(notification) => {
@@ -95,6 +97,13 @@ export class IdeClient {
} catch (error) {
this.connectionStatus = IDEConnectionStatus.Disconnected;
logger.debug('Failed to connect to MCP server:', error);
+ if (transport) {
+ try {
+ await transport.close();
+ } catch (closeError) {
+ logger.debug('Failed to close transport:', closeError);
+ }
+ }
}
}
}