Tools
A simple Model Context Protocol (MCP) server that provides datetime and calculator tools.
Installation
npx mcp-server-toolsAsk AI about Tools
Powered by Claude Β· Grounded in docs
I know everything about Tools. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
MCP Server Tools
A simple Model Context Protocol (MCP) server that provides datetime and calculator tools. Built with FastMCP for easy development and deployment.
ποΈ Architecture
The project follows a layered architecture pattern:
mcp_server_tools/
βββ main.py # Entry point (Presentation Layer)
βββ src/ # Implementation folder
β βββ tools/ # MCP interface layer
β β βββ datetime_tool.py # DateTime MCP tools
β β βββ calculator_tool.py # Calculator MCP tools
β βββ services/ # Business logic layer
β β βββ datetime_service.py # DateTime business logic
β β βββ calculator_service.py # Calculator business logic
β βββ server_manager.py # Server execution management
β βββ logger_config.py # Centralized logging
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.yml # Development and production services
βββ pyproject.toml # Project configuration
βββ .env # Environment variables (create from env.example)
Layer Responsibilities:
- Presentation Layer (
main.py): MCP server setup and tool registration - Tools Layer (
src/tools/): MCP interface functions that handle protocol communication - Services Layer (
src/services/): Pure business logic, independent of MCP - Server Management (
src/server_manager.py): Development and production server execution
π Quick Start
Prerequisites
- Python 3.12+
- uv package manager
- Docker and Docker Compose (for containerized deployment)
Local Development
-
Clone and setup:
git clone <repository-url> cd mcp_server_tools cp env.example .env uv sync --dev -
Development mode (stdio):
uv run mcp dev main.pyThis starts the MCP Inspector for visual testing.
-
Production mode (SSE):
uv run python main.pyThis starts the server with SSE transport on
0.0.0.0:8050.
Docker Deployment
-
Development:
docker-compose --profile dev up -
Production:
docker-compose --profile prod up
π οΈ Available Tools
DateTime Tools
-
datetime_tool(format: str = "iso"): Get current datetimeformat="iso": ISO 8601 format (e.g., "2025-01-08T22:30:00.123456")format="formatted": Human-readable format (e.g., "2025-01-08 22:30:00")
-
timestamp_tool(): Get current timestamp as string
Calculator Tools
-
calculator_tool(expression: str): Evaluate mathematical expressions- Examples:
"2 + 3","10 * 5","100 / 4","2 ** 8"
- Examples:
-
operation_tool(a: float, b: float, operation: str): Perform operations on two numbers- Operations:
+,-,*,/,**,%
- Operations:
-
operations_list_tool(): List all supported mathematical operations
βοΈ Configuration
Environment variables (configure in .env file):
HOST=0.0.0.0 # Server host
PORT=8050 # Server port
DEV_MODE=false # Development mode
LOG_LEVEL=INFO # Logging level
SERVER_NAME=mcp-server-tools # Server name
π§ Development
Code Quality
# Format code
uv run ruff format .
# Lint code
uv run ruff check .
# Run tests
uv run pytest
Project Structure Benefits
- Separation of Concerns: Each layer has a specific responsibility
- Testability: Business logic is isolated and easily testable
- Maintainability: Clear organization makes code easier to understand
- Reusability: Services can be used outside of MCP context
- Scalability: Easy to add new tools and services
Adding New Tools
- Create service in
src/services/(business logic) - Create tool in
src/tools/(MCP interface) - Register tool in
main.pywith@mcp.tool()decorator
π³ Docker
Multi-stage Build
- Builder stage: Installs dependencies
- Production stage: Optimized for production
- Development stage: Includes development tools
Docker Compose Services
mcp-server-dev: Development with volume mountsmcp-server-prod: Production with optimized image
π Logging
Structured logging with configurable levels:
- INFO: Application startup, tool execution
- DEBUG: Detailed operation information
- ERROR: Error conditions and exceptions
Logs are formatted and output to stdout for Docker compatibility.
π Security
- Safe expression evaluation with restricted globals
- Input validation for all tools
- Non-root user in Docker containers
- Environment variable configuration
