Skip to main content
Glama
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).