Skip to content

fix: guard optional discovery identity metadata - #756

Open
yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/client-discover-metadata-type-guard
Open

yorzi wants to merge 1 commit into
modelcontextprotocol:mainfrom
yorzi:fix/client-discover-metadata-type-guard

Conversation

@yorzi

@yorzi yorzi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Motivation and Context

discover and server_implementation read the server identity with dig("_meta", "io.modelcontextprotocol/serverInfo"), which raises TypeError when _meta is not an object or null.

Both now use one private reader that takes the stamp only from a Hash _meta and otherwise falls back to the top-level serverInfo. The order is unchanged: the _meta stamp wins over serverInfo.

Fixes #749

How Has This Been Tested?

  • test/mcp/client_test.rb: discover returns the top-level identity and supported_versions for _meta values false, 1, a string and an array; server_implementation returns nil for _meta: false without an identity, then the top-level one once it is present, and the raw handshake stays unchanged. Two existing tests now also send a conflicting top-level serverInfo, to check that the _meta stamp wins.
  • The new tests fail on main with TypeError.
  • With this change the script in the issue returns the top-level identity for each _meta value.

bundle exec rake passes on Ruby 4.0.10 (RuboCop, 2859 runs with 0 failures, and the conformance baseline). yard --no-output passes.

  • Automated unit / integration tests
  • Tested manually
  • Tested in a real application

Breaking Changes

None. Results with an object or missing _meta are read as before.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Test update (non-breaking change which adds or updates tests)
  • Refactoring (non-breaking change which makes things better)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • CI/build script update (update CI workflow or build scripts)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • I have added automated tests for my change
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Read the reserved identity stamp only from a metadata hash. Both public
readers use the same precedence and fallback.

Fixes modelcontextprotocol#749.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant