MCP-Server
README.md
# Multi-Server Model Context Protocol (MCP) Demo
A complete demonstration of building and integrating multiple [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers with a LangGraph ReAct agent powered by Groq and real-time OpenWeatherMap data.
This project showcases how an LLM agent can dynamically discover and consume tools across different MCP servers and transport protocols (**stdio** and **streamable-http**) in a single unified workflow.
---
## ๐๏ธ Architecture
```mermaid
flowchart LR
subgraph Agent["LangGraph ReAct Agent (client.py)"]
ChatGroq["LLM: Groq (Qwen / ChatGroq)"]
MultiMCP["MultiServerMCPClient"]
end
subgraph MathServer["Math MCP Server (mathserver.py)"]
MathTools["Tools: add, sub, mul, div"]
end
subgraph WeatherServer["Weather MCP Server (weatherserver.py)"]
WeatherTools["Tool: get_weather (OpenWeatherMap API)"]
end
MultiMCP -- "stdio transport (subprocess)" --> MathServer
MultiMCP -- "streamable-http (http://127.0.0.1:8000/mcp)" --> WeatherServer
```
### Components
1. **Math MCP Server ([`mathserver.py`](file:///c:/Users/SREESHANTH_K/Desktop/Mcp_demo/mathserver.py))**:
- Built with **FastMCP**.
- Runs over **`stdio`** transport.
- Exposes arithmetic tools: `add`, `sub`, `mul`, `div`.
- Automatically launched as a background subprocess by the MCP client.
2. **Weather MCP Server ([`weatherserver.py`](file:///c:/Users/SREESHANTH_K/Desktop/Mcp_demo/weatherserver.py))**:
- Built with **FastMCP** running over **`streamable-http`** transport at `http://127.0.0.1:8000/mcp`.
- Uses `httpx` to fetch live meteorological data from the **OpenWeatherMap API**.
- Exposes the `get_weather` tool (returns temperature, weather description, feels like, and humidity).
3. **Orchestrator Client ([`client.py`](file:///c:/Users/SREESHANTH_K/Desktop/Mcp_demo/client.py))**:
- Connects to both MCP servers simultaneously using `MultiServerMCPClient` from `langchain-mcp-adapters`.
- Assembles the tools and powers a LangGraph ReAct agent using Groq's fast LLM inference (`ChatGroq`).
---
## ๐ Project Structure
```text
Mcp_demo/
โโโ client.py # ReAct Agent & Multi-Server MCP client orchestrator
โโโ mathserver.py # FastMCP server running on stdio transport
โโโ weatherserver.py # FastMCP server with OpenWeatherMap API on HTTP transport
โโโ requirements.txt # Python package dependencies
โโโ pyproject.toml # Project configuration & metadata
โโโ .env.example # Environment variables template
โโโ .gitignore # Git ignore rules (protects .env and caches)
โโโ README.md # Project documentation
```
---
## ๐ Getting Started
### 1. Prerequisites
- Python 3.10+
- [Groq API Key](https://console.groq.com/)
- [OpenWeatherMap API Key](https://openweathermap.org/api) *(free tier)*
### 2. Installation
Clone the repository and install dependencies:
```bash
git clone https://github.com/sreeshanthkprakash-stack/MCP-Server.git
cd MCP-Server
# Create and activate virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Linux/macOS:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
```
### 3. Environment Configuration
Create a `.env` file in the root directory (or copy from [`.env.example`](file:///c:/Users/SREESHANTH_K/Desktop/Mcp_demo/.env.example)):
```bash
GROQ_API_KEY=your_groq_api_key_here
OPENWEATHER_API_KEY=your_openweather_api_key_here
```
---
## ๐งช Running the Application
### Step 1: Start the Weather MCP Server
Since the weather server communicates over HTTP, start it first in a terminal:
```bash
python weatherserver.py
```
> The weather server will start listening at `http://127.0.0.1:8000/mcp`.
### Step 2: Run the Agent Client
Open a second terminal window (ensure your virtual environment is active), and run:
```bash
python client.py
```
### Expected Output Example
```text
math_response The result of the expression ((15*20)+200)/4 is 125.
weather_response Weather in Hyderabad: haze, temperature 29.5ยฐC (feels like 32.1ยฐC), humidity 65%
```
---
## ๐ฆ Dependencies
- [`mcp`](https://pypi.org/project/mcp/): Official Model Context Protocol SDK (FastMCP)
- [`langchain-mcp-adapters`](https://pypi.org/project/langchain-mcp-adapters/): Connects LangChain to MCP servers
- [`langgraph`](https://pypi.org/project/langgraph/): Graph-based agent orchestration runtime
- [`langchain-groq`](https://pypi.org/project/langchain-groq/): High-speed LLM inference with Groq
- [`httpx`](https://pypi.org/project/httpx/): Async HTTP client for weather API requests
- [`python-dotenv`](https://pypi.org/project/python-dotenv/): Secure environment variable loading
---
## ๐ License
This project is open-source and available under the [MIT License](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues