Skip to content

fix(server): skip output schema validation for tool errors#2525

Open
Genmin wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Genmin:codex/fix-v1-error-output-validation
Open

fix(server): skip output schema validation for tool errors#2525
Genmin wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Genmin:codex/fix-v1-error-output-validation

Conversation

@Genmin
Copy link
Copy Markdown

@Genmin Genmin commented May 1, 2026

Summary

Fixes #2429.

When a typed FastMCP tool returns a CallToolResult with isError=True, the v1.x server should preserve that error result. Previously, FuncMetadata.convert_result() still validated structuredContent against the inferred output schema, so error results without structured content raised a Pydantic validation error and replaced the intended tool error.

This gates schema validation to non-error CallToolResult values while preserving validation for successful structured tool results.

Validation

  • uv run pytest tests/server/fastmcp/test_func_metadata.py -q
  • uv run pytest tests/server/fastmcp -q
  • uv run ruff check src/mcp/server/fastmcp/utilities/func_metadata.py tests/server/fastmcp/test_func_metadata.py
  • uv run pyright src/mcp/server/fastmcp/utilities/func_metadata.py tests/server/fastmcp/test_func_metadata.py
  • git diff --check

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant