Multi-Server MCP Project
A multi-server implementation that uses OpenAI's LLM to orchestrate multiple tool servers providing web search, weather lookup, random facts, and PostgreSQL database querying capabilities.
README
Multi-Server MCP Project with OpenAI LLM
Overview
This project demonstrates a multi-server setup using MCP (Multi-Channel Protocol) with multiple tool servers and a client that orchestrates them. The servers expose various tools such as web search, weather lookup, random facts, and PostgreSQL database querying. The client uses OpenAI's LLM to interact with these tools via an agent.
Features
- Multiple MCP servers each exposing different tools.
- Tools include:
- Web search (DuckDuckGo)
- Weather information (Open-Meteo API)
- Random fun facts
- PostgreSQL database querying
- Multi-server client that loads tools from all servers.
- Agent powered by OpenAI LLM (
ChatOpenAI) that uses tools to answer user queries. - Modular and clean code structure with explicit tool registration.
Repository Structure
. ├── mcp_server.py # Server 1: Search & Weather tools ├── mcp_server_2.py # Server 2: Random Fact & Postgres tools ├── src │ └── multi.py # Multi-server client using OpenAI LLM ├── tools │ ├── init.py │ ├── mcp_instance.py # MCP instance factory │ ├── search_tool.py │ ├── weather_tool.py │ ├── random_fact_tool.py │ └── postgres_tool.py └── README.md
Prerequisites
- Python 3.8+
- OpenAI API key set in environment variable
OPENAI_API_KEY - PostgreSQL database accessible at the configured host and credentials
- Required Python packages (see below)
Installation
- Clone the repository:
git clone <repository_url>
cd <repository_folder>
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # Linux/macOS
venv\Scripts\activate # Windows
- Install dependencies:
pip install -r requirements.txt
Example requirements.txt includes:
mcp-server langchain langchain-openai langgraph psycopg2-binary requests pydantic
Configuration
- Set your OpenAI API key:
export OPENAI_API_KEY="your_openai_api_key"
- Update PostgreSQL connection details in
tools/postgres_tool.pyif needed.
Running the Servers
Server 1: Search & Weather
python mcp_server.py
Server 2: Random Fact & Postgres
python mcp_server_2.py
Both servers will run and listen on stdio for MCP client connections.
Running the Multi-Server Client
python src/multi.py
- You will be prompted to enter a query.
- The client will load tools from both servers and use OpenAI LLM to answer your query using the tools.
Example Queries
- "Tell me a fun fact."
- "What’s the weather in New York?"
- "Search for the latest news about space exploration."
Code Highlights
- Explicit tool registration: Each tool defines a
register_<tool>_tool(mcp)function to register itself with the MCP server instance. - Separate MCP instances: Each server creates its own MCP instance for isolation.
- Multi-server client: Connects to multiple MCP servers, loads their tools, and combines them for the agent.
- OpenAI LLM: Uses
ChatOpenAIfromlangchain_openaifor language understanding and generation.
Troubleshooting
- If tools do not appear in the client, ensure servers are running and tools are properly registered.
- Check for import errors or exceptions in server logs.
- Verify OpenAI API key is set and valid.
- Confirm PostgreSQL database is reachable and credentials are correct.
Future Improvements
- Integrate local LLMs such as DeepSeek for offline inference.
- Add authentication and security to MCP servers.
- Expand toolset with more APIs and custom tools.
- Add UI frontend for better user experience.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。