使用说明
OpenAPI的MCP服务器
OpenAPI规范中的MCP服务器实现,支持SSE(服务器发送事件)和流式响应。
先决条件
- Python 3.x
- pip(Python包管理器)
- 无烟煤API密钥(适用于MCP客户)
- Google API密钥(适用于ADK代理)
安装
- 创建并激活虚拟环境:
python3 -m venv venv
source venv/bin/activate
- 安装依赖项:
pip install -r requirements.txt
服务器安装程序
服务器可以在两种模式下运行:
SSE模式
python server/mcp_server_sse.py --spec server/httpbin_openapi.yaml --name httpbin --base-url https://httpbin.org
流媒体模式
python server/mcp_server_stream.py --spec server/httpbin_openapi.yaml --name httpbin --base-url https://httpbin.org
客户端设置
MCP客户端
- 创建一个
.env文件,并添加您的Anthropic API密钥:
ANTHROPIC_API_KEY=your_api_key_here
- 运行您选择的客户端:
- 对于 SSE 客户端:
python client/sse_client.py- 对于流媒体客户端:
python client/stream_client.py
MCP或流媒体客户端的示例用法:
MCP Client Started!
Type your queries or 'quit' to exit.
Query: Get Headers
I'll help you get the headers using the api_call function.
[Calling tool api_call with args {'kwargs': '{"action": "get_headers"}'}]
Here are the headers from the response:
```json
{
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json",
"Host": "httpbin.org",
"User-Agent": "python-httpx/0.28.1",
"X-Amzn-Trace-Id": "Root=1-683fecc4-674af7e9323b027c4b9bc740"
}
ADK代理商
先决条件
- 安装ADK:
pip install google-adk
设置步骤
-
重要:流模式解决方法
- 下载最新
mcp_session_manager.py从 谷歌ADK存储库 - 替换ADK安装中的现有文件:
# Typical path (adjust Python version as needed) cp mcp_session_manager.py venv/lib/python3.13/site-packages/google/adk/tools/mcp_tool/
- 下载最新
-
导航到Clients目录:
cd client
-
配置环境:
- 添加以下内容
.env文件在两个httpb_sse_agent和httpbin_stream_agent目录:
GOOGLE_GENAI_USE_VERTEXAI="False" GOOGLE_API_KEY="your_google_api_key_here" - 添加以下内容
-
启动ADK web界面:
adk web
特性
- 基于OpenAPI规范的端点生成
- 支持SSE和流媒体响应
- 多种客户端实现(MCP和ADK)
- 通过环境变量轻松配置
故障排除
ADK流模式问题
如果您在流模式下遇到ADK代理问题:
- 验证您是否已更换
mcp_session_manager.py文件 - 检查您的Google API密钥是否在
.env文件 - 确保您使用的是最新版本的ADK
许可证
此项目根据Apache 2.0许可证获得许可。
