Repository navigation
Conversation
Check duplicate names against the live map, then validate a candidate map before updating the existing registry. Initialization still detects duplicate input entries. Fixes modelcontextprotocol#747.
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
Server#define_tooladded the tool to the registry and to@tool_namesbefore validating, so a call that raised still replaced a registered tool, kept a refused one, and left a duplicate name that made every laterdefine_toolcall raise.define_toolnow checks the name against the registered tools, then validates the registry with the new tool merged in, and changes the registry only after both pass.validate!takes the tools to check as an argument, defaulting to the registered ones.@tool_namesis gone:Server.newstill checks itstools:array for duplicate names, anddefine_toolchecks the registry itself.Fixes #747
How Has This Been Tested?
test/mcp/server_test.rb: a duplicate definition leaves the original tool in place, listed and callable, and a later tool can still be defined. The test for atitleon2025-03-26now also checks that the refused tool is not registered and that the name can be defined afterwards.main.original, definesanother, and leaves no tool after the refusal.bundle exec rakepasses on Ruby 4.0.10 (RuboCop, 2858 runs with 0 failures, and the conformance baseline).yard --no-outputpasses.Breaking Changes
None for a
define_toolcall that succeeds. One that raises no longer changes the registered tools.Types of changes
Checklist