Repository navigation
Conversation
## Motivation and Context `MCP::Resource#to_h` and `MCP::ResourceTemplate#to_h` leave out the members that were not given. A resource registered without a `uri` or a `name` (a class-based resource that sets no `uri`, an anonymous class that sets no `resource_name`, `Resource.new(uri: nil, ...)`) was therefore accepted and then listed without that member, which the spec requires of every `Resource`, and a template without `uriTemplate` or `name` likewise. The server learned nothing of it, and a client that validates `resources/list` rejects the whole result for the one entry. `MCP::Server` now refuses such a definition where it is registered: in the constructor, `resources=`, `resource_templates=`, `define_resource` and `define_resource_template`. The `ArgumentError` names the missing member and what the definition does have. `resource_templates=` becomes a method of its own for this; it was an attribute writer. A resource a `resources_list_handler` returns is not checked, since it is produced per request, and neither is a resource that is never registered or one appended to the Array `resources` returns, which was never a way to register one (it is not indexed for `resources/read` either). ## How Has This Been Tested? `test/mcp/server_resource_registration_test.rb`; on the previous library the incomplete definitions are accepted. ## Breaking Changes A server that registers a resource without a `uri` or a `name`, or a resource template without a `uri_template` or a `name`, now raises `ArgumentError` when it does, where it used to start and list the entry without the member. The check serializes each definition, so one whose `to_h` raises now does so when it is registered, and `resource_templates=` needs something it can iterate.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
MCP::Resource#to_handMCP::ResourceTemplate#to_hleave out the members that were not given. A resource registered without aurior aname(a class-based resource that sets nouri, an anonymous class that sets noresource_name,Resource.new(uri: nil, ...)) was therefore accepted and then listed without that member, which the spec requires of everyResource, and a template withouturiTemplateornamelikewise. The server learned nothing of it, and a client that validatesresources/listrejects the whole result for the one entry.MCP::Servernow refuses such a definition where it is registered: in the constructor,resources=,resource_templates=,define_resourceanddefine_resource_template. TheArgumentErrornames the missing member and what the definition does have.resource_templates=becomes a method of its own for this; it was an attribute writer.A resource a
resources_list_handlerreturns is not checked, since it is produced per request, and neither is a resource that is never registered or one appended to the Arrayresourcesreturns, which was never a way to register one (it is not indexed forresources/readeither).How Has This Been Tested?
test/mcp/server_resource_registration_test.rb; on the previous library the incomplete definitions are accepted.Breaking Changes
A server that registers a resource without a
urior aname, or a resource template without auri_templateor aname, now raisesArgumentErrorwhen it does, where it used to start and list the entry without the member. The check serializes each definition, so one whoseto_hraises now does so when it is registered, andresource_templates=needs something it can iterate.Types of changes
Checklist