此仓库提供了基于以下规范的MCP(模型上下文协议)可流式传输HTTP客户端和服务器的示例实现:📄 MCP可流式传输HTTP规范。
您可以完全使用Python或TypeScript来设置客户端+服务器堆栈。此示例还展示了跨语言兼容性,允许Python客户端与TypeScript服务器通信,反之亦然。
git clone https://github.com/invariantlabs-ai/mcp-streamable-http.git
cd python-example
更新python-example/client目录中的.env文件,内容如下:
ANTHROPIC_API_KEY=your_api_key_here
cd python-example/server
pip install .
python weather.py
默认情况下,服务器将在http://localhost:8123启动。
如果您想指定不同的端口,请使用--port标志:
python weather.py --port=9000
cd ../client
pip install .
python client.py
这将使用MCP可流式传输HTTP协议启动一个交互式聊天循环。
如果您在不同的端口上启动了MCP服务器,请使用--mcp-localhost-port标志指定它:
python client.py --mcp-localhost-port=9000
更新typescript-example/client目录中的.env文件,内容如下:
ANTHROPIC_API_KEY=your_api_key_here
cd typescript-example/server
npm install && npm run build
node build/index.js
默认情况下,服务器将在http://localhost:8123启动。
如果您想指定不同的端口,请使用--port标志:
node build/index.js --port=9000
cd ../client
npm install && npm run build
node build/index.js
这将使用MCP可流式传输HTTP协议启动一个交互式聊天循环。
如果您在不同的端口上启动了MCP服务器,请使用--mcp-localhost-port标志指定它:
node build/index.js --mcp-localhost-port=9000
在客户端聊天界面中,您可以提出如下问题:
客户端会将请求转发到本地的MCP天气服务器,并使用Anthropic的Claude语言模型返回结果。使用的MCP传输层将是可流式传输HTTP。