Basics With Examples
No description available
Ask AI about Basics With Examples
Powered by Claude Β· Grounded in docs
I know everything about Basics With Examples. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP Demo
A demonstration of the Model Context Protocol (MCP) using LangChain and LangGraph. This project showcases how to create and connect to multiple MCP servers (Math and Weather) and use them with a ReAct agent powered by Groq.
Overview
This demo includes:
- Math Server: An MCP server that provides mathematical operations (add, subtract) using stdio transport
- Weather Server: An MCP server that provides weather information using streamable-http transport
- Client: A LangGraph ReAct agent that connects to both servers and can use their tools
Prerequisites
- Python 3.11 or higher
- Groq API key (get one from Groq)
Installation
- Clone or navigate to this directory:
cd MCP_Demo
- Install dependencies using pip:
pip install -r requirements.txt
Or if using uv:
uv sync
Setup
- Create a
.envfile in the project root:
GROQ_API_KEY=your_groq_api_key_here
- Make sure you have the required dependencies installed:
langchain-groqlangchain-mcp-adaptersmcplanggraphlangchainpython-dotenv
Running the Demo
Step 1: Start the Weather Server
In a separate terminal, start the weather server:
python weather.py
The weather server will run on http://localhost:8000/mcp using streamable-http transport.
Step 2: Run the Client
In another terminal, run the client:
python client.py
The client will:
- Connect to both the math server (via stdio) and weather server (via HTTP)
- Create a ReAct agent using Groq's Qwen model
- Execute two example queries:
- A math calculation: "What is (10 + 20) * 3?"
- A weather query: "What is the weather in Pune?"
Project Structure
MCP_Demo/
βββ client.py # Main client that connects to MCP servers and runs the agent
βββ mathserver.py # Math MCP server (stdio transport)
βββ weather.py # Weather MCP server (streamable-http transport)
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ .env # Environment variables (create this)
βββ README.md # This file
How It Works
-
MCP Servers: Both
mathserver.pyandweather.pyuse FastMCP to create MCP servers with different transport mechanisms:- Math server uses
stdiotransport (direct process communication) - Weather server uses
streamable-httptransport (HTTP-based)
- Math server uses
-
Client: The
client.pyusesMultiServerMCPClientfromlangchain-mcp-adaptersto:- Connect to multiple MCP servers simultaneously
- Expose their tools to a LangGraph ReAct agent
- Use Groq's Qwen model for reasoning and tool execution
-
Agent: The ReAct agent can autonomously:
- Understand user queries
- Decide which tools to use
- Execute tools from either server
- Provide natural language responses
Features
- Multi-server MCP integration
- Support for different transport mechanisms (stdio and HTTP)
- LangGraph ReAct agent for autonomous tool use
- Groq API integration for fast inference
- Example tools: Math operations and Weather queries
Troubleshooting
ModuleNotFoundError
If you encounter ModuleNotFoundError: No module named 'langchain', make sure you've installed all dependencies:
pip install -r requirements.txt
Weather Server Connection Issues
Make sure the weather server is running before starting the client. The client expects it at http://localhost:8000/mcp.
API Key Issues
Ensure your .env file contains a valid GROQ_API_KEY. You can get one from Groq Console.
License
This is a demo project for educational purposes.
