A clean and simple Model Context Protocol (MCP) server built with FastMCP that provides four fundamental mathematical operations as tools.
This MCP server exposes the following tools:
- add - Add two numbers together
- subtract - Subtract the second number from the first
- multiply - Multiply two numbers together
- divide - Divide the first number by the second (with zero-division protection)
# Install dependencies
uv syncThe server can be run directly using:
uv run math-mcp-serverAdd this server to your MCP client configuration (e.g., ~/.kiro/settings/mcp.json):
{
"mcpServers": {
"math": {
"command": "uv",
"args": [
"--directory",
"d:\\MCP\\math-mcp-server",
"run",
"math-mcp-server"
]
}
}
}Once configured, you can use the tools through your MCP client:
Addition:
- Input:
a=5, b=3 - Output:
5 + 3 = 8
Subtraction:
- Input:
a=10, b=4 - Output:
10 - 4 = 6
Multiplication:
- Input:
a=7, b=6 - Output:
7 × 6 = 42
Division:
- Input:
a=15, b=3 - Output:
15 ÷ 3 = 5.0
The implementation is extremely simple and readable using FastMCP:
from fastmcp import FastMCP
mcp = FastMCP("Math Operations Server")
@mcp.tool()
def add(a: float, b: float) -> str:
"""Add two numbers together."""
result = a + b
return f"{a} + {b} = {result}"
# ... and so on for subtract, multiply, divideEach operation is a separate @mcp.tool() decorated function, making the code:
- Easy to read and understand
- Simple to extend with new operations
- Self-documenting with type hints and docstrings
math-mcp-server/
├── src/
│ └── math_mcp_server/
│ └── __init__.py # Main server implementation (4 simple functions!)
├── pyproject.toml # Project configuration
└── README.md # This file
- Python >= 3.14
- fastmcp >= 3.4.6
MIT