Bare `dict` / `list` / `tuple` return annotations silently produce no structured output
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Empieza leyendo _create_output_model en src/mcp/server/mcpserver/utilities/func_metadata.py y la documentación sobre salida estructurada en docs/servers/structured-output.md. Reproduce la diferencia entre las anotaciones de contenedor sin tipo y tipadas, y luego revisa las pruebas existentes para los esquemas de salida y el contenido estructurado. El trabajo estará terminado cuando las anotaciones simples de dict, list y tuple tengan el comportamiento esperado de salida estructurada y la documentación lo explique.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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)
- Lenguaje dominante
- Python
- Estrellas
- 24.6k
- Forks
- 4.2k
- Merge medio
- 18 h
- PR fusionados (30 d)
- 39
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de modelcontextprotocol/python-sdk
-
bug v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
modelcontextprotocol/python-sdk#3729 ·
Los mantenedores suelen responder en 1 día
-
bug v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/python-sdk#3698 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid valuesQuizá libre de nuevo @jayzuccarelli la tomó hace 7 días y no hay ningún pull request abierto. Abiertobug v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
modelcontextprotocol/python-sdk#3691 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Skills: URI traversal validation skips percent-encoded dot-segmentsPosiblemente ocupada @Varshith-Kali la tomó hace 6 días. Abiertobug v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
modelcontextprotocol/python-sdk#3685 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.pyQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abiertoenhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
modelcontextprotocol/python-sdk#3673 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de modelcontextprotocol/python-sdk
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
SublimeText/AdvancedNewFile#211 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Imbad0202/academic-research-skills#987 ·
Los mantenedores suelen responder en 1 día
-
Add date of request to the UIAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
Pull-through from gcr.io returns 500 when pulling using podman/buildahPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. AbiertoIssue Triage-Needed
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
pulp/pulp_container#2581 ·
Los mantenedores suelen responder en 1 día