Bare `dict` / `list` / `tuple` return annotations silently produce no structured output
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
先阅读 src/mcp/server/mcpserver/utilities/func_metadata.py 中的 _create_output_model,以及 docs/servers/structured-output.md 中关于结构化输出的文档。复现未指定类型的容器注释与指定类型的容器注释之间的差异,然后检查现有的输出 schema 和结构化内容测试。未指定类型的 dict、list 和 tuple 注释具有预期的结构化输出行为,并且文档对此作出说明,即为完成。
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- Python
- 星标
- 24.5k
- 派生
- 4k
- 平均合并
- 18 小时 28 分钟
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/python-sdk 的其他 Issue
-
2026-07-28 SSE responses share one header list, so in-place middleware appends leak across responses可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug spec-2026-07-28 v2
难度 2/5 1-3 小时 新手友好度 68/100
modelcontextprotocol/python-sdk#3701 · 1 条评论 ·
维护者通常 1 天内回复
-
bug v1 v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/python-sdk#3698 · 1 条评论 ·
维护者通常 1 天内回复
-
Streamable HTTP: Content-Type handling is order dependent and accepts invalid values可能已有人在做 @jayzuccarelli 于 5 天前认领。 未关闭bug v1 v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3691 · 1 条评论 ·
维护者通常 1 天内回复
-
Skills: URI traversal validation skips percent-encoded dot-segments可能已有人在做 @Varshith-Kali 于 4 天前认领。 未关闭bug v2
难度 2/5 1-3 小时 新手友好度 78/100
modelcontextprotocol/python-sdk#3685 · 2 条评论 ·
维护者通常 1 天内回复
-
Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.py可能重新可做 关联的 PR 已关闭且未合并。 未关闭enhancement
难度 2/5 1-3 小时 新手友好度 84/100
modelcontextprotocol/python-sdk#3673 · 4 条评论 ·
维护者通常 1 天内回复
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
sierra-research/tau2-bench#635 ·
维护者通常 1 天内回复
-
The add-ssm-model skill requires a Cython simulator; the contributing guide allows Python ones可能已有人在做 @fmuia 今天认领。 未关闭documentation skill
难度 2/5 1-3 小时 新手友好度 83/100
lnccbrown/ssm-simulators#406 ·
维护者通常 4 天内回复
-
难度 1/5 1 小时以内 新手友好度 95/100
btclib-org/btclib-ecc#309 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
jbacalso24/mimry#459 · 1 条评论 ·
维护者通常 1 天内回复
-
auth bug high-priority
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复