Repository navigation
fix(prompts): return INVALID_PARAMS (-32602) on wrong-type or extra arguments (#3974) - #3977
Open
Abdulrehman1978 wants to merge 2 commits into
Open
Abdulrehman1978 wants to merge 2 commits into
Abdulrehman1978 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 3 files
Reply to a comment to ask cubic a question or push back. It learns from your replies.
Re-trigger cubic
…llback render paths
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.
Summary
When a prompt is rendered with a wrong-type or unknown/extra argument,
Prompt.render()previously letvalidate_callfail inside thetry:block and converted it to a genericValueError, causing the server to return an internal error (-32603/0) instead ofINVALID_PARAMS(-32602).Fixes #3974
Changes
fn_metadata(FuncMetadata) onPromptinPrompt.from_function().Prompt.render(), reject unknown/extra arguments againstself.argumentswithMCPError(code=INVALID_PARAMS, ...)and validate argument types withself.fn_metadata.validate_arguments(...)before invokingself.fn, translatingValidationErrorintoMCPError(code=INVALID_PARAMS, message=f"Invalid arguments for prompt {self.name}")(preserving the withholding of Pydantic internals, while keeping internal prompt-body errors as internal errors).tests/interaction/mcpserver/test_prompts.pyand added unit + interaction tests for wrong-type and extra prompt arguments.Testing
uv --directory python-sdk run --no-sync pytest tests/server/mcpserver/prompts/ tests/interaction/mcpserver/test_prompts.py -q(74 passed)uv --directory python-sdk run --no-sync ruff check src/mcp/server/mcpserver/prompts/base.py tests/interaction/mcpserver/test_prompts.py tests/server/mcpserver/prompts/test_base.py(All checks passed!)