A tutorial project demonstrating how to integrate MCP (Model Context Protocol) servers with LangChain and LangGraph.
This project connects multiple MCP servers and uses LangChain's ReAct agent to automatically select and use the appropriate tools based on user questions.
- Math Server: Mathematical operation tools (addition, multiplication)
- Weather Server: Weather information lookup tool
- Multi-Server Client: Connect and manage multiple MCP servers simultaneously
- ReAct Agent: Automatically select appropriate tools based on questions
-
Python 3.11 or higher is required.
-
Install dependencies:
uv syncOr if using pip:
pip install -r requirements.txt- Create a
.envfile and set your OpenAI API key:
OPENAI_API_KEY=your_api_key_here
- Check the paths in
main.py. Make sure the absolute path tomath_server.pyis correct.
Run the weather server as a separate process in a terminal:
uv run python servers/weather_server.pyOr:
python servers/weather_server.pyThis server will run on http://localhost:8000/sse.
In another terminal:
uv run python main.pyOr:
python main.py- Weather question:
"what is the weather in nyc?" - Math question:
"what is 5 + 3?"or"what is 10 * 7?"
You can modify the question in the last line of the main.py file.
mcp-crash-course/
├── main.py # Main execution file
├── langchain_client.py # LangChain client setup (similar to main.py)
├── servers/
│ ├── math_server.py # Math MCP server (stdio transport)
│ └── weather_server.py # Weather MCP server (sse transport)
├── pyproject.toml # Project dependencies
└── README.md # This file
- The Math server uses stdio transport (process communication)
- The Weather server uses SSE (Server-Sent Events) transport (HTTP-based)
- The ReAct agent analyzes questions and automatically selects appropriate tools