Skip to content

Commit 4d53e35

Browse files
committed
cleanup when running onClose
1 parent 3de6e3b commit 4d53e35

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

apps/sim/lib/mcp/client.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,14 @@ export class McpClient {
281281
/**
282282
* Register a callback to be invoked when the underlying transport closes.
283283
* Used by the connection manager for reconnection logic.
284+
* Chains with the SDK's internal onclose handler so it still performs its cleanup.
284285
*/
285286
onClose(callback: () => void): void {
286-
this.transport.onclose = callback
287+
const existingHandler = this.transport.onclose
288+
this.transport.onclose = () => {
289+
existingHandler?.()
290+
callback()
291+
}
287292
}
288293

289294
/**

0 commit comments

Comments
 (0)