Skip to content

fix: hide input values from tool validation error messages - #3582

Closed
MohammadaminAlbooyeh wants to merge 1 commit into
modelcontextprotocol:mainfrom
MohammadaminAlbooyeh:fix/hide-input-in-validation-errors
Closed

MohammadaminAlbooyeh wants to merge 1 commit into
modelcontextprotocol:mainfrom
MohammadaminAlbooyeh:fix/hide-input-in-validation-errors

Conversation

@MohammadaminAlbooyeh

Copy link
Copy Markdown

Fixes #3572

Motivation and Context

Tool validation errors echoed the rejected input_value back to the client via pydantic's default str(ValidationError) format. Servers handling sensitive input (PII/PHI, credentials) must not leak data in error messages.

How Has This Been Tested?

Added test_validation_error_does_not_echo_input_value in tests/server/mcpserver/test_func_metadata.py. All 59 tests in that file pass locally.

Breaking Changes

None. Error messages are less verbose (no data echoed), but the rule description (type=string_type, int_parsing, etc.) is still present.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

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

Tool validation errors previously echoed the rejected input value via
pydantic's default str(ValidationError) format, leaking PII/PHI in
servers that handle sensitive data.

Set hide_input_in_errors=True on ArgModelBase.model_config so the
generated arg model never includes input_value in its error messages.
The error still describes the rule (type, constraint) but not the data.

Fixes modelcontextprotocol#3572
Copilot AI lite review requested due to automatic review settings September 25, 2026 07:40
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3572.

If a maintainer assigns you to #3572, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Nested user-defined models may still expose rejected values, and the regression coverage needs strengthening.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Fixes leakage of rejected input values in tool validation errors.

Changes:

  • Enables hidden input values for generated argument models.
  • Adds regression coverage for sanitized validation errors.
File Description
tests/​server/​mcpserver/​test_func_metadata.py Tests that rejected values are omitted from validation errors.
src/​mcp/​server/​mcpserver/​utilities/​func_metadata.py Configures generated argument models to hide validation inputs.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

return kwargs

model_config = ConfigDict(arbitrary_types_allowed=True)
model_config = ConfigDict(arbitrary_types_allowed=True, hide_input_in_errors=True)
Comment on lines +1533 to +1535
meta = func_metadata(fn)
with pytest.raises(Exception) as exc_info:
meta.arg_model.model_validate({"name": "Alice", "age": "not-a-number"})
def fn(name: str, age: int) -> str: ... # pragma: no branch

meta = func_metadata(fn)
with pytest.raises(Exception) as exc_info:
@MohammadaminAlbooyeh

Copy link
Copy Markdown
Author

I've implemented a fix and opened PR #3582. The approach: set hide_input_in_errors=True on ArgModelBase.model_config — a one-line change that suppresses input_value from all pydantic validation errors for tool arguments. All 59 existing tests pass. Happy to address the Copilot review comments (nested model coverage, ValidationError instead of Exception, end-to-end test) if a maintainer assigns me.

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

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool validation errors echo the rejected input value (input_value) — add a masking option or a public validation-error hook

2 participants