一个桥接客户端,使本地的MCP(模型上下文协议)客户端(如Claude Desktop)能够连接到使用StreamableHTTP传输并需要OAuth认证的远程MCP服务器。
mcp-streamablehttp-client充当协议桥接器,转换以下内容:
这使得支持基于stdio的MCP服务器的工具可以无缝集成OAuth保护的MCP服务。
pixi add --pypi mcp-streamablehttp-client
pip install m
FROM python:3.11-slim
# 安装包
RUN pip install mcp-streamablehttp-client
# 设置工作目录
WORKDIR /app
# 复制.env文件(如果存在)
COPY .env* ./
# 运行客户端
CMD ["mcp-streamablehttp-client"]
services:
mcp-client:
image: mcp-streamablehttp-client:latest
build:
context: ./mcp-streamablehttp-client
environment:
- MCP_SERVER_URL=${MCP_SERVER_URL}
volumes:
- ./.env:/app/.env:ro
stdin_open: true
tty: true
# 使用docker-compose构建和运行
docker-compose up -d
首先,与您的MCP服务器进行身份验证:
# 使用just(推荐)
just auth
# 或直接
mcp-streamablehttp-client --token
这将引导您完成OAuth流程,并将您的凭据保存到.env中。
验证您的身份验证:
just test-auth
在您的claude_desktop_config.json中添加:
{
"mcpServers": {
"my-oauth-server": {
"command": "mcp-streamablehttp-client",
"env": {
"MCP_SERVER_URL": "https://mcp-fetch.yourdomain.com"
}
}
}
}
运行MCP工具命令:
# 列出可用工具
just list-tools
# 执行工具
just exec "fetch https://example.com"
just exec "echo message='Hello World'"
所有配置均通过.env中的环境变量完成:
| 变量 | 描述 | 是否必需 |
|---|---|---|
MCP_SERVER_URL | 目标MCP服务器URL | 是 |
MCP_CLIENT_ID | OAuth客户端ID | 自动生成 |
MCP_CLIENT_SECRET | OAuth客户端密钥 | 自动生成 |
MCP_CLIENT_ACCESS_TOKEN | 当前访问令牌 | 自动生成 |
MCP_CLIENT_REFRESH_TOKEN | 刷新令牌 | 自动生成 |
MCP_CLIENT_REGISTRATION_TOKEN | RFC 7592管理令牌 | 自动生成 |
MCP_CLIENT_REGISTRATION_URI | RFC 7592管理端点 | 自动生成 |
# 设置或刷新OAuth令牌
mcp-streamablehttp-client --token
# 测试身份验证状态
mcp-streamablehttp-client --test-auth
# 清除所有凭据
mcp-streamablehttp-client --reset-auth
# 列出可用工具
mcp-streamablehttp-client --list-tools
# 列出可用资源
mcp-streamablehttp-client --list-resources
# 列出可用提示
mcp-streamablehttp-client --list-prompts
# 执行工具命令
mcp-streamablehttp-client -c "tool_name arguments"
# 获取客户端注册信息
mcp-streamablehttp-client --get-client-info
# 更新客户端注册
mcp-streamablehttp-client --update-client "client_name=New Name,contacts=admin@example.com"
# 删除客户端注册
mcp-streamablehttp-client --delete-client
# 发送原始JSON-RPC请求
mcp-streamablehttp-client --raw '{"jsonrpc": "2.0", "method": "tools/list", "id": 1}'
# 作为持续代理运行(用于Claude Desktop)
mcp-streamablehttp-client
客户端支持多种参数格式以提高灵活性:
# JSON格式(适用于复杂参数)
mcp-streamablehttp-client -c 'tool {"key": "value", "nested": {"foo": "bar"}}'
# 键值对格式
mcp-streamablehttp-client -c 'tool key1=value1 key2=value2'
# 智能检测(URL、路径等)
mcp-streamablehttp-client -c 'fetch https://example.com'
mcp-streamablehttp-client -c 'read_file /path/to/file.txt'
# 简单字符串参数
mcp-streamablehttp-client -c 'echo "Hello World"'
┌─────────────────────┐ stdio ┌──────────────────────┐ HTTP + OAuth ┌─────────────────┐
│ Claude Desktop │ ←------------→ │ mcp-streamablehttp- │ ←----------------→ │ Remote MCP │
│ (或其他stdio │ JSON-RPC │ client │ StreamableHTTP │ Server │
│ MCP客户端) │ │ (协议桥接器) │ │ (OAuth保护) │
└─────────────────────┘ └──────────────────────┘ └─────────────────┘
客户端充当透明桥接器,处理:
.env文件中# 运行所有测试
just test
# 运行特定测试
just test-auth
# 构建Docker镜像
just build
# 不使用缓存重新构建
just rebuild
“未找到凭据”
mcp-streamablehttp-client --token进行身份验证“令牌已过期”
--token强制刷新“未找到OAuth服务器”
MCP_SERVER_URL是否正确“权限被拒绝”
设置环境变量以启用详细日志记录:
export MCP_DEBUG=1
mcp-streamablehttp-client --test-auth
查看examples/目录:
claude_desktop_config.json - Claude Desktop配置command_examples.sh - 常见命令模式demo.py - Python集成示例token_example.md - OAuth流程指南[许可信息在此处]
[贡献指南在此处]