Repository navigation
Description
Describe the bug
Three checks of the client's declared capabilities give a wrong answer:
ServerSession#create_form_elicitation(lib/mcp/server_session.rb:257) only checks thatelicitationis present, so a client declaringelicitation: { url: {} }is sent a form mode request. The specification says servers MUST NOT send elicitation requests with modes the client does not support (2025-11-25, 2026-07-28). Theinput_requiredcheck already refuses it.InputRequiredResult#missing_client_capabilities(lib/mcp/server/input_required_result.rb:121) andServerContext#require_client_capability!(lib/mcp/server_context.rb:90) take a capability declared asfalseas declared, while theServerSessionchecks take it as not declared.ServerSession#create_url_elicitation(lib/mcp/server_session.rb:279) raisesTypeErrorwhenelicitationis not an object, instead of the documentedRuntimeError.
The schema defines these capabilities as objects, so 2 and 3 need a client that sends invalid values. 1 needs only a conformant client.
To Reproduce
Save as repro.rb in the repository root and run bundle exec ruby -Ilib repro.rb on main (4962426):
require "mcp"
class RecordingTransport < MCP::Transport
def send_request(method, params = nil, **)
puts "sent #{method} (#{params[:mode]})"
{ action: "decline" }
end
end
def attempt
yield
rescue => e
puts "#{e.class}: #{e.message}"
end
server = MCP::Server.new(name: "repro", version: "1.0")
session = MCP::ServerSession.new(server: server, transport: RecordingTransport.new(server), session_id: "s")
# 1. A client that declares URL mode only is sent a form mode request.
session.store_client_info(client: {}, capabilities: { elicitation: { url: {} } })
attempt do
session.create_form_elicitation(related_request_id: "1", message: "Name?", requested_schema: { type: "object", properties: {} })
end
# 2. A capability declared as `false` counts as declared: nothing is reported missing.
result = MCP::Server::InputRequiredResult.new(input_requests: { r: { method: "roots/list" } })
p result.missing_client_capabilities({ roots: false })
# 3. A scalar declaration raises TypeError instead of the documented RuntimeError.
session.store_client_info(client: {}, capabilities: { elicitation: true })
attempt do
session.create_url_elicitation(related_request_id: "1", message: "Sign in", url: "https://example.com", elicitation_id: "e")
endExpected behavior
Form mode is refused when the client declares only URL mode. false counts as not declared. A declaration that is not an object raises the usual RuntimeError. A declaration naming neither mode, such as elicitation: {}, still implies form mode.
Logs
sent elicitation/create (form)
{}
TypeError: TrueClass does not have #dig method
Ruby 4.0.9.
Additional context
require_client_capability!(:elicitation, :form) does not apply the rule that elicitation: {} implies form mode, and tool-enabled sampling raises TypeError for sampling: true. Both are left for a separate change.
I have a fix with tests and will open a PR for it.
Activity