Title: Tool return annotations for `Enum`/`UUID`/`datetime`/`Decimal`/`Path` drop structured output, and `AnyUrl`/`AnyHttpUrl` silently emit `{}` · Issue #3886 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Tool return annotations for `Enum`/`UUID`/`datetime`/`Decimal`/`Path` drop structured output, and `AnyUrl`/`AnyHttpUrl` silently emit `{}` · Issue #3886 · modelcontextprotocol/python-sdk
X Title: Tool return annotations for `Enum`/`UUID`/`datetime`/`Decimal`/`Path` drop structured output, and `AnyUrl`/`AnyHttpUrl` silently emit `{}` · Issue #3886 · modelcontextprotocol/python-sdk
Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before openi...
Open Graph Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex...
X Description: Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/mod...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3886
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tool return annotations for `Enum`/`UUID`/`datetime`/`Decimal`/`Path` drop structured output, and `AnyUrl`/`AnyHttpUrl` silently emit `{}`","articleBody":"### Initial Checks\n\n- [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)\n- [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue\n\n### Release line\n\n2.x (current stable)\n\n### Description\n\nIn `src/mcp/server/mcpserver/utilities/func_metadata.py`, `_create_output_model()` only sends exact builtin types `(str, int, float, bool, bytes, type(None), list, tuple, set, frozenset)` to the `{\"result\": ...}` wrapper (Case 4), and falls through to Case 5 (`type_hints = get_type_hints(type_annotation)`) for every other non-`BaseModel`, non-`TypedDict`, non-`dict` class.\n\nThis causes two concrete bugs for standard Pydantic-serializable return annotations:\n\n1. **Silent data loss for `AnyUrl` / `AnyHttpUrl` (and other non-`BaseModel` Pydantic scalar types with private annotations)**:\n - `get_type_hints(AnyHttpUrl)` is non-empty (it contains private attributes such as `_constraints`), which `_create_model_from_class()` skips (`if field_name.startswith(\"_\"): continue`).\n - As a result, `_create_model_from_class()` builds an **empty `BaseModel` with zero fields**:\n `output_schema == {'properties': {}, 'title': 'AnyHttpUrl', 'type': 'object'}`.\n - When the tool runs, `convert_result()` silently discards the URL and returns **`structured_content == {}`**!\n\n2. **Dropped structured output / `InvalidSignature` for standard library enums and value types**:\n - `Enum` / `StrEnum` / `IntEnum`, `UUID`, `datetime`, `date`, `time`, `timedelta`, `Decimal`, `Path` / `PurePath`, and `IPv4Address` / `IPv6Address` / `IPv4Interface` / `IPv6Interface` / `IPv4Network` / `IPv6Network` all have empty `get_type_hints(...)`, so `_create_output_model()` returns `(None, False)`.\n - With default `structured_output=None`, `output_schema` is silently `None` and no `structured_content` is emitted.\n - With `structured_output=True`, registration raises `InvalidSignature: return type ... is not serializable for structured output`—even though Pydantic natively serializes all of these types, they work as tool input parameters, and wrapped/generic forms like `-> list[Color]` or `-> Color | None` already work cleanly.\n\n#### Expected behavior\n\nFollowing the same principle as #3758 (bare `dict`/`set`/`frozenset`), standard Pydantic-serializable scalar/enum types (`Enum`, `date`/`datetime`/`time`/`timedelta`, `Decimal`, `UUID`, `PurePath`, `ipaddress` types) and non-`BaseModel` types implementing `__get_pydantic_core_schema__` (such as `AnyUrl` / `AnyHttpUrl`) should be wrapped in `{\"result\": ...}` in Case 4 of `_create_output_model()`, producing a valid object `output_schema` and preserving the serialized value under `structured_content[\"result\"]`.\n\nUnannotated custom classes (`class Foo: ...`) and `NamedTuple` subclasses remain unaffected.\n\nI have a minimal fix + 13 parametrized regression tests verified locally (`pytest`, `ruff`, `pyright`) and would be happy to submit a PR if this is confirmed.\n\n### Example Code\n\n```python\nfrom datetime import datetime\nfrom decimal import Decimal\nfrom enum import StrEnum\nfrom pathlib import Path\nfrom uuid import UUID\n\nfrom pydantic import AnyHttpUrl\n\nfrom mcp.server.mcpserver import MCPServer\nfrom mcp.server.mcpserver.utilities.func_metadata import func_metadata\n\n\nclass Color(StrEnum):\n RED = \"red\"\n BLUE = \"blue\"\n\n\ndef get_homepage() -> AnyHttpUrl:\n return AnyHttpUrl(\"https://example.com\")\n\n\nmeta = func_metadata(get_homepage)\nprint(\"AnyHttpUrl output_schema:\", meta.output_schema)\nprint(\"AnyHttpUrl structured_content:\", meta.convert_result(get_homepage()).structured_content)\n# Actual:\n# AnyHttpUrl output_schema: {'properties': {}, 'title': 'AnyHttpUrl', 'type': 'object'}\n# AnyHttpUrl structured_content: {} \u003c-- URL silently lost!\n\n\ndef get_color() -> Color:\n return Color.RED\n\n\nprint(\"Color (default) output_schema:\", func_metadata(get_color).output_schema)\n# Actual: None\n\nmcp = MCPServer(\"repro\")\nfor ret_type in (Color, UUID, datetime, Decimal, Path):\n def fn():\n return None\n fn.__annotations__ = {\"return\": ret_type}\n try:\n mcp.add_tool(fn, name=f\"t_{ret_type.__name__}\", structured_output=True)\n except Exception as e:\n print(f\"{ret_type.__name__} (structured_output=True) -> {type(e).__name__}: {e}\")\n# Actual:\n# Color (structured_output=True) -> InvalidSignature: Function fn: return type \u003cenum 'Color'> is not serializable for structured output\n# UUID (structured_output=True) -> InvalidSignature: Function fn: return type \u003cclass 'uuid.UUID'> is not serializable for structured output\n# datetime (structured_output=True) -> InvalidSignature: Function fn: return type \u003cclass 'datetime.datetime'> is not serializable for structured output\n# Decimal (structured_output=True) -> InvalidSignature: Function fn: return type \u003cclass 'decimal.Decimal'> is not serializable for structured output\n# Path (structured_output=True) -> InvalidSignature: Function fn: return type \u003cclass 'pathlib.Path'> is not serializable for structured output\n```\n\n### Python & MCP Python SDK\n\n```text\nPython 3.14.8, macOS\nmodelcontextprotocol/python-sdk main @ 77001c96 (2.3.1.dev20+77001c96)\n```\n\n---\n*AI disclosure: AI assistance was used to help investigate and draft this issue; the reproduction and observed output were verified locally.*\n","author":{"url":"https://github.com/0718lol","@type":"Person","name":"0718lol"},"datePublished":"2026-11-21T05:35:35Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3886"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:01504f30-4028-fb3e-ed18-caab318d6001 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D772:2DE1B0:4C97C3:6ABB9C:6B05BB4D |
| html-safe-nonce | 6f26931004eb182fcb4748f9e5bd49fc0f9d4149798ca8d74f5f4654152879d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENzcyOjJERTFCMDo0Qzk3QzM6NkFCQjlDOjZCMDVCQjREIiwidmlzaXRvcl9pZCI6IjI0NjI4NzEwOTEyNzQ5NTU1OTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9faaac9e54291a914ab7d4db140efe572593499f4198c2ce9c6007fdb97ccc91 |
| hovercard-subject-tag | issue:6525003801 |
| 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/3886/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4cc7462e286a1700128a5d26181e6a923f40dd11ebbdfc972d5a7eb76b861454/modelcontextprotocol/python-sdk/issues/3886 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4cc7462e286a1700128a5d26181e6a923f40dd11ebbdfc972d5a7eb76b861454/modelcontextprotocol/python-sdk/issues/3886 |
| og:image:alt | Initial Checks I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1) I confirm that I searched for my issue in https://github.com/modelcontex... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 0718lol |
| hostname | github.com |
| expected-hostname | github.com |
| None | 708c2f10d746dbcf1dd80dc8309daa7d595df3fce8066244380fc3238618f09c |
| 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 | 2a29e3cf4fb57e81fd311774f91f345cc4436f40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width