使用说明
带流式HTTP的MCP服务器
使用流式HTTP传输的模型上下文协议(MCP)服务器实现。
特性
- 可流式HTTP传输
- 示例工具:添加数字和发送问候
- 库存/积压物品端点
- 如果客户支持,可以使用新的工具、资源和提示轻松扩展。
先决条件
- Python 3.13+
- uv包管理器(推荐)或pip
安装
- 克隆存储库:
git clone https://github.com/edtemboml/mcp-server-remote.git
cd mcp-server-remote
- 创建并激活虚拟环境:
# Using uv (recommended)
uv venv
.\.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
# OR using standard venv
python -m venv .venv
.\.venv\Scripts\activate # Windows
source .venv/bin/activate # Linux/Mac
- 安装依赖项:
uv add fastmcp
uv add mcp[cli]
uv add asyncio
部署到Google Cloud Run(替代方案)
您可以将服务器部署到Google Cloud Run进行托管、可扩展的部署:
- 安装Google Cloud SDK并验证或使用Cloud Shell:
gcloud auth login
gcloud config set project YOUR_PROJECT_ID
- 在中配置部署设置
gcloud_infra.bash:
# Edit these variables in gcloud_infra.bash
export PROJECT_ID="your-project-id"
export REGION="your-region" # e.g., us-central1
export SERVICE_NAME="remote-mcp-server-1" # or anything fitting.
- 部署到云运行:
# Make the script executable
chmod +x gcloud_infra.bash
# Deploy
./gcloud_infra.bash
部署脚本将:
- 构建并推送Docker镜像
- 使用适当的设置部署到Cloud Run
- 输出服务URL
或者,在本地部署服务器
- 启动服务器:
uv run streamable_server.py
# OR
python streamable_server.py
可用工具和资源(注意:某些客户端不支持资源)
inventory://items/overstock-获取积压物品列表- 工具:
add(a: int, b: int)-加两个数字 - 工具:
say_hello(name: str)-向某人发送问候
发展
要添加新工具或资源,请执行以下操作:
- 打开
streamable_server.py - 使用添加新工具
@mcp.tool()装饰器 - 使用添加新资源
@mcp.resource()装饰器
看https://modelcontextprotocol.io/docs/getting-started/intro
例子:
@mcp.tool()
def your_new_tool(param: type) -> return_type:
"""Tool description."""
return result
许可证
MIT许可证