带有 Docker 的 MCP 服务器
该项目演示了如何将模型控制协议 (MCP) 与 OpenAI 的 API 集成,使 OpenAI 能够访问和使用在 Docker 中运行的 MCP 服务器公开的工具。
先决条件
您的系统上安装了 Docker
Git(克隆存储库)
项目结构
server.py
:使用工具实现的 MCP 服务器client.py
:连接服务器并调用代理的客户端Dockerfile
:构建 Docker 镜像的说明requirements.txt
:项目的 Python 依赖项
数据流解释
用户查询:用户向系统发送查询(例如,“我们公司的休假政策是什么?”)
OpenAI API :OpenAI 从 MCP 服务器接收查询和可用工具
工具选择:OpenAI 根据查询决定使用哪些工具
MCP Client :客户端接收OpenAI的工具调用请求,并转发给MCP服务器
MCP 服务器:服务器执行请求的工具(例如,检索知识库数据)
响应流:工具结果通过 MCP 客户端流回 OpenAI
最终响应:OpenAI 生成包含工具数据的最终响应
使用 Docker 运行
步骤 1:构建 Docker 镜像
步骤 2:运行 Docker 容器
这将在 Docker 容器内启动 MCP 服务器并将其公开在端口 8050 上。
运行客户端
一旦服务器运行,您就可以在单独的终端中运行客户端:
客户端将连接到服务器,列出可用的工具,并呼叫代理来回答查询。
故障排除
如果遇到连接问题:
检查服务器是否正在运行:使用
docker ps
确保 Docker 容器正在运行。验证端口映射:使用
docker ps
或检查docker run
命令的输出确保端口正确映射。检查服务器日志:使用
docker logs <container_id>
查看服务器日志,看看是否有任何错误。主机绑定:服务器已配置为绑定到
0.0.0.0
而不是127.0.0.1
,以便从容器外部访问。如果仍然遇到问题,您可能需要检查防火墙设置。网络问题:如果您在远程计算机上运行 Docker,请确保可以从客户端计算机访问该端口。
笔记
该服务器配置为使用 SSE(服务器发送事件)传输并监听端口 8050。
客户端通过
http://localhost:8050/sse
连接到服务器。启动客户端之前请确保服务器正在运行。
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
一个将模型控制协议与 OpenAI 的 API 相集成的项目,允许 OpenAI 访问和使用由 dockerized MCP 服务器公开的工具。
Related MCP Servers
- -securityAlicense-qualityA Model Context Protocol (MCP) server that lets you seamlessly use OpenAI's models right from Claude.Last updated -9068MIT License
- -securityAlicense-qualityA simple MCP server for interacting with OpenAI assistants. This server allows other tools (like Claude Desktop) to create and interact with OpenAI assistants through the Model Context Protocol.Last updated -936MIT License
- AsecurityAlicenseAqualityEnables integration with OpenAI models through the MCP protocol, supporting concise and detailed responses for use with Claude Desktop.Last updated -4MIT License
- -securityFlicense-qualityA Model Context Protocol server implementation that enables connection between OpenAI APIs and MCP clients for coding assistance with features like CLI interaction, web API integration, and tool-based architecture.Last updated -35