Skip to content

Commit 2c16fe9

Browse files
authored
Merge pull request #20160 from Homebrew/mcp_server_eof
mcp_server: fix EOF handling.
2 parents 4759ca9 + 8186623 commit 2c16fe9

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Library/Homebrew/mcp_server.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def run
155155
input = if ping_switch?
156156
{ jsonrpc: JSON_RPC_VERSION, id: 1, method: "ping" }.to_json
157157
else
158+
break if @stdin.eof?
159+
158160
@stdin.gets
159161
end
160162
next if input.nil? || input.strip.empty?

Library/Homebrew/test/mcp_server_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@
228228
end
229229

230230
it "exits on Interrupt" do
231+
stdin.puts
232+
stdin.rewind
231233
allow(stdin).to receive(:gets).and_raise(Interrupt)
232234
expect do
233235
server.run
@@ -237,6 +239,8 @@
237239
end
238240

239241
it "exits on error" do
242+
stdin.puts
243+
stdin.rewind
240244
allow(stdin).to receive(:gets).and_raise(StandardError, "fail")
241245
expect do
242246
server.run

0 commit comments

Comments
 (0)