MCP服务器与客户端示例

一个基于Python的MCP服务器与客户端示例,用于演示服务器与客户端的交互。

  • by ShanGor
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 ShanGor/mcp-poc-python

使用说明

Python MCP 服务器和客户端示例

安装

  1. 安装 Python 3.12 或更高版本
  2. 使用 Python 模块 pip 安装 requirements.txt 文件中的依赖项

运行服务器:

使用 uvicorn 运行 test_mcp_server 模块中的 app 应用,主机设为 0.0.0.0,工作进程数为 1,端口设为 8000

运行客户端以测试服务器:

运行 python test_mcp_client.py

经验

  • 最好不要启用 json_response,因为在客户端关闭时会触发服务器错误。

    示例 mcp = FastMCP("StatelessServer", stateless_http=True, json_response=True)