Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#3,572 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
65/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

Look at the Tool.run method and how it wraps pydantic ValidationError into ToolError. The error message is built from str(ValidationError). Find where tool validation happens, likely in the tool manager or argument model. The goal is to add a masking option or a hook to customize the error message without leaking input_value. Check existing server configuration for similar flags. A successful change will produce a validation error that describes the rule but not the sensitive data.

由索引模型根據 Issue 內容生成。

描述

What happens

When a tool call's arguments fail pydantic validation, Tool.run wraps the ValidationError into a ToolError whose message includes the pydantic rendering — and str(ValidationError) carries the offending value:

Error executing tool <name>: 1 validation error for <model>
<field>
  Input should be a valid string [type=string_type, input_value=12345, input_type=int]

That message is sent to the client as an isError result, so the rejected value is echoed back to the caller (and into the model's context).

Why it matters

Servers that handle sensitive input (PII/PHI, credentials, member identifiers) must not let a validation failure repeat the value; the error should describe the rule, not the data. We hit this building a healthcare-platform MCP server whose tool inputs can be PHI.

Workaround we use today (reaches private API)

We replace the SDK-generated arguments model with a subclass that raises MCPError(-32602, "<field>: <rule>") instead of the default ToolError:

tool = server._tool_manager.add_tool(fn, ...)
tool.fn_metadata.arg_model = PhiSafeArgModel(tool.fn_metadata.arg_model)

This depends on _tool_manager and fn_metadata.arg_model (both private) and on validation continuing to flow through model_validate, so it is fragile across minor releases.

Asks (any one would remove the private-API dependency)
  1. An opt-in setting to omit input values from tool validation errors (e.g. a mask_error_details-style flag), or
  2. A public/supported hook to customize argument-validation failures (or documenting arg_model as an extensible point), or
  3. Excluding input_value from the argument-validation error text by default.

Version: mcp 2.2.0 (Python). Happy to open a PR if you can point at the preferred shape.

主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 16 小時
30 天內合併 PR
25

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。