Skip to content

fix(server): rebuild tool argument errors instead of echoing pydantic's - #6107

Merged
zzstoatzz merged 4 commits into
PrefectHQ:mainfrom
xubenqiang:fix/validation-error-disclosure
Nov 10, 2026
Merged

zzstoatzz merged 4 commits into
PrefectHQ:mainfrom
xubenqiang:fix/validation-error-disclosure

Conversation

@xubenqiang

Copy link
Copy Markdown
Contributor

Fixes #6099

When a tools/call fails argument validation the server re-raised the pydantic error, so str(ValidationError) reached the caller with the exact pydantic version URL (https://errors.pydantic.dev/2.14/v/string_type), the internal adapter name (call[echo]), and every submitted value with its inferred type. Server-side logging already avoids all of that (#5106); the response did not.

Change

fastmcp_slim/fastmcp/server/server.py

  • New _validation_error_message(tool_name, error) rebuilds the client-facing text from error.errors(include_url=False, include_context=False, include_input=False): one line per invalid argument with its location and reason, prefixed by the tool name.
  • The argument-validation branch raises ToolError with that message instead of re-raising the pydantic error. The warning log (_validation_error_summary) is unchanged.
  • Raw pydantic errors raised by a tool's own validation (the separate branch) keep their previous behaviour.

Before:

2 validation errors for call[echo]
message
  Input should be a valid string [type=string_type, input_value=123, input_type=int]
    For further information visit https://errors.pydantic.dev/2.14/v/string_type
extra
  Unexpected keyword argument [type=unexpected_keyword_argument, input_value='x', input_type=str]

After:

Invalid arguments for tool 'echo': 2 validation errors
- message: Input should be a valid string
- extra: Unexpected keyword argument

Tests

tests/server/test_input_validation.py

  • New test_client_error_omits_pydantic_details drives the issue's repro and asserts the field/reason lines are present while errors.pydantic.dev, call[, input_value, input_type and N validation errors for are absent.
  • test_validation_logs_omit_client_data previously asserted the client still received the raw values; it now asserts the caller learns which argument failed without the pydantic internals, while the log assertions are unchanged.

Verified: pytest tests/server/test_input_validation.py -q -> 54 passed; with only server.py reverted, 7 failed (the six log/client parametrizations and the new test). ruff check reports only the two pre-existing findings in untouched code (PYI041 on the set_instructions signature and the string-concat finding at line 2046), and ruff format is clean on both changed files.

When `tools/call` fails argument validation the server re-raised the pydantic
error, so `str(ValidationError)` reached the caller with the exact pydantic
version URL (`https://errors.pydantic.dev/2.14/v/...`), the internal adapter name
(`call[echo]`) and every submitted value with its inferred type. Server-side
logging already avoids all of that (PrefectHQ#5106); the response did not.

Rebuild the client-facing message from the error details without the URL,
context or inputs: one line per invalid argument with its location, the reason,
and the tool name. The caller still learns which argument failed and why, and
the warning log is unchanged.
Copilot AI balanced review requested due to automatic review settings October 27, 2026 19:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions

This comment has been minimized.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-27T19:40:26.499301Z 13fd91b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. security Security fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses. server Related to FastMCP server implementation or server-side functionality. labels Oct 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13fd91b5a6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread fastmcp_slim/fastmcp/server/server.py Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
zzstoatzz and others added 2 commits November 10, 2026 13:33
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zzstoatzz
zzstoatzz merged commit 8fba5f7 into PrefectHQ:main Nov 10, 2026
26 checks passed
zzstoatzz added a commit that referenced this pull request Nov 10, 2026
* Revert "fix: preserve referenced schema definitions (#5588)"

This reverts commit 5f1d152.

* Revert "fix(server): rebuild tool argument errors instead of echoing pydantic's (#6107)"

This reverts commit 8fba5f7.

* Revert "Advertise the MCP Apps extension only when the server serves an app (#5062)"

This reverts commit b89222b.

* Revert "fix(tasks): retain results after tool removal (#5507)"

This reverts commit 711575a.

* Revert "fix(client): Prevent stale ClientGroup refreshes from replacing newer routes (#5543)"

This reverts commit 365d5d2.

* Revert "fix(prompts): honor field aliases when rendering prompts (#5836)"

This reverts commit a450fd8.

* Revert "Stop FastMCP callable caches from retaining dropped tools (#6147)"

This reverts commit 713f247.

* Revert "feat(auth): Add KeystoneTokenVerifier (#6264)"

This reverts commit c33f3de.

* Revert "fix(json-schema): keep x-unsupported-pattern when a format is set (#5731)"

This reverts commit dc9849d.

* Revert "Roll back the tool stamp when a tool registration is rejected (#5798)"

This reverts commit d6566c5.

* Revert "fix(server): validate cursors when pagination is disabled (#6045)"

This reverts commit 4917bee.

* Revert "Keep constraints on scalar schema references (#6041)"

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

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. bypass-issue-check security Security fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses. server Related to FastMCP server implementation or server-side functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool argument validation errors returned by a FastMCP server include the pydantic version URL and internal adapter name

3 participants