python-sdk
The official Python SDK for Model Context Protocol servers and clients
- 评测生成时间(北京时间)
- 本报告引擎
- v3.9.1
- 当前引擎
- v3.16.0
本报告与当前引擎使用不同规则;原分数不会自动更新,不同版本的分数不宜直接对比。
进入后确认来源与额度,提交才会创建任务。
综合采用结论
证据充分,整体质量与安全表现优秀
- 基础评测完成+25/25确定性评分与静态安全扫描已完成
- README 有效证据+13/255,142 个去重后的有效字符
- 独立证据来源+16/204 类非重复证据,重复文件不叠加
- 仓库元数据+10/10已取得仓库状态与采用数据
- 活跃记录+5/5已取得最近提交时间
- AI 复核+15/15已完成结构化 AI 证据复核
MCP客户端与服务器交互流程
README展示了客户端通过HTTP调用服务器工具的过程,存在请求和响应关系。
左右滑动查看完整图示
- • 客户端示例:async with Client("http://localhost:8000/mcp") as client:
- • 调用:await client.call_tool("add", {"a": 1, "b": 2})
- • 响应:print(result.structured_content) # {'result': 3}
- 安装命令:uv add "mcp[cli]" 或 pip install "mcp[cli]"
- 服务器示例:@mcp.tool() 和 @mcp.resource() 定义工具和资源
- 客户端示例:async with Client("http://localhost:8000/mcp") 调用工具
- 传输方式:stdio、Streamable HTTP、SSE
- 文档链接:https://py.sdk.modelcontextprotocol.io/ 包含Get started、API reference等
- 问题与用途描述
- 有效 README
- 安装或接入步骤
- 可执行示例
- 未发现已知高风险模式
- 缺少错误处理或排障
- 缺少错误处理和排障章节
- 未明确说明权限和数据边界
- 未提供安全默认值或安全配置说明
- 未提及失败处理机制
构建MCP服务器和客户端的Python开发者、需要快速原型验证的开发者、需要标准传输方式(stdio、HTTP)的项目、希望利用类型提示自动生成JSON Schema的场景
需要详细错误处理指南的开发者、需要安全配置或权限边界文档的场景
也有自己的公开项目?先看完证据,再用当前规则生成独立报告。
评测我的项目 →静态扫描不是安全保证,生产接入前仍应人工复核权限和数据边界。
- 01补充错误处理或排障
方法、证据与局限展开收起
GitHub Repository API
4 个文件 · 9,503 字符
v3.9.1 · AI 复核已启用(deepseek-chat)
- 静态评测不会安装或执行项目代码
- 安全扫描基于高信号文件与已知模式,不能替代人工审计
- 流行度只反映采用程度,不代表安全或工程质量
30 天热度趋势
README
MCP Python SDK
[!NOTE] This is v2 of the MCP Python SDK, the current stable release line. It is a major rework of the SDK, both to support the 2026-07-28 MCP specification (and every earlier revision) and to fix long-standing architectural issues. Coming from v1? See What's new in v2 for the tour of what changed and the migration guide for every breaking change.
Not ready to migrate? v1.x lives on the
v1.xbranch, continues to receive critical bug fixes and security patches, and is documented at https://py.sdk.modelcontextprotocol.io/v1/. Sincepip install mcpnow installs 2.x, keep a<2upper bound on your requirement (for examplemcp>=1.28,<2) until you've migrated.Something rough, confusing, or broken? Open an issue or find us in #python-sdk-dev on the MCP Contributors Discord.
Documentation
The documentation lives at https://py.sdk.modelcontextprotocol.io/.
It has a Get started guide, What's new in v2, the API reference, and the migration guide.
What is MCP?
The Model Context Protocol lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but designed for LLM interactions. With this SDK you can:
- Build MCP servers that expose tools, resources, and prompts to any MCP host
- Build MCP clients that connect to any MCP server
- Speak every standard transport: stdio, Streamable HTTP, and SSE
Requirements
Python 3.10+.
Installation
uv add "mcp[cli]" # or: pip install "mcp[cli]"
The cli extra adds the mcp command-line tool (mcp dev, mcp run, mcp install) on top of the SDK; install plain mcp if you don't need it. For one-off commands, uv run --with "mcp[cli]" mcp ... works without a project.
A server in 15 lines
Create a server.py:
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.resource("greeting://{name}")
def greeting(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"
Full example: docs_src/index/tutorial001.py
That's a complete MCP server: one tool, one templated resource. Open it in the MCP Inspector:
uv run mcp dev server.py
Call add with a=1, b=2 and you get 3 back.
Notice what you did not write: no JSON Schema (a: int, b: int is the schema), no request parsing, no validation code, no protocol handling. Two type-hinted Python functions and a docstring.
Get started takes it from here.
A client in 10 lines
The same package is a full MCP client. Serve server.py over HTTP:
uv run mcp run server.py --transport streamable-http
then point a Client at it:
import asyncio
from mcp import Client
async def main() -> None:
async with Client("http://localhost:8000/mcp") as client:
result = await client.call_tool("add", {"a": 1, "b": 2})
print(result.structured_content) # {'result': 3}
asyncio.run(main())
A URL means Streamable HTTP, the transport you deploy. Client can also launch a local server as a stdio subprocess or take any custom transport; Clients has the rest.
Contributing
We are passionate about supporting contributors of all levels of experience and would love to see you get involved in the project. See the contributing guide to get started.
License
This project is licensed under the MIT License. See the LICENSE file for details.