流MCP服务器
暴露 27工具 跨六个资源域——支付链接、客户、产品、优惠券、发票和支付——以及一个只读的OpenAPI文档资源。
______________________________________________________________________
快速开始
1.安装
# Clone & install in editable mode
git clone stream-mcp-server && cd stream-mcp-server
pip install -e ".[dev]"2.配置
cp .env.example .env
# Edit .env and set your Stream API key:
# STREAM_API_KEY=sk_live_…| 变量 | 默认值 | 描述 |
|---|---|---|
STREAM_API_KEY | *(stdio模式需要)* | 您的Stream API密钥 |
STREAM_BASE_URL | https://stream-app-service.streampay.sa | API基本URL |
STREAM_OPENAPI_URL | https://stream-app-service.streampay.sa/openapi.json | OpenAPI规范URL(独立于 STREAM_BASE_URL,例如分期) |
STREAM_TIMEOUT | 30 | 请求超时(秒) |
STREAM_MAX_RETRIES | 2 | 429/5xx的重试次数 |
HOST | 0.0.0.0 | 远程服务器绑定主机(stream-mcp-remote) |
PORT | 8000 | 远程服务器绑定端口(stream-mcp-remote) |
3.跑步
本地stdio模式(推荐)
stream-mcp远程HTTP模式(URL客户端)
# No STREAM_API_KEY needed on the server process in remote mode
HOST=0.0.0.0 PORT=8000 stream-mcp-remote端点:
http://localhost:8000/mcp______________________________________________________________________
MCP客户端配置(克劳德桌面/光标/VS代码)
在MCP配置文件中使用这两种模式之一(claude_desktop_config.json 或 mcp.json).
选项A:stdio
{
"mcpServers": {
"stream": {
"command": "stream-mcp",
"env": {
"STREAM_API_KEY": "sk_live_your_key_here"
}
}
}
}选项B:远程URL(stream-mcp-remote)
{
"mcpServers": {
"stream": {
"url": "http://localhost:8000/mcp",
"headers": {
"Authorization": "Bearer sk_live_your_key_here"
}
}
}
}______________________________________________________________________
可用工具
付款链接
| 工具 | 说明 |
|---|---|
create_payment_link | 创建新的结账/付款链接 |
list_payment_links | 带可选状态过滤器的分页列表 |
get_payment_link | 按ID获取单个支付链接 |
deactivate_payment_link | 停用/存档付款链接 |
客户
| 工具 | 说明 |
|---|---|
create_customer | 使用姓名、电子邮件、电话和元数据创建客户 |
list_customers | 分页客户列表 |
get_customer | 通过ID获取单个客户 |
update_customer | 更新客户字段 |
delete_customer | 软删除客户 |
产品
| 工具 | 说明 |
|---|---|
create_product | 创建一次性或重复使用的产品 |
list_products | 列出带有可选类型过滤器的产品 |
get_product | 按ID获取单个产品 |
update_product | 更新产品名称、描述或价格 |
archive_product | 存档产品 |
优惠券
| 工具 | 说明 |
|---|---|
create_coupon | 创建固定或百分比折扣优惠券 |
list_coupons | 列出带有可选状态过滤器的优惠券 |
get_coupon | 凭身份证领取一张优惠券 |
deactivate_coupon | 停用优惠券 |
发票
| 工具 | 说明 |
|---|---|
create_invoice | 创建符合ZATCA标准的发票 |
list_invoices | 列出带有过滤器的发票 |
get_invoice | 按ID获取单个发票 |
send_invoice | 通过电子邮件/短信(重新)发送发票 |
void_invoice | 作废/取消未付发票 |
支付
| 工具 | 说明 |
|---|---|
list_payments | 使用筛选器列出付款 |
get_payment | 获取付款详细信息 |
refund_payment | 全额或部分退款 |
资源
| 资源URI | 描述 |
|---|---|
stream://docs/openapi | API主机的完整流OpenAPI规范(缓存、自动刷新) |
______________________________________________________________________
远程部署(托管URL)
您可以将MCP服务器部署为 托管URL 因此用户可以远程连接到它。
每个用户传递他们自己的Stream API密钥作为承载令牌。
1.本地运行(远程模式)
# No STREAM_API_KEY needed — each user provides their own
stream-mcp-remote
# → Listening on http://0.0.0.0:8000
# Custom host/port
HOST=0.0.0.0 PORT=3000 stream-mcp-remote2.使用Docker进行部署
docker build -t stream-mcp .
docker run --rm -p 8000:8000 -e HOST=0.0.0.0 stream-mcp如果你使用 --env-file 从一个 本地 .env 这设置 HOST=127.0.0.1,该进程仅在环回上侦听 里面 容器,主机将看到 ECONNREFUSED 上 localhost:8000。要么省略 HOST 在Docker的那个文件中,或者通过 -e HOST=0.0.0.0 之后 --env-file 所以它会被覆盖。
3.用户如何连接(远程)
用户将此添加到他们的MCP客户端配置中:
克劳德桌面/VS代码:
{
"mcpServers": {
"stream": {
"url": "https://your-domain.com/mcp",
"headers": {
"Authorization": "Bearer sk_live_YOUR_STREAM_API_KEY"
}
}
}
}每个用户通过他们的 拥有 流式传输API密钥作为承载令牌。 服务器从不存储密钥——它们仅在会话期间使用。
______________________________________________________________________
项目结构
src/stream_mcp/
├── server.py # FastMCP app entry-point (local + remote modes)
├── config.py # Settings from env vars
├── client.py # Async HTTP client (auth, retries, errors)
├── auth.py # Bearer token middleware (remote mode)
├── helpers.py # get_client() — resolves per-request StreamClient
├── models/ # Pydantic v2 request/response models
│ ├── payment_links.py
│ ├── customers.py
│ ├── products.py
│ ├── coupons.py
│ ├── invoices.py
│ └── payments.py
└── tools/ # FastMCP tool definitions
├── __init__.py # Registers all tools
├── payment_links.py
├── customers.py
├── products.py
├── coupons.py
├── invoices.py
├── payments.py
└── docs.py # OpenAPI resource添加新的资源域 =在中添加一个文件 models/,一个 tools/,以及一条进口线 tools/__init__.py.
______________________________________________________________________
错误处理
所有工具捕捉 StreamAPIError 并返回一个结构化的dict,而不是引发:
{
"error": true,
"code": 422,
"message": "Validation failed: …"
}这确保了LLM代理始终收到可用的响应。
______________________________________________________________________
发展
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v______________________________________________________________________
许可证
麻省理工学院
