home / mcp / mcp calculator server
Provides arithmetic tools (add, subtract, multiply, divide) via MCP for interactive and programmatic use.
Configuration
View docs{
"mcpServers": {
"ayyappachinpandi-mcp-example-ayyappa": {
"url": "http://127.0.0.1:8000",
"headers": {
"UV_PROJECT_ENVIRONMENT": ".venv"
}
}
}
}You can run a minimal MCP server that exposes calculator tools (add, subtract, multiply, divide) and connect MCP clients to perform arithmetic operations. This server is designed as a practical, self-contained example you can run locally, test with an inspector, and extend for your own MCP projects.
You will connect MCP clients to the server using two common transport methods. The standard input/output (stdio) transport runs locally in the same process, making it ideal for quick testing and integration with MCP Inspector. The HTTP transport exposes the server over a network port so clients can connect remotely.
Prerequisites you need before starting are: Python 3.11 or newer, and the MCP command line tools.
1) Create and activate a virtual environment.
python -m venv .venv
.\.venv\Scripts\Activate.ps12) Install the MCP CLI within the virtual environment.
pip install "mcp[cli]"3) Run the server using stdio transport for local testing.
python calculator_server.py4) Run tests if you wish to verify functionality.
python -m pytestIf you prefer to expose the server over HTTP for remote clients, you can start the server with a streamable-http transport and specify a host and port.
python calculator_server.py --transport streamable-http --host 127.0.0.1 --port 8000You can bind to all interfaces to allow external access, but be aware of security implications and ensure you understand DNS rebinding protections.
python calculator_server.py --transport streamable-http --host 0.0.0.0 --port 8080Example host/port combinations to tailor the setup to your environment include binding to a specific IP or localhost with a different port.
To use the calculator with Claude Desktop, configure a MCP server entry that runs the calculator server in stdio mode inside a virtual environment.
{
"mcpServers": {
"calculator": {
"command": "uv",
"args": [
"--directory",
"<path-to-project>",
"run",
"python",
"calculator_server.py"
],
"env": {
"UV_PROJECT_ENVIRONMENT": ".venv"
}
}
}
}If you enable HTTP binding on all interfaces, understand that this exposes the server to external clients. Only use external binding when you trust connected clients and you have appropriate network security controls.
The stdio transport is suitable for local development and testing with MCP Inspector and Claude Desktop when running on the same machine.
Run the test suite to verify arithmetic behavior and error handling, such as division by zero, which is handled by the server.
Expand the server by adding more arithmetic tools or prompts to guide user workflows, and explore additional transport options (HTTP, SSE, stdio) for broader client compatibility.
Add two numbers together with parameters a and b and return the sum.
Subtract b from a and return the difference.
Multiply two numbers and return the product.
Divide a by b and return the quotient, with an error on division by zero.