精选85MCP Python SDK(GitHub Releases)AI 编程与模型
MCP Python SDK v2.1.0:客户端直接接受 StdioServerParameters
v2.1.0
推荐理由
MCP Python SDK 是 AI 编程与模型开发的核心依赖,v2.1.0 引入了破坏性行为变更(异常处理与内容块返回),直接影响现有工具开发。建议升级前仔细阅读变更说明,调整代码以适配新行为。
Highlights
亮点
- Client accepts StdioServerParameters directly: Client(StdioServerParameters(command="uv", args=["run", "server.py"])) (#3321).
- Prompt messages accept Image and Audio, prompt functions may return bare content blocks, and Message / UserMessage / AssistantMessage are exported from mcp.server.mcpserver (#3320).
- The 4 MiB request body limit now also covers the SSE transport and the OAuth endpoints; SseServerTransport and MCPServer.sse_app() take max_request_body_size, and the SSE message endpoint answers 405 to non-POST requests (#3336).
- 客户端直接接受 StdioServerParameters:Client(StdioServerParameters(command="uv", args=["run", "server.py"])) (#3321)。
- 提示消息接受图像和音频,提示函数可以返回裸内容块,并且 Message / UserMessage / AssistantMessage 从 mcp.server.mcpserver 导出 (#3320)。
- 4 MiB 请求体限制现在也适用于 SSE 传输和 OAuth 端点;SseServerTransport 和 MCPServer.sse_app() 接受 max_request_body_size,并且 SSE 消息端点对非 POST 请求返回 405 (#3336)。
Behaviour changes to be aware of
需要注意的行为变更
- Handler exceptions (#3314): an unexpected exception from a tool, resource or prompt handler is logged once at ERROR with its traceback, and the client now sees only Error executing tool <name> (or the resource/prompt equivalent) rather than the exception text. Raise ToolError / ResourceError when the message is meant for the model; those still reach the client and are logged at INFO without a traceback.
- Content-block return annotations (#3320): a tool annotated to return TextContent, EmbeddedResource, Image, Audio, or lists/unions of them no longer advertises outputSchema or returns structuredContent; its content is unchanged. Pass structured_output=True to keep the previous shape.
- 处理器异常 (#3314):来自工具、资源或提示处理器的意外异常会以 ERROR 级别记录一次并附带堆栈跟踪,客户端现在只能看到“执行工具 <名称> 时出错”(或资源/提示的等效消息),而不是异常文本。当消息旨在发送给模型时,请抛出 ToolError / ResourceError;这些错误仍然会到达客户端,并以 INFO 级别记录,不附带堆栈跟踪。
- 内容块返回注解 (#3320):注解为返回 TextContent、EmbeddedResource、Image、Audio 或它们的列表/联合类型的工具不再公布 outputSchema 或返回 structuredContent;其内容保持不变。传递 structured_output=True 以保持之前的形状。
Fixes
修复
- TypedDict tool results: NotRequired keys are omitted instead of serialized as null, and registration no longer fails on Python 3.10 (#3224, #3227); recursive return types get an object-rooted outputSchema that pre-2026 clients accept (#3337).
- 2026-07-28 over HTTP: a POSTed notification such as notifications/cancelled is acknowledged with 202 instead of rejected with 400 (#3324).
- Pre-2026 sessions ignore cache-hint fields from later revisions instead of failing list_tools() (#3223), and accept boolean sub-schemas in tool schema properties (#3353).
- mcp install reads and preserves a Claude Desktop config containing non-ASCII text on any Windows code page (#3296).
- TypedDict 工具结果:NotRequired 键被省略而不是序列化为 null,并且在 Python 3.10 上注册不再失败 (#3224, #3227);递归返回类型获得对象根 outputSchema,2026 年前的客户端可以接受 (#3337)。
- 通过 HTTP 的 2026-07-28:POST 通知(如 notifications/cancelled)以 202 确认,而不是以 400 拒绝 (#3324)。
- 2026 年前的会话忽略来自后续修订的缓存提示字段,而不是使 list_tools() 失败 (#3223),并接受工具模式属性中的布尔子模式 (#3353)。
- mcp install 读取并保留包含非 ASCII 文本的 Claude Desktop 配置,适用于任何 Windows 代码页 (#3296)。
What's Changed
变更内容
- Retire wording tied to pre-2.0 milestones by @maxisbey in #3211
- Describe the maintenance line without hardcoding 1.28 by @maxisbey in #3212
- Ask which release line a bug report is on by @maxisbey in #3213
- Link the released 2026-07-28 spec and point migrators at /v1/ by @maxisbey in #3214
- Bump conformance harness to 0.2.0-alpha.11 by @maxisbey in #3282
- Read UTF-8 test fixtures with explicit encoding by @ShuQingDollarVoyager in #3245
- Pin each conformance leg to a spec-revision wire by @maxisbey in #3304
- docs: publish translated docs in twelve languages and the tool that maintains them by @maxisbey in #3280
- Pin text I/O to UTF-8 and fail CI on locale-dependent reads/writes by @maxisbey in #3296
- docs: lead the README client example with a URL, not the server object by @maxisbey in #3315
- Publish versioning, roadmap, and dependency policies for v2 by @maxisbey in #3215
- Drop later-revision cache-hint fields on pre-2026 sessions by @maxisbey in #3223
- Stop framing breaking changes as a workflow in AGENTS.md by @maxisbey in #3286
- MCPServer: content-block returns are unstructured, prompt messages take Image/Audio by @maxisbey in #3320
- Let Client take StdioServerParameters directly by @maxisbey in #3321
- Gate external PRs on an assigned, linked issue by @maxisbey in #3291
- docs: cover the remaining Tier 1 audit items by @maxisbey in #3325
- Acknowledge notification POSTs with 202 on the 2026-07-28 HTTP entry by @maxisbey in #3326
- Shorten stdio test comments by @Kludex in #3329
- Hand TypedDict tool results to pydantic natively by @maxisbey in #3331
- Apply the request body limit to the SSE and OAuth endpoints by @maxisbey in #3336
- Accept boolean sub-schemas in 2025-11-25 tool schema properties by @pja-ant in #3354
- Log MCPServer handler exceptions by kind and keep crash details off the wire by @maxisbey in #3314
- Give recursive tool return types an object-rooted output schema by @maxisbey in #3376
- docs: refresh translations for recent English changes by @maxisbey in #3379
- Build releases with the pinned hatchling and a publish action that accepts Metadata 2.5 by @maxisbey in #3380
- 由 @maxisbey 在 #3211 中移除与 2.0 之前里程碑相关的措辞
- 由 @maxisbey 在 #3212 中描述维护线,不硬编码 1.28
- 由 @maxisbey 在 #3213 中询问错误报告所在的发布线
- 由 @maxisbey 在 #3214 中链接已发布的 2026-07-28 规范,并引导迁移者访问 /v1/
- 由 @maxisbey 在 #3282 中将一致性测试工具提升到 0.2.0-alpha.11
- 由 @ShuQingDollarVoyager 在 #3245 中使用显式编码读取 UTF-8 测试夹具
- 由 @maxisbey 在 #3304 中将每个一致性测试分支固定到规范修订版本
- 文档:发布十二种语言的翻译文档及维护这些文档的工具,由 @maxisbey 在 #3280 中完成
- 将文本 I/O 固定为 UTF-8,并在依赖区域设置的读写操作上使 CI 失败,由 @maxisbey 在 #3296 中完成
- 文档:在 README 客户端示例中首先展示 URL,而非服务器对象,由 @maxisbey 在 #3315 中完成
- 发布 v2 的版本控制、路线图和依赖策略,由 @maxisbey 在 #3215 中完成
- 在 2026 年前的会话中移除较新修订的缓存提示字段,由 @maxisbey 在 #3223 中完成
- 停止在 AGENTS.md 中将破坏性变更描述为工作流程,由 @maxisbey 在 #3286 中完成
- MCPServer:内容块返回为非结构化,提示消息接受图像/音频,由 @maxisbey 在 #3320 中完成
- 让 Client 直接接受 StdioServerParameters,由 @maxisbey 在 #3321 中完成
- 外部 PR 需关联已分配的问题,由 @maxisbey 在 #3291 中完成
- 文档:覆盖剩余的 Tier 1 审计项,由 @maxisbey 在 #3325 中完成
- 在 2026-07-28 HTTP 入口上以 202 状态确认通知 POST,由 @maxisbey 在 #3326 中完成
- 缩短 stdio 测试注释,由 @Kludex 在 #3329 中完成
- 将 TypedDict 工具结果原生传递给 pydantic,由 @maxisbey 在 #3331 中完成
- 将请求体限制应用于 SSE 和 OAuth 端点,由 @maxisbey 在 #3336 中完成
- 在 2025-11-25 工具模式属性中接受布尔子模式,由 @pja-ant 在 #3354 中完成
- 按类型记录 MCPServer 处理程序异常,并避免将崩溃细节发送到网络上,由 @maxisbey 在 #3314 中完成
- 为递归工具返回类型提供以对象为根的输出模式,由 @maxisbey 在 #3376 中完成
- 文档:刷新近期英文变更的翻译,由 @maxisbey 在 #3379 中完成
- 使用固定的 hatchling 和接受 Metadata 2.5 的发布操作构建版本,由 @maxisbey 在 #3380 中完成
New Contributors
新贡献者
- @ShuQingDollarVoyager made their first contribution in #3245
- @ShuQingDollarVoyager 在 #3245 中做出了首次贡献
Full Changelog: v2.0.0...v2.1.0
完整变更日志:v2.0.0...v2.1.0
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力