feat: deprecate roots sampling and logging
Warn when Roots, Sampling, or Logging APIs are used with MCP protocol version 2026-07-28 or newer. Add a shared protocol deprecation helper, YARD deprecation notes, and regression tests covering warnings at and after the deprecation threshold and no warnings for older or never-established protocol versions. Closes https://github.com/modelcontextprotocol/ruby-sdk/issues/390 Co-authored-by: Qlaw <noreply@qlaw.quick.shopify.io>
This commit is contained in:
parent
f4d939d349
commit
6a43d3d6fb
1 changed files with 508 additions and 3 deletions
|
|
@ -4,6 +4,8 @@ require "test_helper"
|
|||
|
||||
module MCP
|
||||
class ServerRootsTest < ActiveSupport::TestCase
|
||||
include DeprecationWarningTestHelper
|
||||
|
||||
class MockTransport < Transport
|
||||
attr_reader :requests
|
||||
|
||||
|
|
@ -62,6 +64,36 @@ module MCP
|
|||
assert callback_called
|
||||
end
|
||||
|
||||
test "notifications/roots/list_changed warns when negotiated protocol version is 2026-07-28" do
|
||||
server = Server.new(name: "test", version: "1.0")
|
||||
server.handle({
|
||||
jsonrpc: "2.0",
|
||||
method: "initialize",
|
||||
id: 1,
|
||||
params: {
|
||||
protocolVersion: "2026-07-28",
|
||||
capabilities: { roots: { listChanged: true } },
|
||||
clientInfo: { name: "test-client", version: "1.0" },
|
||||
},
|
||||
})
|
||||
|
||||
assert_deprecation_warning(/MCP Roots .*2026-07-28/) do
|
||||
server.handle({
|
||||
jsonrpc: "2.0",
|
||||
method: "notifications/roots/list_changed",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
test "notifications/roots/list_changed does not warn when negotiated protocol version is older" do
|
||||
assert_no_deprecation_warning do
|
||||
@server.handle({
|
||||
jsonrpc: "2.0",
|
||||
method: "notifications/roots/list_changed",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
test "notifications/roots/list_changed is handled as no-op by default" do
|
||||
result = @server.handle({
|
||||
jsonrpc: "2.0",
|
||||
|
|
@ -144,6 +176,21 @@ module MCP
|
|||
assert_silent { session.list_roots(related_request_id: "req-1") }
|
||||
end
|
||||
|
||||
test "ServerSession#list_roots warns when negotiated protocol version is 2026-07-28 and client lacks roots" do
|
||||
session = ServerSession.new(server: @server, transport: @mock_transport)
|
||||
session.store_client_info(client: { name: "test-client" }, capabilities: {})
|
||||
session.mark_initialized!(protocol_version: "2026-07-28")
|
||||
|
||||
error = nil
|
||||
assert_deprecation_warning(/MCP Roots .*2026-07-28/) do
|
||||
error = assert_raises(RuntimeError) do
|
||||
session.list_roots(related_request_id: "req-1")
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal("Client does not support roots.", error.message)
|
||||
end
|
||||
|
||||
test "ServerSession#client_capabilities falls back to server global capabilities" do
|
||||
transport = MCP::Server::Transports::StreamableHTTPTransport.new(@server)
|
||||
|
||||
|
|
@ -219,5 +266,31 @@ module MCP
|
|||
end
|
||||
assert_equal("No active stream for roots/list request.", error.message)
|
||||
end
|
||||
|
||||
test "ServerSession#list_roots warns when session negotiated protocol version is 2026-07-28" do
|
||||
server = Server.new(name: "test", version: "1.0")
|
||||
transport = MockTransport.new(server)
|
||||
|
||||
session = ServerSession.new(server: server, transport: transport, session_id: "s1")
|
||||
server.handle(
|
||||
{
|
||||
jsonrpc: "2.0",
|
||||
method: "initialize",
|
||||
id: 1,
|
||||
params: {
|
||||
protocolVersion: "2026-07-28",
|
||||
capabilities: { roots: {} },
|
||||
clientInfo: { name: "http-client", version: "1.0" },
|
||||
},
|
||||
},
|
||||
session: session,
|
||||
)
|
||||
|
||||
assert_deprecation_warning(/MCP Roots .*2026-07-28/) do
|
||||
session.list_roots(related_request_id: "req-1")
|
||||
end
|
||||
|
||||
assert_equal Methods::ROOTS_LIST, transport.requests.first[:method]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue