Merge pull request #49 from koic/suppress_interrupt_exception_for_stdio_server

Suppress `Interrupt` exception for stdio server
This commit is contained in:
Koichi ITO 2025-06-10 00:34:52 +09:00 • committed by GitHub
commit 2ee3d39814
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,8 @@ module MCP
class Server
module Transports
class StdioTransport < Transport
STATUS_INTERRUPTED = Signal.list["INT"] + 128
def initialize(server)
@server = server
@open = false
@ -20,6 +22,10 @@ module MCP
while @open && (line = $stdin.gets)
handle_json_request(line.strip)
end
rescue Interrupt
warn("\nExiting...")
exit(STATUS_INTERRUPTED)
end
def close