Skip to content

Commit 7d64add

Browse files
committed
Keep Ruby 2.7 from warning about keywords in StdioTransport
Since 1.8.0, `ServerSession#handle` accepts bare keyword arguments as the request (`handle(request = nil, auth_info: nil, **request_keywords)`), so `StdioTransport` passing the parsed request Hash as its only argument makes Ruby 2.7 treat the Hash as keyword arguments. The request is still handled, but every frame prints "Using the last argument as keyword parameters is deprecated" to stderr when deprecation warnings are enabled, which breaks callers that expect a silent stderr, such as RuboCop's MCP server specs on Ruby 2.7. Passing `auth_info: nil` explicitly keeps the Hash positional without changing the request that reaches the server.
1 parent 56af0c7 commit 7d64add

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)