fix(server): forward tool args under the real parameter name, not the…#3119
Draft
jayzuccarelli wants to merge 1 commit into
Draft
fix(server): forward tool args under the real parameter name, not the…#3119jayzuccarelli wants to merge 1 commit into
jayzuccarelli wants to merge 1 commit into
Conversation
… schema alias a tool parameter with an explicit alias, e.g. city: Annotated[str, Field(alias="location")], is advertised in the input schema as "location" and clients send "location". at call time model_dump_one_level forwarded the value under the alias, so the function was invoked as fn(location=...) and raised TypeError: got an unexpected keyword argument 'location'. track each field's real python parameter name at metadata-build time and forward arguments under it. the internal alias used to dodge BaseModel attribute shadowing (field "field_schema" -> param "schema") is preserved because its real name is recorded the same way. the resolver arg-name matching in tools/base.py reads the same map so by-name resolvers keep resolving.
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.
Forward tool arguments to the underlying function under the real parameter name instead of the schema alias.
Motivation and Context
A tool parameter with an explicit alias, e.g.
city: Annotated[str, Field(alias="location")], is advertised in the tool input schema aslocation, and clients sendlocation. At call timemodel_dump_one_levelforwarded the value under the alias, so the function was invoked asfn(location=...)and raisedTypeError: got an unexpected keyword argument 'location'. Both sync and async tools are affected.The root cause is that
field_info.aliasis used as the kwarg name, but the alias is a wire name, not necessarily a valid Python parameter. It happens to be correct for the internal shadow-rename case (a param named after aBaseModelattribute, e.g.schema-> fieldfield_schemawithalias="schema"), where the alias is the real param name — so the two cases are indistinguishable fromFieldInfoalone.The fix records each field's real Python parameter name at metadata-build time and forwards arguments under it. The shadow-rename case keeps working because its real name is recorded the same way. Resolver arg-name matching in
tools/base.pyreads the same map so by-name resolvers keep resolving.How Has This Been Tested?
Added a regression test (
test_call_with_aliased_parameter) that fails before the change with theTypeErrorabove and passes after. Repro:Full
tests/server/mcpserver/suite passes locally (552 tests), along with ruff, pyright, and strict-no-cover.Breaking Changes
None.
Types of changes
Checklist