McpLangchain
No description available
Ask AI about McpLangchain
Powered by Claude Β· Grounded in docs
I know everything about McpLangchain. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP LangChain Integration Project
A Model Context Protocol (MCP) implementation with multiple servers and LangChain integration for AI agent interactions.
π Project Overview
This project demonstrates how to create MCP servers and integrate them with LangChain agents using the GROQ API. It includes:
- Weather Server: A simple weather service that returns weather information
- Math Server: A mathematical operations service with add and multiply functions
- Client: A LangChain agent that can interact with both servers
π Project Structure
MCPLangchain/
βββ weather.py # Weather MCP server
βββ mathserver.py # Math MCP server
βββ client.py # LangChain client with agent
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (API keys)
βββ README.md # This file
π οΈ Installation
- Clone and setup the environment:
cd MCPLangchain
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a
.envfile with your GROQ API key:
GROQ_API_KEY="your_groq_api_key_here"
πββοΈ Running the Project
1. Start the Weather Server
python weather.py
The weather server will start on port 8001 with streamable-http transport.
2. Start the Math Server (in a separate terminal)
python mathserver.py
The math server uses stdio transport for direct communication.
3. Run the Client
python client.py
This will:
- Connect to both MCP servers
- Create a LangChain agent with GROQ model
- Execute math and weather queries
π§ Configuration
Weather Server (weather.py)
- Transport: streamable-http
- Port: 8000
- Function:
get_weather(location)- Returns weather info for any location
Math Server (mathserver.py)
- Transport: stdio
- Functions:
add(a, b)- Adds two integersmultiply(a, b)- Multiplies two integers
Client (client.py)
- Model: GROQ Qwen-QWQ-32B
- Agent Type: React Agent
- Capabilities: Can invoke tools from both servers
π Dependencies
mcp- Model Context Protocol implementationlangchain-mcp-adapters- LangChain MCP integrationlangchain-groq- GROQ API integrationlanggraph- LangGraph for agent creationuvicorn- ASGI server for HTTP transportpython-dotenv- Environment variable management
π― Example Usage
The client demonstrates two main interactions:
- Math Operations: "What is 100 + 200?"
- Weather Queries: "What's the weather in Noida?"
Import Errors
Ensure all dependencies are installed:
pip install -r requirements.txt
API Key Issues
Verify your .env file contains the correct GROQ API key:
GROQ_API_KEY="gsk_your_actual_key_here"
π Next Steps
- Add more MCP servers (database, file system, etc.)
- Implement more complex agent workflows
- Add authentication and security features
- Create a web interface for the agent
π Resources
Note: This project demonstrates the power of MCP for creating modular, composable AI services that can be easily integrated with LangChain agents.
