A Model Context Protocol (MCP) server built with Python and FastMCP that provides utility tools for AI assistants and applications.
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
- 🔧 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
- Python 3.8+
mcppackagerequestspackage
-
Clone or download this repository
-
Install the required dependencies:
pip install mcp requestsRun the server with default settings (port 8080):
python server.pyOr specify a custom port using an environment variable:
PORT=9000 python server.pyAdds two integers together.
Parameters:
a: First integerb: Second integer
Returns: Sum of the two numbers
Returns a random word from a predefined list.
Returns: A random word (apple, banana, or cherry)
Fetches current weather information for a specified city.
Parameters:
city: Name of the city to get weather for
Returns: Weather information in text format
The server can be configured using the following environment variables:
PORT: The port number on which the server will run (default: 8080)
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
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).
- 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
This MCP server can be integrated with MCP-compatible clients such as:
- Claude Desktop
- Custom AI assistants
- Automation tools that support the MCP protocol
mcp_server_python/
├── server.py # Main server implementation
└── README.md # This file
This project is open source and available for educational purposes.
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.