Skip to content

Commit 7a101d6

Browse files
authored
Merge pull request #621 from koic/keep_ruby_2_7_from_warning_about_keywords_in_stdio_transport
Keep Ruby 2.7 from warning about keywords in `StdioTransport`
2 parents 56af0c7 + 7d64add commit 7a101d6

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎lib/mcp/server/transports/stdio_transport.rb‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ def parse_line(line)
168168
# (an `initialize` after a modern lock, a modern envelope after a legacy lock, or a missing envelope after a modern lock)
169169
# are rejected in-band by `Server#lift_request_envelope`.
170170
def dispatch_with_era(parsed)
171-
response = @session.handle(parsed)
171+
# Passing `auth_info:` keeps Ruby 2.7 from taking the request Hash as keyword arguments,
172+
# which works but warns that the conversion is deprecated.
173+
response = @session.handle(parsed, auth_info: nil)
172174
lock_modern_era_on_success(parsed, response)
173175
response
174176
end

‎test/mcp/server/transports/stdio_transport_test.rb‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ class StdioTransportTest < ActiveSupport::TestCase
135135
end
136136
end
137137

138+
test "open passes a request to the session without a keyword argument warning" do
139+
request = { jsonrpc: "2.0", method: "ping", id: "1" }
140+
input = StringIO.new(JSON.generate(request) + "\n")
141+
original_stdin = $stdin
142+
original_deprecated = Warning[:deprecated]
143+
144+
begin
145+
$stdin = input
146+
Warning[:deprecated] = true
147+
148+
_out, err = capture_io { @transport.open }
149+
150+
assert_empty(err)
151+
ensure
152+
$stdin = original_stdin
153+
Warning[:deprecated] = original_deprecated
154+
end
155+
end
156+
138157
test "open handles a malformed JSON-RPC batch element and emits an error response" do
139158
input = StringIO.new("[[]]\n")
140159
output = StringIO.new

0 commit comments

Comments
 (0)