项目概述
模型上下文协议(MCP)服务器,使OpenAI的gpt-4o-search-preview模型可以通过MCP访问。
app/app.py:主要应用程序入口点。requirements.txt:列出运行应用程序所需的Python依赖项。- :在Docker容器中构建和运行应用程序的说明。
.env.example:示例环境变量文件。将此复制到.env并根据需要更新值。
______________________________________________________________________
部署说明
1.环境变量
在运行应用程序之前,请设置环境变量:
- 复制
.env.example向.env:
cp .env.example .env- 编辑
.env并根据您的环境需要更新这些值。
2.使用Docker部署
- 构建Docker镜像:
docker build -t my-python-app -f dockerfile .- 运行容器:
docker run --env-file .env -p 8000:8000 my-python-app3.使用Python(virtualenv)进行部署
- 创建并激活虚拟环境:
python3 -m venv venv
source venv/bin/activate- 安装依赖项:
pip install -r requirements.txt- 设置环境变量(请参见
.env.example). - 运行应用程序:
python app/app.py______________________________________________________________________
示例:使用roo代码连接到MCP
下面是一个示例配置块 gpt-4o-search MCP服务:
"gpt-4o-search": {
"url": "http://link-to-where-service-is-hosted:8000/sse",
"transport": "http",
"alwaysAllow": [
"search"
],
"timeout": 300
}Python示例:执行“搜索”操作
以下Python代码演示了如何使用上述配置连接到MCP服务,并使用roo代码原理执行“搜索”操作。此示例使用 requests 库向MCP端点发送搜索请求。
from mcp import MCPClient
# Initialize the MCP client for the gpt-4o-search server
client = MCPClient("http://link-to-where-service-is-hosted:8000/sse")
# Perform a "search" operation
result = client.tool("search", {"query": "What is Model Context Protocol?"})
print("Search result:", result)
### Explanation
- **MCPClient**: The official `mcp` Python library provides the `MCPClient` class to connect to an MCP server.
- **client = MCPClient(...)**: Initializes the client with the URL of the gpt-4o-search MCP server.
- **client.tool("search", {...})**: Performs the "search" operation by specifying the tool name and parameters as a dictionary.
- **Result**: The result of the search operation is printed.
---
# Notes
- Only perform the work outlined above and do not deviate from these instructions.
- For further details, refer to the individual files and comments within the codebase.```