mcp-calculator
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.

mcp-calculator
Precise Arithmetic for AI Agents
A Model Context Protocol (MCP) server that eliminates AI math errors by providing deterministic arithmetic operations using Decimal precision.
The Problem
LLMs confidently produce wrong arithmetic. This isn't ignorance—language models are text prediction engines, not calculators.
Real-world examples:
Context | AI Output | Correct Value | Error |
Financial report | "72% decline" | 26.3% decline | Confused ratio with % change |
Trend analysis | "trending higher" | trending lower | Incorrect comparison |
Observed error rate: 10-20% when AI does math vs. 0% with this tool.
Related MCP server: leftbrain
Quick Start
Running the Server
# Using Go
go run ./cmd/mcp-calculator
# Using Docker
docker run -p 8080:8080 mcp-calculator
# Using Make
make runMCP Client Configuration
Add to your MCP client configuration (e.g., Claude Desktop):
{
"mcpServers": {
"calculator": {
"url": "http://localhost:8080/mcp"
}
}
}Example Request
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"clientInfo": {"name": "curl", "version": "1.0"}
}
}'Supported Operations
Basic Arithmetic
add- Sum values:[100, 200]→ 300subtract- Difference:[500, 200]→ 300multiply- Product:[10, 5]→ 50divide- Division:[100, 4]→ 25
Statistical
sum- Total of array:[100, 200, 300]→ 600average- Mean:[100, 200, 300]→ 200min- Minimum:[100, 50, 200]→ 50max- Maximum:[100, 50, 200]→ 200median- Median valuestddev- Standard deviation
Financial
percentage- Percent change:[150, 100]→ 50.0 (50% increase)roi- Return on investment:[gain, cost]compound_interest- Future value:[principal, rate, periods]present_value- Present value:[future_value, rate, periods]
Utility
round- Round to decimals:[3.14159, 2]→ 3.14abs- Absolute valueceil- Round upfloor- Round down
Comparison
compare- Boolean comparison:[5, 10, "<"]→ True
Variable References
Calculations can reference previous results by name:
{
"calculations": [
{"name": "oct_rate", "operation": "divide", "args": [2400000, 8]},
{"name": "sep_rate", "operation": "divide", "args": [8400000, 21]},
{"name": "change", "operation": "percentage", "args": ["oct_rate", "sep_rate"]}
]
}Why Decimal Precision?
// Float (IEEE 754) - imprecise
0.1 + 0.2 = 0.30000000000000004
// mcp-calculator (Decimal) - exact
0.1 + 0.2 = 0.3For financial applications, floating-point errors are unacceptable.
Error Handling
Errors are returned per-calculation, not as exceptions:
{
"success": true,
"results": {
"valid": 6,
"error": {"error": "division by zero"}
}
}Configuration
The server is configured via environment variables:
Variable | Default | Description |
|
| Host to bind to |
|
| Port to listen on |
|
| Session timeout duration |
|
| Maximum concurrent sessions |
|
| Requests per minute |
|
| Burst size for rate limiting |
| (none) | API key for authentication |
Endpoints
Endpoint | Method | Description |
| POST | MCP JSON-RPC endpoint |
| DELETE | Delete session |
| GET | Health check |
| GET | Readiness probe |
| GET | Prometheus metrics |
Development
# Clone and build
git clone https://github.com/scottrfrancis/mcp-calculator
cd mcp-calculator
# Install dependencies
make deps
# Run tests
make test
# Run with race detection
go test -race ./...
# Build binary
make build
# Run locally
make runProject Structure
mcp-calculator/
├── cmd/mcp-calculator/ # Server entry point
├── internal/
│ ├── calculator/ # Decimal arithmetic engine
│ ├── server/ # MCP server implementation
│ ├── session/ # Session management
│ ├── auth/ # OAuth/API key authentication
│ └── middleware/ # Rate limiting, metrics
├── test/ # Test suites
├── spec/ # Protocol specifications
├── docs/ # Documentation
└── reference/ # Python reference implementationArchitecture
Protocol: MCP 2025-03-26 (Streamable HTTP)
Precision: Decimal arithmetic via
shopspring/decimalConcurrency: Goroutine-safe with RWMutex
Authentication: OAuth 2.1 or API key
Rate Limiting: Token bucket per session/IP
See DESIGN_AND_ARCHITECTURE.md for details.
Python Reference Implementation
A Python reference implementation is available in the reference/ directory for testing and development purposes.
cd reference
pip install -e ".[dev]"
python -m mcp_calculator --testLicense
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
High-precision finance & business calculations for AI agents — exact decimals, never floats.
Loan & mortgage calculator, compound interest, ROI, crypto prices, FX conversion for AI agents.
500+ deterministic tools for AI agents: math, conversion, validation, hashing, encoding, date/time.
Deterministic signed verification of numeric & financial claims for AI agents & spreadsheets.
Related MCP Servers
AlicenseNot gradedqualityCmaintenanceProvides over 500 deterministic tools for math, conversions, validation, hashing, and more, enabling AI agents to perform accurate calculations and data transformations without hallucination.1MIT- AlicenseNot gradedqualityBmaintenanceProvides exact, deterministic tools for math, dates, units, validation, and more to AI agents, returning precise answers with explicit assumptions and warnings instead of model guesses.MIT
- AlicenseBqualityBmaintenanceEnables AI agents to perform accurate local computations including arbitrary-precision math, date handling, unit conversion, subnet calculations, encoding, hashing, and text analysis, all without network calls or API keys.27MIT
- AlicenseAqualityBmaintenanceProvides LLMs with deterministic math tools for sandboxed expression evaluation, descriptive statistics, primality testing, prime factorization, GCD/LCM, quadratic solving, and base conversion. Every operation runs real code rather than relying on the model's arithmetic, with expression parsing restricted to a whitelist of operators, constants, and functions.21MIT