An agentic application that implements the Model Context Protocol (MCP) using LangChain and LangGraph to coordinate multiple local and remote tool servers. By leveraging ChatGroq (Llama 3.3), the system dynamically routes queries to resolve mathematical operations and fetch live weather data via hybrid transport protocols.
This orchestrator binds independent FastMCP tool servers (running via stdio and HTTP transports) into a single, unified agentic workspace using the LangChain MCP Adapters.
View Runtime Architecture & Flow Diagram
graph TD
classDef client fill:#1C3C3C,stroke:#333,stroke-width:1px,color:#fff;
classDef server fill:#3776AB,stroke:#333,stroke-width:1px,color:#fff;
classDef agent fill:#F55036,stroke:#333,stroke-width:1px,color:#fff;
classDef tool fill:#f4f4f4,stroke:#333,stroke-width:1px,color:#333;
User([User Request]) --> Agent[LangGraph ReAct Agent]:::agent
Agent --> Client[MultiServerMCPClient]:::client
Client -->|stdio| MathServer[Math Server]:::server
Client -->|HTTP| WeatherServer[Weather Server]:::server
subgraph Tools
MathServer --> add[add]:::tool
MathServer --> mutiple[multiple]:::tool
WeatherServer --> get_wether[get_weather]:::tool
end
- Multi-Server Coordination — Integrates multiple MCP tool servers concurrently under a single client adapter.
- Dynamic Tool Calling — A LangGraph ReAct agent discovers, plans, and invokes the most appropriate tool depending on the user's natural language input.
- Hybrid Transport Modes — Connects to local sub-processes via standard input/output (stdio) and remote/decoupled web servers via HTTP (streamable_http).
- FastMCP Protocol Integration — Servers are built with FastMCP, enabling declarative, type-safe Python decorator tools with automatically generated schemas.
- Live Third-Party API Integration — Retrieves geocoding details and weather forecasts dynamically from the Open-Meteo API.
.
├── client.py # Main client — configures adapter, builds LangGraph agent, runs queries
├── mathserver.py # Math tool server (stdio transport: add, multiply tools)
├── weather.py # Weather tool server (HTTP transport: geocoding & forecast tools)
├── pyproject.toml # Python dependency definitions & project configuration (uv format)
├── requirements.txt # Pip dependency definitions
├── .env # Environment secrets (GROQ_API_KEY)
└── .gitignore # Version control exclusions
- Python 3.13+
- A Groq API Key (get one from console.groq.com)
# Clone the repository
git clone https://github.com/your-username/mcp-langchain.git
cd mcp-langchain
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies using uv (recommended)
uv pip install -r requirements.txt
# Or using pip:
pip install -r requirements.txtCreate a .env file in the root of the project to configure your credentials:
GROQ_API_KEY=your_groq_api_key_hereSince the Weather Server communicates over HTTP (streamable_http), you must run it in a separate process before launching the main client:
-
Start the Weather Server:
python weather.py
This will start the server listening at
http://127.0.0.1:8000/mcp. -
Run the Agent Client: In another terminal (with the virtual environment activated):
python client.py
The client automatically spawns the Math Server via a child process (stdio transport) and connects to the running Weather Server over HTTP, queries the agent, and prints outputs for both math and weather operations.
View Detailed Pipeline Steps
MultiServerMCPClient initialized in client.py aggregates all tools declared in mathserver.py (via subprocess) and weather.py (via HTTP).
LangGraph wraps the LangChain tools and ChatGroq model in a state-based loop:
- Model Step: LLM decides if it needs a tool or can respond directly.
- Tool Execution: If a tool is called, the execution is dispatched to the corresponding MCP server.
- Observation Step: The tool results are fed back to the model state to form a final answer.
The system is designed to be highly modular and extensible. You can adapt it to any set of services:
| Component | Target File | Modification Details |
|---|---|---|
| Add New Math Tools | mathserver.py | Define new decorated functions with the @mcp.tool() decorator |
| New Integrations | client.py | Register additional server endpoints inside the MultiServerMCPClient initialization map |
| Different Model | client.py | Replace the model parameter in ChatGroq(...) with other models |
- Model Context Protocol (MCP) for standardizing application-tool interaction
- LangChain and LangGraph for the execution state-machine frameworks
- Open-Meteo for their free geocoding and meteorological APIs