Title: FastMCP crashes when tool return type uses Python 3.10+ `A | B | C` union syntax · Issue #2591 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: FastMCP crashes when tool return type uses Python 3.10+ `A | B | C` union syntax · Issue #2591 · modelcontextprotocol/python-sdk
X Title: FastMCP crashes when tool return type uses Python 3.10+ `A | B | C` union syntax · Issue #2591 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue Description FastMCP crashes on sta...
Open Graph Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ...
X Description: Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening t...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2591
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"FastMCP crashes when tool return type uses Python 3.10+ `A | B | C` union syntax","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the latest version of MCP Python SDK\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Description\n\n`FastMCP` crashes on startup when a tool function's return type annotation uses Python 3.10+ union syntax (`A | B | C`, i.e. `types.UnionType`). The error originates from `_create_wrapped_model` in `func_metadata.py`, which passes the union annotation directly to Pydantic's `create_model()` as a bare keyword value, causing `PydanticUserError`.\n\n### Example Code\n\n```Python\nfrom mcp.server.fastmcp import FastMCP\n\nmcp = FastMCP(\"test\")\n\n@mcp.tool()\nasync def my_tool(flag: bool) -\u003e dict | list | str: # \u003c-- triggers the bug\n if flag:\n return {\"key\": \"value\"}\n return [\"item\"]\n```\n\n### Python \u0026 MCP Python SDK\n\n```Text\n- mcp (Python): latest (\u003e=1.0.0,\u003c2.0.0)\n- pydantic: \u003e=2.10 (observed on 2.10.x)\n- Python: \u003e=3.10\n```","author":{"url":"https://github.com/Swcmb","@type":"Person","name":"Swcmb"},"datePublished":"2026-05-14T12:45:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/2591/python-sdk/issues/2591"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:50742448-8f98-a548-ac34-cda7f50d5d4d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A4D2:12D89D:1B698EE:23E0D1A:6A5C71EE |
| html-safe-nonce | 82585af21b8e603085eaca210edc43b72636be57084dc6c40897a7cb2fcc7f4a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEQyOjEyRDg5RDoxQjY5OEVFOjIzRTBEMUE6NkE1QzcxRUUiLCJ2aXNpdG9yX2lkIjoiNjQ1MTg5MzcxNDg1MjU0MDkxMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2d6608f29ee1f70e3c037f9b25db644e4bd860272c351c37e6ea331005f12bfe |
| hovercard-subject-tag | issue:4446001200 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2591/issue_layout |
| twitter:image | https://opengraph.githubassets.com/099801f6ef00cbe0353773aad0287cfcb493f7d928ba0484bc8fe2bc1ec6fc5b/modelcontextprotocol/python-sdk/issues/2591 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/099801f6ef00cbe0353773aad0287cfcb493f7d928ba0484bc8fe2bc1ec6fc5b/modelcontextprotocol/python-sdk/issues/2591 |
| og:image:alt | Initial Checks I confirm that I'm using the latest version of MCP Python SDK I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Swcmb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width