About calculator-mcp-server
calculator-mcp-server is an MCP server for mathematical calculations, suited to clients and agents that need numeric or symbolic results. It combines evaluation, simplification, and differentiation with typed errors and bounded execution.
Key features
- 01Evaluate arithmetic, statistics, matrices, units, and more
- 02Simplify algebraic and trigonometric expressions
- 03Compute symbolic derivatives
- 04Select number, BigNumber, or Fraction results
- 05Read syntax and function guidance from a resource
Use cases
- 01Check numeric results with chosen precision
- 02Simplify expressions before further processing
- 03Differentiate an expression by a named variable
MCP support
Exposes the `calculate` tool for evaluation, simplification, and derivatives, plus the `calculator://help` resource. Supports STDIO and Streamable HTTP transports.
Configuration
Remote servers need no local install. Pick your client, then copy the config or install in one click.
https://calculator.caseyjhand.com/mcpclaude mcp add --transport http cyanheads-calculator https://calculator.caseyjhand.com/mcp{"mcpServers":{"cyanheads-calculator":{"type":"http","url":"https://calculator.caseyjhand.com/mcp"}}}Open in Cursor{"servers":{"cyanheads-calculator":{"type":"http","url":"https://calculator.caseyjhand.com/mcp"}}}Open in VS Code{"mcpServers":{"cyanheads-calculator":{"type":"http","url":"https://calculator.caseyjhand.com/mcp"}}}{"mcpServers":{"cyanheads-calculator":{"serverUrl":"https://calculator.caseyjhand.com/mcp"}}}Run commands in a terminal; paste JSON into the client’s MCP config and restart. Servers that need sign-in will prompt on first connect.
Tools
1| Parameter | Type | Required | Description |
|---|---|---|---|
| scope | object | No | Variable assignments for evaluate; simplify and derivative ignore them. Example: { "x": 5, "y": 3 } makes "x + y" evaluate to 8. |
| variable | any | No | Variable to differentiate with respect to. Required when operation is "derivative". Empty string is treated as omitted. Example: "x". |
| operation | enum | No | Operation to perform. "evaluate" computes a numeric result (default). "simplify" reduces an algebraic expression symbolically (e.g., "2x + 3x" -> "5 * x"). Supports algebraic and trigonometric identities. When the simplifier cannot reduce the expression further (e.g. rational expressions requiring polynomial factoring), the result is returned unchanged and unchanged: true is set in the output. "derivative" computes the symbolic derivative (requires the variable parameter).evaluate | simplify | derivative |
| precision | any | No | Significant digits (1–16) for numeric results. Omit for full precision. Empty string is treated as omitted. Fraction results always print exactly, and symbolic operations (simplify, derivative) ignore it. |
| expression | string | Yes | One mathematical expression per call — neither `;` nor newlines separate statements. Inside matrices, `;` separates rows (e.g. `[1, 2; 3, 4]`). Supports arithmetic (+, -, *, /, ^, %), functions across arithmetic/trig (sin, cos, sqrt, log, abs, round), statistics (mean, median, std, variance — std and variance return the sample (n − 1) form by default; pass "uncorrected" for the population form, e.g. `std([2, 4, 6], "uncorrected")`), combinatorics (factorial, permutations, combinations), and matrix (det, inv, transpose), plus constants (pi, e, phi, i), units (5 kg to lbs), and variables (when scope is provided). Standard notation `ln` and `arc*` (e.g. `arcsin`, `arctan`) is accepted alongside the math.js names `log` and `asin`/`atan`; common synonyms such as `stdev`, `permute`, `nCr`, and `length`/`len` resolve to their math.js names (`std`, `permutations`, `combinations`, `count`). |
| numericType | enum | No | Numeric type for evaluate. "number" (default): 64-bit IEEE 754 float — fastest, about 16 significant digits; a value past about 1.8e308 (171!, 2^1024, exp(1000)) overflows and fails with undefined_result. "BigNumber": decimal with 64 significant digits and a much wider exponent range, slower than "number" — retry an overflow with it; results are 64-digit approximations (10000!/9999! returns 9999.99…96, which precision: 16 rounds to 10000). Division by zero, 0/0, and log(0) are undefined in every numeric type, so another numeric type does not fix them. "Fraction": exact rational arithmetic (0.1 + 0.2 returns 3/10); fails with fraction_unsupported when the result has no exact rational value (sqrt(2), sin(1), log(3)), the expression calls a function Fraction mode cannot compute (sqrt(4), 5!, combinations(5, 2)), or it uses a value Fraction mode holds only as a rounded float (pi, e, 2^(1/2), a complex number with a non-integer part, number(x), random()) — use "number" or "BigNumber" for those. A unit conversion with an irrational factor (30 deg to rad) returns a close rational approximation, not an exact value. Ignored for symbolic operations (simplify, derivative).number | BigNumber | Fraction |
Details
From the project README@cyanheads/calculator-mcp-server
Evaluate, simplify, and differentiate mathematical expressions via MCP. STDIO or Streamable HTTP.
Public Hosted Server: https://calculator.caseyjhand.com/mcp
Overview
Calculator powered by math.js. Verify numeric results, simplify algebraic expressions, and compute symbolic derivatives through one tool.
Tools
| Tool | Description |
|---|---|
calculate | Evaluate math expressions, simplify algebraic expressions, or compute symbolic derivatives. |
Resources
| Resource | Description |
|---|---|
calculator://help | Available functions, operators, constants, and syntax reference. |
Capability reference
calculate tool
- One
expressionper call.operationselectsevaluate(default),simplify, orderivative; derivatives requirevariable(e.g."x"). - Evaluate arithmetic, trigonometry, logarithms, statistics, matrices, complex numbers, units, and combinatorics; assign numeric variables through
scope, e.g.{ "x": 5 }. numericTypeselectsnumber,BigNumber(64 significant digits, for values that overflow a 64-bit float), orFraction(exact rationals). Fraction mode returnsfraction_unsupported, with guidance to change numeric type, when a result has no exact rational value (sqrt(2)), the expression calls a function Fraction mode cannot compute (sqrt(4),5!), or it uses a value Fraction mode holds only as a rounded float (pi,2^(1/2)).precisionsets 1–16 significant digits for numeric results. Blank optionalvariableandprecisionvalues are treated as omitted; scope and precision do not affect symbolic operations.- Simplification includes algebraic and trigonometric identities (
2x + 3x→5 * x);unchanged: trueidentifies expressions the simplifier cannot reduce, including polynomial factoring and rational cancellation cases. - Returns the result string, result type, original expression, and operation. Validation failures include typed reasons and recovery hints.
calculator://help resource
- Markdown reference for functions, operators, constants, units, and expression syntax; no parameters.
- Examples cover scope, matrices, complex numbers, precision, and all three operations.
- Cacheable for 24 hours with public scope (
cacheHint) — static content that never changes at runtime.
Features
Built on @cyanheads/mcp-ts-core: stdio and Streamable HTTP transports, pluggable auth (none / jwt / oauth), swappable storage (in-memory, filesystem, Supabase, Cloudflare KV/R2/D1), structured logging with optional OpenTelemetry tracing.
Calculator-specific:
- Hardened math.js v15 instance — dangerous functions disabled, evaluation run under a
vmtimeout - No auth required — all operations are read-only and stateless
- Input validation: expression length limits and rejection of multiple statements; matrix row separators and string contents remain valid
- Result validation: blocked result types (functions, parsers, result sets), configurable max result size
- Size limits: functions that build a matrix or string from a size, product, broadcast, index, or precision argument are capped per call, and each evaluation has a total element budget; oversized requests fail fast with
result_too_large - Scope sanitization: numeric-only values, prototype pollution prevention (blocked
__proto__,constructor, etc.)
Agent-friendly output:
- Effective-call echo — every response echoes the expression and operation, plus which scope variables and what precision were applied, so agents can verify what was actually computed
- Discriminated output contracts —
unchanged: trueonsimplifyflags a no-op result instead of silently returning the same expression - Typed error reasons — validation and evaluation failures carry a typed
reason(e.g.fraction_unsupported,evaluation_timeout,disallowed_result_type) plus an actionable recovery hint, rather than a raw exception
Getting started
Public Hosted Instance
A public instance is available at https://calculator.caseyjhand.com/mcp — no installation required. It serves Streamable HTTP; each client takes its own config shape.
For Claude Code:
claude mcp add --transport http calculator-mcp-server https://calculator.caseyjhand.com/mcp
For Cline (cline_mcp_settings.json):
{
"mcpServers": {
"calculator-mcp-server": {
"type": "streamableHttp",
"url": "https://calculator.caseyjhand.com/mcp"
}
}
}
For Cursor (mcp.json):
{
"mcpServers": {
"calculator-mcp-server": {
"url": "https://calculator.caseyjhand.com/mcp"
}
}
}
Claude Desktop adds remote servers under Settings → Connectors.
Self-Hosted / Local
Add one of the following to your MCP client configuration file:
{
"mcpServers": {
"calculator-mcp-server": {
"type": "stdio",
"command": "bunx",
"args": ["@cyanheads/calculator-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Or with npx (no Bun required):
{
"mcpServers": {
"calculator-mcp-server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@cyanheads/calculator-mcp-server@latest"],
"env": {
"MCP_TRANSPORT_TYPE": "stdio",
"MCP_LOG_LEVEL": "info"
}
}
}
}
Or with Docker:
{
"mcpServers": {
"calculator-mcp-server": {
"type": "stdio",
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_TRANSPORT_TYPE=stdio",
"ghcr.io/cyanheads/calculator-mcp-server:latest"
]
}
}
}
For Streamable HTTP, set the transport and start the built server:
MCP_HTTP_PORT=3010 bun run start:http
# Server listens at http://localhost:3010/mcp
Prerequisites
- Bun v1.4.0 or higher
Installation
- Clone the repository:
git clone https://github.com/cyanheads/calculator-mcp-server.git
- Navigate into the directory:
cd calculator-mcp-server
- Install dependencies:
bun install
Configuration
| Variable | Description | Default |
|---|---|---|
CALC_MAX_EXPRESSION_LENGTH | Maximum allowed expression string length (10–10,000). | 1000 |
CALC_EVALUATION_TIMEOUT_MS | Maximum evaluation time in milliseconds (100–30,000). | 5000 |
CALC_MAX_RESULT_LENGTH | Maximum result string length in characters (1,000–1,000,000). | 100000 |
MCP_TRANSPORT_TYPE | Transport: stdio or http. | stdio |
MCP_HTTP_HOST | Hostname for the HTTP server. | 127.0.0.1 |
MCP_HTTP_PORT | Port for HTTP server. | 3010 |
MCP_HTTP_ENDPOINT_PATH | Path for the HTTP MCP endpoint. | /mcp |
MCP_HTTP_MAX_BODY_BYTES | Maximum inbound HTTP request size; 0 disables the limit. | 1048576 |
MCP_AUTH_MODE | Auth mode: none, jwt, or oauth. | none |
MCP_SESSION_MODE | auto, stateful, or stateless. The server declares stateless in code, so every launch path resolves the same way; setting this overrides that declaration. | stateless |
MCP_LOG_LEVEL | Log level (RFC 5424). | info |
See .env.example for optional session, resumability, logging, and telemetry settings.
Running the server
Local development
-
Build and run the production version:
bun run build bun run start:http # or start:stdio -
Run checks and tests:
bun run devcheck # Lints, formats, type-checks bun run test # Runs test suite
Docker
docker build -t calculator-mcp-server .
docker run -p 3010:3010 calculator-mcp-server
The image defaults to Streamable HTTP on port 3010, stateless sessions, and logs at /var/log/calculator-mcp-server. OpenTelemetry dependencies are installed by default; build with --build-arg OTEL_ENABLED=false to omit them.
Project structure
| Directory | Purpose |
|---|---|
src/mcp-server/tools/ | Tool definitions (*.tool.ts). |
src/mcp-server/resources/ | Resource definitions (*.resource.ts). |
src/services/ | Domain service integrations (MathService). |
src/config/ | Environment variable parsing and validation with Zod. |
docs/ | Generated directory tree. |
tests/ | Calculation, configuration, and response-contract tests. |
Development guide
See AGENTS.md or CLAUDE.md for development guidelines and architectural rules. The short version:
- Handlers throw, framework catches — no
try/catchin tool logic - Use
ctx.logfor logging - Register new tools and resources in
src/index.ts
Contributing
Issues are welcome. Run checks before submitting:
bun run devcheck
bun run test
License
Apache-2.0 — see LICENSE for details.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.