Skip to content

fix: support PEP 604 structured output unions#2592

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/fastmcp-pep604-output
Open

fix: support PEP 604 structured output unions#2592
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/fastmcp-pep604-output

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • wrap FastMCP structured output annotations with Pydantic's explicit (annotation, ...) field form
  • add regression coverage for dict | list | str return annotations

Fixes #2591.

To verify

  • uv run pytest tests\server\mcpserver\test_func_metadata.py -q --basetemp .tmp\pytest -p no:cacheprovider
  • uv run ruff check src\mcp\server\mcpserver\utilities\func_metadata.py tests\server\mcpserver\test_func_metadata.py
  • uv run ruff format --check src\mcp\server\mcpserver\utilities\func_metadata.py tests\server\mcpserver\test_func_metadata.py
  • git diff --check

@he-yufeng he-yufeng force-pushed the fix/fastmcp-pep604-output branch from a2d08e8 to cc2e919 Compare May 14, 2026 15:10
@he-yufeng
Copy link
Copy Markdown
Author

Pushed a follow-up for the pre-commit pyright failure: the regression helper now uses typed dict/list generics instead of bare dict | list | str. Revalidated locally with:

  • uv run pytest tests\server\mcpserver\test_func_metadata.py -q --basetemp .tmp\pytest -p no:cacheprovider
  • uv run ruff check src\mcp\server\mcpserver\utilities\func_metadata.py tests\server\mcpserver\test_func_metadata.py
  • uv run ruff format --check src\mcp\server\mcpserver\utilities\func_metadata.py tests\server\mcpserver\test_func_metadata.py
  • uv run pyright tests\server\mcpserver\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.

FastMCP crashes when tool return type uses Python 3.10+ A | B | C union syntax

1 participant