# MCP Python SDK — Build MCP Servers & Clients > Build MCP servers and clients in Python with FastMCP, plus a CLI for dev and install flows; supports stdio, SSE, and Streamable HTTP transports. ## Install Save as a script file and run: # MCP Python SDK — Build MCP Servers & Clients > Build MCP servers and clients in Python with FastMCP, plus a CLI for dev and install flows; supports stdio, SSE, and Streamable HTTP transports. ## Quick Use 1. Install: ```bash pip install "mcp[cli]" ``` 2. Run: ```bash python -c "import mcp; print('mcp installed')" ``` 3. Verify: - Run one FastMCP demo server and confirm a tool call succeeds in the MCP inspector. --- ## Intro Build MCP servers and clients in Python with FastMCP, plus a CLI for dev and install flows; supports stdio, SSE, and Streamable HTTP transports. - **Best for:** Python teams building their own MCP tools (servers) or integrating MCP into internal agent runtimes - **Works with:** Python, uv/pip workflows, MCP transports (stdio/SSE/streamable HTTP) and FastMCP decorators - **Setup time:** 15 minutes ### Quantitative Notes - PyPI install group: `mcp[cli]` (repo docs) - GitHub stars + forks (verified): see Source & Thanks - Setup time ~15 minutes (Python env + one demo server + inspector) --- ## Practical Notes A minimal, reliable path is: build one FastMCP server with 1–2 tools, run it in dev mode, then validate with the official inspector. Only after that, add auth/env handling and move to HTTP transports. If you’re using Claude Code, prefer explicit install steps and keep tool inputs narrow and typed. **Safety note:** Don’t expose unconstrained exec/file tools over HTTP without an allowlist and auditing; MCP transports are powerful by design. ### FAQ **Q: Is this only for servers?** A: No. The SDK supports both building servers and writing MCP clients that connect to servers. **Q: Which transport should I pick?** A: Use stdio for local tools, and Streamable HTTP for production-like deployments; SSE is also supported. **Q: Do I need uv?** A: No. uv is recommended in docs, but pip works too (`pip install "mcp[cli]"`). --- ## Source & Thanks > GitHub: https://github.com/modelcontextprotocol/python-sdk > Owner avatar: https://avatars.githubusercontent.com/u/182288589?v=4 > License (SPDX): MIT > GitHub stars (verified via `api.github.com/repos/modelcontextprotocol/python-sdk`): 22,953 > GitHub forks (verified via `api.github.com/repos/modelcontextprotocol/python-sdk`): 3,411 --- # MCP Python SDK——用 Python 写 MCP Server/Client > 用 Python 构建 MCP server/client:提供 FastMCP 与 CLI 开发工具,支持 stdio、SSE 与 Streamable HTTP 传输,便于本地调试与集成。 ## 快速使用 1. 安装: ```bash pip install "mcp[cli]" ``` 2. 运行: ```bash python -c "import mcp; print('mcp installed')" ``` 3. 验证: - Run one FastMCP demo server and confirm a tool call succeeds in the MCP inspector. --- ## 简介 用 Python 构建 MCP server/client:提供 FastMCP 与 CLI 开发工具,支持 stdio、SSE 与 Streamable HTTP 传输,便于本地调试与集成。 - **适合谁(Best for):** 需要自建 MCP 工具(server)或把 MCP 接入内部 agent 运行时的 Python 团队 - **兼容工具(Works with):** Python、uv/pip 工作流、MCP 传输(stdio/SSE/streamable HTTP)与 FastMCP 装饰器 - **安装时间(Setup time):** 15 分钟 ### 量化信息 - PyPI 安装可选组:`mcp[cli]`(仓库文档) - GitHub stars + forks(已核验):见「来源与感谢」 - 跑通约 15 分钟(Python 环境 + demo server + inspector) --- ## 实战要点 最稳的落地路径:先用 FastMCP 写一个只包含 1–2 个工具的 server,用 dev 模式跑起来,再用官方 inspector 验证工具调用链路;跑通后再加鉴权/环境变量管理,并迁移到 HTTP 传输。如果接入 Claude Code,建议显式安装流程,并把工具入参做小且类型化。 **安全提示:** 不要在 HTTP 传输上暴露无约束的 exec/文件工具;MCP 天生能力强,需要白名单与审计配套。 ### FAQ **Q: 只能写 server 吗?** A: 不是。SDK 既能写 MCP server,也能写 MCP client 去连接现有 server。 **Q: 传输协议怎么选?** A: 本地工具优先 stdio;更接近生产的部署用 Streamable HTTP;SSE 也支持。 **Q: 一定要用 uv 吗?** A: 不必须。文档推荐 uv,但 pip 同样可用(`pip install "mcp[cli]"`)。 --- ## 来源与感谢 > GitHub:https://github.com/modelcontextprotocol/python-sdk > Owner avatar:https://avatars.githubusercontent.com/u/182288589?v=4 > 许可证(SPDX):MIT > GitHub stars(已通过 `api.github.com/repos/modelcontextprotocol/python-sdk` 核验):22,953 > GitHub forks(已通过 `api.github.com/repos/modelcontextprotocol/python-sdk` 核验):3,411 --- Source: https://tokrepo.com/en/workflows/mcp-python-sdk-build-mcp-servers-clients Author: MCP Hub