feat: Allow any value type in get_prompt arguments #1058
+71
−2
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.
The type hints for the
arguments
parameter inClientSession.get_prompt
and the correspondingGetPromptRequestParams
were previously restricted todict[str, str]
.This was overly restrictive and prevented passing arguments with non-string values, such as numbers or booleans. This commit changes the type to
dict[str, Any]
, allowing for more flexible prompt argument structures.A corresponding test case has been added to verify that calling
get_prompt
with an integer argument now works as expected.Fixes #749
Motivation and Context
Imagine this MCP server code:
And this client code:
It's very strange that we have to send a string argument although the argument type in the MCP server is int.
This PR also gives us flexibility to send an argument with a different type, like a list of strings, as referenced in the bug report.
The argument in calling the tool is not restricted to string. Why do we need to restrict it in the prompt case?
How Has This Been Tested?
I have added a unit test.
Breaking Changes
Nope.
Types of changes
Checklist
Additional context
I was not sure where to put the unit test. The
test_session.py
is not ideal. But I couldn't find a better place.