Skip to content

Client#discover and #server_implementation raise TypeError when _meta is not an object #749

Backlog

Description

@yorzi

Describe the bug

Both readers look up the io.modelcontextprotocol/serverInfo stamp with dig("_meta", ...). When a server sends _meta as something other than an object or null, such as false, a string, a number or an array, dig raises TypeError. discover then fails as a whole, and server_implementation never reaches the top-level serverInfo fallback that servers built against the SEP-2575 text send.

To Reproduce

Save as repro.rb in the repository root and run bundle exec ruby -Ilib repro.rb on main (2e07497):

require "mcp"

class FixedTransport
  def initialize(result)
    @result = result
  end

  def send_request(request:)
    { "jsonrpc" => "2.0", "id" => request[:id], "result" => @result }
  end

  def server_info
    @result
  end
end

def attempt(label)
  puts "#{label}: #{yield.inspect}"
rescue => e
  puts "#{label}: #{e.class}: #{e.message}"
end

[false, "meta", 1, []].each do |meta|
  result = {
    "supportedVersions" => ["2026-07-28"],
    "capabilities" => {},
    "serverInfo" => { "name" => "srv", "version" => "1.0" },
    "_meta" => meta,
  }
  client = MCP::Client.new(transport: FixedTransport.new(result))
  attempt("_meta: #{meta.inspect}, discover") { client.discover.server_info }
  attempt("_meta: #{meta.inspect}, server_implementation") { client.server_implementation }
end

Expected behavior

A _meta that is not an object is ignored for the identity, so both readers return the top-level serverInfo ({"name" => "srv", "version" => "1.0"}), or nil when there is none.

Logs

_meta: false, discover: TypeError: FalseClass does not have #dig method
_meta: false, server_implementation: TypeError: FalseClass does not have #dig method
_meta: "meta", discover: TypeError: String does not have #dig method
_meta: "meta", server_implementation: TypeError: String does not have #dig method
_meta: 1, discover: TypeError: Integer does not have #dig method
_meta: 1, server_implementation: TypeError: Integer does not have #dig method
_meta: [], discover: TypeError: no implicit conversion of String into Integer
_meta: [], server_implementation: TypeError: no implicit conversion of String into Integer

Additional context

Ruby 4.0.10. Only a server that sends an invalid _meta triggers this. I have a fix with tests and will open a PR for it.

Activity

  1. added
    bug
    on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions