Split `ValueError` from unexpected errors during logs.

Draft
ST
1mo ago
+100-5

Fixes #3342.

Motivation and Context

When a prompt is called without a required argument, the request is correctly rejected, but Python-SDK logs validation error with a full traceback.

Validation error doesn't need a full traceback, which is typically reserved for unexpected errors.
Thus, there needs a fix to separate validation error from unexpected errors.

How Has This Been Tested?

Yes. Two tests are added inside tests/server/mcpserver/test_server.py:

  • test_get_prompt_missing_args_logs_warning_without_traceback — it asserts that missing-argument ValueErrors are an expected validation failure, so logger writes a plain warning without exc_info. No full traceback at all.

  • test_get_prompt_unexpected_error_still_logs_traceback — it asserts that a prompt function raising an unexpected exception must still have logs containing a full traceback.

Breaking Changes

No breaking changes at all. This PR #3347 is a pure bug fix.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I am assigned to the linked issue (or it is labeled help wanted, or I'm a maintainer)
  • I have disclosed any AI assistance and can explain the change in my own words
  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

1. AI disclosure

I used Claude Sonnet 5 during chat sessions as a pair-programming and debugging assistant for:

  • Drafting initial fix.
  • Catching a real regression when cubic-dev-ai flagged that original blanket except ValueError would have also swallowed tracebacks for genuine unexpected crashes, not just missing-argument case. Fixed by creation of a new class called PromptValidationError inside src/mcp/server/mcpserver/prompts/base.py.

2. Notes

I left a claim comment on issue #3342 before starting as repo convention per CONTRIBUTING.md. As of opening this PR, no one else has commented on this issue, and it hasn't been formally assigned or labeled ready for work. Currently PR #3347 is a draft, so bug fix and CI status are verifiable and visible. Waiting on maintainers' buy-in.

3. Final

I have reviewed, tested, and can explain every change in my own words.