Merge pull request #20160 from Homebrew/mcp_server_eof

mcp_server: fix EOF handling.
This commit is contained in:
Mike McQuaid 2025-06-23 16:04:29 +00:00 committed by GitHub
commit 2c16fe9184
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 0 deletions

View File

@ -155,6 +155,8 @@ module Homebrew
input = if ping_switch?
{ jsonrpc: JSON_RPC_VERSION, id: 1, method: "ping" }.to_json
else
break if @stdin.eof?
@stdin.gets
end
next if input.nil? || input.strip.empty?

View File

@ -228,6 +228,8 @@ RSpec.describe Homebrew::McpServer do
end
it "exits on Interrupt" do
stdin.puts
stdin.rewind
allow(stdin).to receive(:gets).and_raise(Interrupt)
expect do
server.run
@ -237,6 +239,8 @@ RSpec.describe Homebrew::McpServer do
end
it "exits on error" do
stdin.puts
stdin.rewind
allow(stdin).to receive(:gets).and_raise(StandardError, "fail")
expect do
server.run