Rakshith1997-netizen/mcp_server_python
If you are the rightful owner of mcp_server_python and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server built with Python and FastMCP that provides utility tools for AI assistants and applications.
Demo MCP Server
A Model Context Protocol (MCP) server built with Python and FastMCP that provides utility tools for AI assistants and applications.
Overview
This MCP server exposes three useful tools that can be utilized by MCP-compatible clients:
- Add Numbers: Perform simple addition operations
- Get Secret Word: Retrieve a random secret word from a predefined list
- Get Current Weather: Fetch real-time weather data for any city
Features
- 🔧 Built with FastMCP for easy tool creation and server management
- 🌐 SSE (Server-Sent Events) transport protocol support
- 📝 Comprehensive logging for monitoring and debugging
- 🌤️ Real-time weather data integration using wttr.in API
- ⚙️ Configurable port via environment variables
Requirements
- Python 3.8+
mcppackagerequestspackage
Installation
-
Clone or download this repository
-
Install the required dependencies:
pip install mcp requests
Usage
Starting the Server
Run the server with default settings (port 8080):
python server.py
Or specify a custom port using an environment variable:
PORT=9000 python server.py
Available Tools
1. add(a: int, b: int) -> int
Adds two integers together.
Parameters:
a: First integerb: Second integer
Returns: Sum of the two numbers
2. get_secret_word() -> str
Returns a random word from a predefined list.
Returns: A random word (apple, banana, or cherry)
3. get_current_weather(city: str) -> str
Fetches current weather information for a specified city.
Parameters:
city: Name of the city to get weather for
Returns: Weather information in text format
Configuration
The server can be configured using the following environment variables:
PORT: The port number on which the server will run (default: 8080)
Architecture
The server uses:
- FastMCP: Simplifies the creation of MCP servers and tool definitions
- SSE Transport: Server-Sent Events for real-time communication
- wttr.in API: External service for weather data
Logging
The server implements comprehensive logging with the following levels:
- INFO: General operational messages
- ERROR: Error conditions and exceptions
Logs are output to the standard output stream (console).
Error Handling
- Weather API failures are gracefully handled with error messages
- Server exceptions are logged and result in proper cleanup
- Request timeouts are set to 10 seconds for the weather API
Example Integration
This MCP server can be integrated with MCP-compatible clients such as:
- Claude Desktop
- Custom AI assistants
- Automation tools that support the MCP protocol
Project Structure
mcp_server_python/
├── server.py # Main server implementation
└── README.md # This file
License
This project is open source and available for educational purposes.
Credits
This project was created as part of learning the Model Context Protocol (MCP) and server development.
Special thanks to FreeCodeCamp for providing excellent educational resources and tutorials that helped make this project possible.