CA

Calculator MCP Server for Precise Numerical LLM Calculations

Enable LLMs to perform precise numerical calculations using an MCP server for fast, reliable, high-accuracy results.

Quick Install
npx -y @githejie/mcp-server-calculator

Overview

The Calculator MCP Server provides a lightweight Model Context Protocol (MCP) service that offloads numerical work from language models to a deterministic, high-precision calculation backend. Instead of asking an LLM to perform arithmetic, unit conversion, or other numeric evaluation (which can produce hallucinated or imprecise answers), an LLM can call this MCP server to get reliable, auditable numeric results and then incorporate them into natural-language output.

This server implements a small set of calculator tools exposed over HTTP in an MCP-compatible way. It supports arbitrary-precision arithmetic, configurable precision and rounding, and a concise tool-discovery endpoint so LLM orchestrators can discover available operations. The result is faster, more accurate numeric computation integrated directly into LLM workflows.

Features

  • Exposes calculator tools using the Model Context Protocol (MCP) discovery/call pattern
  • Arbitrary/high-precision arithmetic (BigInt/BigDecimal style) with configurable precision
  • Expression evaluation for arithmetic, functions (exp, log, trig), and unit conversions
  • Deterministic, reproducible outputs suitable for audit trails and chaining in LLM prompts
  • Simple HTTP API and Docker image for deployment in local or cloud environments
  • Lightweight and fast — designed as a tool service for LLM tool-calling patterns

Installation / Configuration

Clone the repository and run with Node or Docker. Example steps:

Clone the repo:

git clone https://github.com/githejie/mcp-server-calculator.git
cd mcp-server-calculator

Run with Docker:

# Build image
docker build -t mcp-calculator .

# Run container, default port 3000
docker run -p 3000:3000 --env MCP_CALC_PRECISION=50 mcp-calculator

Run locally with Node (if the project is Node-based):

# Install dependencies and start
npm install
npm start

Example environment variables (server reads these at startup):

# Number of significant digits / decimal places for calculations
MCP_CALC_PRECISION=50

# Maximum expression length accepted
MCP_MAX_EXPR_LENGTH=2000

# Bind address and port
MCP_HOST=0.0.0.0
MCP_PORT=3000

You can also provide a YAML/JSON config file if preferred:

precision: 50
maxExpressionLength: 2000
allowUnsafe: false

Available Tools

The server exposes one or more calculator tools via MCP discovery. Typical tools include:

Tool namePurpose
calculateEvaluate a numeric expression with configured precision
addAdd two or more numbers with arbitrary precision
multiplyMultiply arguments with arbitrary precision
convert_unitsConvert values between units (length, mass, time, etc.)
constantsReturn high-precision mathematical constants (pi, e)

Tool discovery endpoint example:

  • GET /mcp/tools — returns available tool names and JSON schemas describing inputs and outputs.

Tool call example (POST):

  • POST /mcp/tools/calculate/run — evaluate an expression and return a typed numeric result.

API Examples

Discover tools:

curl http://localhost:3000/mcp/tools

Evaluate an expression (curl):

curl -X POST http://localhost:3000/mcp/tools/calculate/run \
  -H "Content-Type: application/json" \
  -d '{"expression":"(3.14159265358979323846^2 + 1/3) / 7", "precision": 40}'

Example response:

{
  "result": "1.469801... (stringified high-precision number)",
  "precision": 40,
  "tool": "calculate"
}

JavaScript fetch example:

const res = await fetch('http://localhost:3000/mcp/tools/calculate/run', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ expression: 'sqrt(2) * pi', precision: 60 })
});
const json = await res.json();
console.log(json);

Python requests example:

import requests
r = requests.post("http://localhost:3000/mcp/tools/calculate/run",
                  json={"expression": "1/3", "precision": 80})
print(r.json())

Use Cases

  • Improving LLM numeric reliability: Offload arithmetic and unit conversions to the MCP calculator so generated text contains verified numeric answers.
  • Financial computations: Perform high-precision decimal arithmetic for pricing, tax calculations, or interest computations where floating-point errors are unacceptable.
  • Scientific workflows: Combine symbolic LLM explanations with accurate numeric results (constants, integrals approximated numerically, unit conversions).
  • Audit trails: Keep deterministic calculation outputs and parameter metadata alongside LLM-generated prose for reproducibility and debugging.
  • Tool chaining: Use the server as a deterministic tool in multi-step LLM chains (e.g., compute -> verify -> format).

Concrete example:

  • A user asks an LLM for the monthly payment on a loan. The LLM constructs a call to the calculator tool with the exact formula and parameters (principal, rate, term). The calculator returns a high-precision numeric payment, which the LLM then formats and explains in plain language.

Notes & Best Practices

  • Validate expressions on the client side before sending them to the server to avoid injection-style inputs (server config can limit allowed functions).
  • Configure precision according to your domain: default might be sufficient for casual use; increase for finance or scientific tasks.
  • Use the tool-discovery endpoint to dynamically generate tool schemas for LLM tool-calling integrations.
  • Deploy the service behind your application firewall or VPC when used with sensitive or private data.

Repository: https://github.com/githejie/mcp-server-calculator — check the repo for exact endpoint names, runtime requirements, and sample clients.

Tags:ai-ml