Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcp/server/mcpserver/utilities/func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def model_dump_one_level(self) -> dict[str, Any]:
kwargs[output_name] = value
return kwargs

model_config = ConfigDict(arbitrary_types_allowed=True)
model_config = ConfigDict(arbitrary_types_allowed=True, hide_input_in_errors=True)


class FuncMetadata(BaseModel):
Expand Down
19 changes: 19 additions & 0 deletions tests/server/mcpserver/test_func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -1520,3 +1520,22 @@ def fn() -> StepA | StepB: ... # pragma: no branch

meta = func_metadata(fn)
assert meta.output_schema is None


def test_validation_error_does_not_echo_input_value():
"""Tool validation errors must not leak the rejected input value (PII/PHI risk).

Regression test for: https://github.com/modelcontextprotocol/python-sdk/issues/3572
"""

def fn(name: str, age: int) -> str: ... # pragma: no branch

meta = func_metadata(fn)
with pytest.raises(Exception) as exc_info:
meta.arg_model.model_validate({"name": "Alice", "age": "not-a-number"})
Comment on lines +1533 to +1535

error_text = str(exc_info.value)
assert "not-a-number" not in error_text, "Rejected input value must not appear in validation error message"
assert "int_parsing" in error_text or "int" in error_text.lower(), (
"Error should still describe the rule (type mismatch)"
)
Loading