Aliaksei-Kharlap/MCP_server
If you are the rightful owner of MCP_server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a structured summary of a Model Context Protocol (MCP) server with integration into an AI agent within a console application.
MCP Server Project
Multi-Server MCP (Model Context Protocol) implementation providing weather information and temperature conversion services with LangChain/LangGraph integration.
Features
- Weather Service: Real-time weather data via OpenWeatherMap API with comprehensive meteorological information
- Temperature Converter: Temperature conversion between Celsius, Fahrenheit, and Kelvin units
- LangChain/LangGraph Integration: Advanced AI-powered chat client with intelligent tool usage
- Automated Startup: One-command deployment with automatic server management
- FastMCP Servers: MCP servers with HTTP transport
Project Structure
mcp_servers/
├── weather/
│ ├── server.py # Weather MCP server
│ └── tools/
│ └── weather_provider.py # Weather service implementation
├── temperature/
│ ├── server.py # Temperature MCP server
│ └── tools/
│ └── temperature_converter.py # Temperature conversion service
├── chat_client.py # MCP chat client with LangChain integration
├── start.sh # Automated startup script
├── pyproject.toml # Poetry configuration and dependencies
└── README.md # Project documentation
Installation
Prerequisites
- Python 3.11+
- Poetry (recommended) or pip
- OpenWeatherMap API key
- DeepSeek API key
Setup
- Clone the repository:
git clone <repository-url>
cd MCP_server
- Install dependencies:
# Using Poetry (recommended)
poetry install
- Configure environment variables:
Create a
.envfile with the following variables:
# OpenWeatherMap API
OPENWEATHER_API_KEY=your_openweather_api_key
# LLM Configuration (for LangChain client)
DEEPSEEK_API_KEY=your_deepseek_api_key
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
Usage
Quick Start (Recommended)
Use the provided startup script to run everything in one command:
chmod +x start.sh
./start.sh
This script will:
- Start the weather server on port 8000
- Start the temperature server on port 9000
- Wait for servers to initialize (2 seconds)
- Launch the chat client
- Automatically cleanup servers when chat ends
Manual Setup
If you prefer to start servers manually:
- Weather Server (Port 8000):
poetry run python mcp_servers/weather/server.py
- Temperature Server (Port 9000):
poetry run python mcp_servers/temperature/server.py
- Chat Client:
poetry run python chat_client.py
Weather Service
Endpoint: http://127.0.0.1:8000/mcp
Available Tool: get_weather
Parameters:
city(str): City name (e.g., "London", "New York")units(str, optional): Temperature units - "metric", "imperial", or "kelvin" (default: "metric")
Example Response:
{
"success": true,
"city": "London",
"country": "GB",
"temperature": {
"current": 15.2,
"feels_like": 14.1,
"min": 12.3,
"max": 17.8,
"unit": "°C"
},
"weather": {
"main": "Clouds",
"description": "overcast clouds",
"icon": "04d"
},
"wind": {
"speed": 3.5,
"direction_degrees": 220,
"direction_name": "SW",
"unit": "m/s"
},
"humidity": 73,
"pressure": {
"value": 1013,
"unit": "hPa"
},
"coordinates": {
"latitude": 51.5074,
"longitude": -0.1278
}
}
Temperature Conversion Service
Endpoint: http://127.0.0.1:9000/mcp
Available Tool: convert_temperature
Parameters:
temperature(float): Temperature value to convertfrom_unit(str): Source unit ("celsius", "fahrenheit", "c", "f", "k")to_unit(str): Target unit ("celsius", "fahrenheit", "c", "f", "k")
Example Response:
{
"success": true,
"original_temperature": 25.0,
"original_unit": "celsius",
"converted_temperature": 77.0,
"converted_unit": "fahrenheit",
"conversion_formula": "°F = (°C × 9/5) + 32"
}
Features in Detail
Weather Provider
- Multiple Units: Supports metric, imperial, and kelvin units
- Comprehensive Data: Temperature, humidity, pressure, wind, visibility
- Validation: Input validation
Temperature Converter
- Multiple Formats: Supports full names and abbreviations
- Validation: Temperature validation against absolute zero
- Precision: Proper rounding and precision handling
- Formulas: Returns conversion formulas for transparency
Chat Clients
- Basic Client: Simple MCP integration
- LangChain Client: Advanced AI-powered conversations
- Error Handling: Comprehensive error handling and recovery
- Session Management: Chat history tracking
Configuration
Server Ports
- Weather Service:
8000 - Temperature Service:
9000
Error Handling
The project implements comprehensive error handling:
- Validation Errors: Input validation with helpful error messages
- Logging: Structured logging for debugging and monitoring
Security Considerations
- API keys are loaded from environment variables