diff --git a/src/server/stdio.ts b/src/server/stdio.ts index e3c78b21..30c80012 100644 --- a/src/server/stdio.ts +++ b/src/server/stdio.ts @@ -62,13 +62,17 @@ export class StdioServerTransport implements Transport { } async close(): Promise { - // Remove our event listeners + // Remove our event listeners first this._stdin.off("data", this._ondata); this._stdin.off("error", this._onerror); - - // Destroy streams to ensure they're fully closed - this._stdin.destroy(); - this._stdout.destroy(); + + // Check if we were the only data listener + const remainingDataListeners = this._stdin.listenerCount('data'); + if (remainingDataListeners === 0) { + // Only pause stdin if we were the only listener + // This prevents interfering with other parts of the application that might be using stdin + this._stdin.pause(); + } // Clear the buffer and notify closure this._readBuffer.clear();