Skip to content

fix(prompts): return INVALID_PARAMS (-32602) on wrong-type or extra arguments (#3974) - #3977

Open
Abdulrehman1978 wants to merge 2 commits into
modelcontextprotocol:mainfrom
Abdulrehman1978:fix/prompt-invalid-args-error-code
Open

Abdulrehman1978 wants to merge 2 commits into
modelcontextprotocol:mainfrom
Abdulrehman1978:fix/prompt-invalid-args-error-code

Conversation

@Abdulrehman1978

Copy link
Copy Markdown

Summary

When a prompt is rendered with a wrong-type or unknown/extra argument, Prompt.render() previously let validate_call fail inside the try: block and converted it to a generic ValueError, causing the server to return an internal error (-32603 / 0) instead of INVALID_PARAMS (-32602).

Fixes #3974

Changes

  • Store fn_metadata (FuncMetadata) on Prompt in Prompt.from_function().
  • In Prompt.render(), reject unknown/extra arguments against self.arguments with MCPError(code=INVALID_PARAMS, ...) and validate argument types with self.fn_metadata.validate_arguments(...) before invoking self.fn, translating ValidationError into MCPError(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).
  • Updated tests/interaction/mcpserver/test_prompts.py and 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!)

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong or extra prompt arguments return an internal error instead of -32602

1 participant