MCPSERVERLangchain
No description available
Ask AI about MCPSERVERLangchain
Powered by Claude Β· Grounded in docs
I know everything about MCPSERVERLangchain. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP Server Langchain Demo
A demonstration project showing how to integrate Model Context Protocol (MCP) servers with LangChain and LangGraph agents.
Overview
This project demonstrates how to create MCP servers for math and weather operations and integrate them with LangChain agents using the langchain-mcp-adapters library. The agents can perform calculations and get weather information through the MCP protocol.
Features
- Math Server: Provides addition and multiplication operations via MCP
- Weather Server: Provides weather information via MCP
- LangChain Integration: Uses LangGraph agents to interact with MCP servers
- Multiple Transports: Demonstrates both stdio and HTTP transports
Project Structure
MCPSERVERLangchain/
βββ client.py # Main client that uses LangChain agents with MCP tools
βββ mathserver.py # MCP server for math operations (stdio transport)
βββ weather.py # MCP server for weather operations (HTTP transport)
βββ main.py # Basic entry point
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ .env # Environment variables (API keys)
βββ README.md # This file
Setup
Prerequisites
- Python 3.13 or higher
- A Groq API key
Installation
-
Clone or download this repository
-
Navigate to the project directory:
cd MCPSERVERLangchain -
Install dependencies:
pip install -r requirements.txt -
Create a
.envfile with your API key:GROQ_API_KEY=your_groq_api_key_here
Usage
Running the Complete Demo
Run the main client that demonstrates both math and weather servers:
python client.py
This will:
- Start the math server as a subprocess
- Connect to a weather server (if running on localhost:8000)
- Ask the agent to solve a math problem: "what's (3 + 5) x 12?"
- Ask the agent for weather information: "what is the weather in California?"
Running Individual Servers
Math Server (stdio transport)
python mathserver.py
Weather Server (HTTP transport)
python weather.py
MCP Servers
Math Server (mathserver.py)
Provides mathematical operations via stdio transport:
- add(a: int, b: int): Adds two numbers
- multiple(a: int, b: int): Multiplies two numbers
Weather Server (weather.py)
Provides weather information via HTTP transport:
- get_weather(location: str): Returns weather for a location
Configuration
The client is configured to use:
- Groq LLM:
qwen-qwq-32bmodel - Math Server: stdio transport, subprocess execution
- Weather Server: HTTP transport on
localhost:8000
Dependencies
langchain-groq: Groq LLM integrationlangchain-mcp-adapters: MCP protocol adapters for LangChainlanggraph: Agent framework for LangChainmcp: Model Context Protocol implementationpython-dotenv: Environment variable management
Troubleshooting
Math Server Returns Blank Response
Common issues:
- Missing dependencies: Ensure all packages are installed
- Path issues: Make sure
mathserver.pyis in the current directory - Transport configuration: Verify stdio transport is properly configured
Weather Server Not Responding
- Make sure the weather server is running on
localhost:8000 - Check that the HTTP transport is properly configured
- Verify network connectivity
API Key Issues
- Ensure your
.envfile contains a validGROQ_API_KEY - Check that the API key has sufficient credits/permissions
Development
Adding New Tools
To add new mathematical operations to the math server:
@mcp.tool()
def subtract(a: int, b: int) -> int:
"""Subtract two numbers"""
return a - b
Modifying Transport
To change from stdio to HTTP transport in the math server:
if __name__ == "__main__":
mcp.run(transport="sse", port=8001)
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
If you encounter issues:
- Check the troubleshooting section above
- Verify all dependencies are properly installed
- Ensure API keys are correctly configured
- Check the MCP server logs for error messages
