Labsco
cyanheads logo

calculator-mcp-server

โ˜… 1

from cyanheads

Math evaluation, simplification, derivatives

๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedFreeAdvanced setup

@cyanheads/calculator-mcp-server

Evaluate, simplify, and differentiate mathematical expressions via MCP. STDIO or Streamable HTTP.

1 Tool โ€ข 1 Resource

Install in Claude Desktop Install in Cursor Install in VS Code


Tools

One tool for all mathematical operations:

Tool NameDescription
calculateEvaluate math expressions, simplify algebraic expressions, or compute symbolic derivatives.

calculate

A single tool covering 100% of the server's purpose. The operation parameter defaults to evaluate, so the common case is just { expression: "..." }.

  • Evaluate โ€” arithmetic, trigonometry, logarithms, statistics, matrices, complex numbers, unit conversion, combinatorics
  • Simplify โ€” reduce algebraic expressions symbolically (e.g., 2x + 3x -> 5 * x). Supports algebraic and trigonometric identities
  • Derivative โ€” compute symbolic derivatives (e.g., 3x^2 + 2x + 1 -> 6 * x + 2)
  • Variable scope via scope parameter: { "x": 5, "y": 3 }
  • Configurable precision for numeric results
  • Blank optional variable and precision values from form-based MCP clients are treated as omitted

Resources

URI PatternDescription
calculator://helpAvailable functions, operators, constants, and syntax reference.

Features

Built on @cyanheads/mcp-ts-core:

  • Declarative tool definitions โ€” single file per tool, framework handles registration and validation
  • Unified error handling across all tools
  • Structured logging with optional OpenTelemetry tracing
  • Runs locally (stdio/HTTP) or in Docker

Calculator-specific:

  • Hardened math.js v15 instance โ€” dangerous functions disabled, evaluation sandboxed via vm.runInNewContext() with timeout
  • No auth required โ€” all operations are read-only and stateless
  • Input validation: expression length limits, expression separator rejection (semicolons and newlines), variable name regex enforcement
  • Result validation: blocked result types (functions, parsers, result sets), configurable max result size
  • Scope sanitization: numeric-only values, prototype pollution prevention (blocked __proto__, constructor, etc.)

Project Structure

DirectoryPurpose
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.

Development Guide

See AGENTS.md or CLAUDE.md for development guidelines and architectural rules. The short version:

  • Handlers throw, framework catches โ€” no try/catch in tool logic
  • Use ctx.log for logging
  • Register new tools and resources in src/index.ts