Bare `dict` / `list` / `tuple` return annotations silently produce no structured output
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend-api-design
Rechercherichtung
Lies zuerst _create_output_model in src/mcp/server/mcpserver/utilities/func_metadata.py und die Dokumentation zur strukturierten Ausgabe unter docs/servers/structured-output.md. Reproduziere den Unterschied zwischen einfachen und typisierten Containerannotationen und prüfe dann die bestehenden Tests für Ausgabeschemas und strukturierte Inhalte. Fertig ist die Arbeit, wenn einfache dict-, list- und tuple-Annotationen das erwartete Verhalten bei der strukturierten Ausgabe haben und die Dokumentation es erklärt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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 opening this issue
Release line
2.x (current stable)
Description
A tool annotated with a bare dict (or list / tuple) gets no outputSchema and no structuredContent. The result only arrives as JSON text. -> dict[str, Any] works, and -> str gets {"result": ...}. With structured_output=True the bare annotation raises InvalidSignature: Function f: return type <class 'dict'> is not serializable for structured output, which reads as if a dict weren't serializable.
Expected: -> dict behaves like dict[str, Any], and -> list / -> tuple like list[Any] (wrapped in {"result": ...}). Failing that, the structured-output docs could say that bare containers opt out.
Cause: _create_output_model sends bare dict / list / tuple to the "other class types" case. get_type_hints(dict) is empty, so the model stays None: the silent opt-out documented for classes without type hints, which isn't obvious for builtins. We hit it while building an MCP server: our tools were -> dict, and our client code expected structured_content that was always None.
Proposed fix: a case before the class fallback that sends bare dict down the dict[str, ...] path and wraps bare list / tuple like their generic forms, plus a test and one sentence in docs/servers/structured-output.md. It's about 10 lines of code, and the full suite passes (6206 passed). One behaviour change to weigh: existing bare -> dict / -> list tools would start publishing an outputSchema and validating their results.
I'd like to send this as a PR if you're open to it. It's on a branch: https://github.com/g-s-jithesh/python-sdk/commit/6ecfa04ece6032816c7d3a087fd8c841cb0c43e1
I used an AI coding assistant (Claude Code) to help investigate this and draft the fix. I reproduced the bug myself and reviewed the change.
Example Code
import asyncio
from typing import Any
from mcp import Client
from mcp.server.mcpserver import MCPServer
mcp = MCPServer("repro")
@mcp.tool()
def bare() -> dict:
return {"id": 1}
@mcp.tool()
def typed() -> dict[str, Any]:
return {"id": 1}
async def main() -> None:
async with Client(mcp) as client:
for name in ("bare", "typed"):
print(name, (await client.call_tool(name, {})).structured_content)
asyncio.run(main())
# bare None
# typed {'id': 1}
Python & MCP Python SDK
Python 3.14, Windows 11; mcp 2.3.0, and main at 9f66f37 (src/mcp/server/mcpserver/utilities/func_metadata.py, _create_output_model)
- Vorherrschende Sprache
- Python
- Sterne
- 24.5k
- Forks
- 4k
- Ø Merge
- 18 Std.
- Gemergte PRs (30 T.)
- 39
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/python-sdk
-
bug v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/python-sdk#3698 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid valuesEvtl. vergeben @jayzuccarelli hat das vor 6 Tagen übernommen. Offenbug v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
modelcontextprotocol/python-sdk#3691 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Skills: URI traversal validation skips percent-encoded dot-segmentsEvtl. vergeben @Varshith-Kali hat das vor 5 Tagen übernommen. Offenbug v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
modelcontextprotocol/python-sdk#3685 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.pyEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offenenhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
modelcontextprotocol/python-sdk#3673 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Streamable HTTP server rejects a mixed-case Content-Type with 415Evtl. wieder frei @CRYPTONIKAV hat das vor 8 Tagen übernommen, und es ist kein Pull Request offen. Offenbug v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
modelcontextprotocol/python-sdk#3670 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in modelcontextprotocol/python-sdk
Ähnliche Issues
-
comp/cli P3 type/security
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
NousResearch/hermes-agent#141420 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
vendor-pitch
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 87/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug llm p2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
New tool: ZIPZAX Python Notebook StudioEvtl. vergeben @github-actions hat das heute übernommen. Offensubmission triage
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
kausalflow/tools#226 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100