Skip to main content
Glama
Mathematical Calculator MCP Server

Mathematical Calculator MCP Server

by Chetto983

Mathematical Calculator MCP Server

This is a Model Context Protocol (MCP) server that provides advanced mathematical calculation capabilities, including symbolic math, statistical analysis, matrix operations, vector operations, and headless function plotting.

Features

The Mathematical Calculator MCP Server provides the following tools:

  • Basic Calculations: Evaluate mathematical expressions safely

  • Symbolic Mathematics:

    • Solve equations (linear, quadratic, polynomial, etc.)

    • Calculate derivatives of expressions

    • Compute integrals of expressions

  • Statistical Analysis:

    • Mean, median, mode

    • Variance, standard deviation

    • Correlation coefficient

    • Linear regression

    • Confidence intervals

  • Matrix Operations:

    • Matrix addition

    • Matrix multiplication

    • Matrix transposition

    • Matrix determinant

  • Vector Operations:

    • Dot product

    • Cross product

    • Magnitude

  • Plotting:

    • Headless function plot generation with a PNG render check

Related MCP server: Math MCP Server

Installation

Prerequisites

  • Python 3.11+

  • uv (recommended) or pip

  • Any MCP host that supports stdio servers

Installation Steps

  1. Clone the repository:

    git clone https://github.com/chetto1983/calculator-mcp-server.git
    cd calculator-mcp-server
  2. (Option 1) Setup with the provided script:

    chmod +x setup_venv.sh
    ./setup_venv.sh

    (Option 2) Or manually set up the virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    pip install -e ".[dev]"
  3. Run doc-tests to verify everything works:

    bash run_doctests.sh

Integration with Claude Desktop

Method 1: Configure in Claude Desktop

Add the server to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json

Add the following to the mcpServers section:

{
  "mcpServers": {
    "calculator": {
      "command": "uvx",
      "args": [
        "--from",
        "calculator-mcp-server@git+https://github.com/chetto1983/calculator-mcp-server.git",
        "--",
        "calculator-mcp-server",
        "--stdio"
      ]
    }
  }
}

Note: The server defaults to stdio. The --stdio flag is accepted for explicit host configuration, and --sse is available for local SSE experiments. The -- separates uvx arguments from the calculator server arguments.

Method 2: Install with the MCP CLI

  1. Make sure you have uv installed (Installation Guide)

  2. Install the MCP server in Claude Desktop:

    mcp install calculator_server.py

    Or with a custom name:

    mcp install calculator_server.py --name "Math Calculator"
  3. Once installed, Claude will automatically have access to all the mathematical tools and functions.

Usage Examples

After integrating with Claude Desktop, you can ask Claude to perform various mathematical operations. Here are some examples:

Basic Calculations

Can you calculate 3.5^2 * sin(pi/4)?

Solving Equations

Solve the following equation: x^2 - 5x + 6 = 0

Calculating Derivatives

What's the derivative of sin(x^2) with respect to x?

Computing Integrals

Calculate the integral of x^2 * e^x

Statistical Analysis

Find the mean, median, mode, and standard deviation of this dataset: [23, 45, 12, 67, 34, 23, 18, 95, 41, 23]

Linear Regression

Perform a linear regression on these points: (1,2), (2,3.5), (3,5.1), (4,6.5), (5,8.2)

Matrix Operations

Multiply these two matrices:
[1, 2, 3]
[4, 5, 6]

and

[7, 8]
[9, 10]
[11, 12]

Vector Operations

Compute the dot product of [1, 2, 3] and [4, 5, 6].

Function Plotting

Plot y = x^2 from -2 to 2.

Development

Testing

Run the comprehensive doctest suite:

bash run_doctests.sh

Run the pytest suite:

python -m pytest

Run linting:

ruff check .

Interactive Development Mode

For development and debugging, you can use the MCP development mode:

mcp dev calculator_server.py

This will start a local web interface where you can test all tools interactively.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Available Tools

23 tools
calculateA

Evaluates a mathematical expression and returns the result.

Supports basic operators (+, -, *, /, **, %, ^), mathematical functions (sin, cos, tan, exp, log, log10, sqrt), and constants (pi, e). Uses an AST whitelist for safe execution.

Args: expression: The mathematical expression to evaluate as a string. Examples: "2 + 2", "sin(pi/4)", "sqrt(16) * 2", "log(100, 10)"

Returns: On success: {"result": } On error: {"error": }

Examples: >>> calculate("2 * 3 + 4") {'result': 10} >>> calculate("sin(pi/2)") {'result': 1.0} >>> calculate("sqrt(16)") {'result': 4.0} >>> calculate("(2 + 3)^2") {'result': 25}

Notes: - Use 'x' as the variable (e.g., x2, not x^2) - Multiplication must be explicitly indicated with * (e.g., 2*x, not 2x) - Powers can be represented with ** or ^ (e.g., x2 or x^2)

Inputs: expression (required).

confidence_intervalB

Computes the confidence interval for the mean of a dataset.

Args: data: A list of numerical values. confidence: The confidence level (default is 0.95).

Returns: On success: {"confidence_interval": <(lower_bound, upper_bound)>} On error: {"error": }

Examples: >>> import numpy as np >>> np.random.seed(42) # For reproducible results >>> confidence_interval([1, 2, 3, 4]) # doctest: +ELLIPSIS {'confidence_interval': (0.445739743239..., 4.554260256760...)}

Inputs: data (required), confidence.

correlation_coefficientB

Computes the Pearson correlation coefficient between two lists of numbers.

Args: data_x: The first list of numerical values. data_y: The second list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> correlation_coefficient([1, 2, 3], [4, 5, 6]) {'result': 1.0}

Inputs: data_x (required), data_y (required).

differentiateA

Computes the derivative of a mathematical expression with respect to a variable.

Supports polynomials, trigonometric functions, exponential functions, logarithms, and other functions supported by SymPy.

Args: expression: The mathematical expression to differentiate as a string. Examples: "x**2", "sin(x)", "exp(x)", "log(x)" variable: The variable with respect to which to differentiate. Default is "x". Optionally, other variables can be specified.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> differentiate("x**2") {'result': '2x'} >>> differentiate("sin(x)") {'result': 'cos(x)'} >>> differentiate("xy", "y") {'result': 'x'} >>> differentiate("exp(x)") {'result': 'exp(x)'}

Notes: - Use mathematical notation with explicit operators (* for multiplication) - Powers can be represented with ** or ^ (e.g., x**2 or x^2) - For trigonometric functions, use sin(x), cos(x), etc. - Only support for one variable at a time (implicit differentiation not supported)

Inputs: expression (required), variable.

expandB

Expands an expression.

Args: expression: The expression to expand as a string.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> expand("(x + 1)2") {'result': 'x2 + 2*x + 1'}

Inputs: expression (required).

factorizeA

Factorizes an expression.

Args: expression: The expression to factorize as a string.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> factorize("x**2 + 2*x + 1") {'result': '(x + 1)**2'}

Inputs: expression (required).

integrateA

Computes the indefinite integral of a mathematical expression with respect to a variable.

Supports polynomials, trigonometric functions, exponential functions, logarithms, and other functions supported by SymPy.

Args: expression: The mathematical expression to integrate as a string. Examples: "x**2", "sin(x)", "exp(x)", "1/x" variable: The variable with respect to which to integrate. Default is "x". Optionally, other variables can be specified.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> integrate("x2") {'result': 'x3/3'} >>> integrate("sin(x)") {'result': '-cos(x)'} >>> integrate("exp(x)") {'result': 'exp(x)'} >>> integrate("1/x") {'result': 'log(x)'} >>> integrate("xy", "y") {'result': 'xy**2/2'}

Notes: - The result is the indefinite integral without the constant of integration - Complex expressions may be returned in simplified form

Inputs: expression (required), variable.

linear_regressionA

Performs linear regression on a set of points and returns the slope and intercept.

Args: data: A list of tuples, where each tuple contains (x, y) coordinates.

Returns: On success: {"slope": , "intercept": } On error: {"error": }

Examples: >>> linear_regression([(1, 2), (2, 3), (3, 5)]) {'slope': 1.5, 'intercept': 0.3333333333333335}

Inputs: data (required).

matrix_additionA

Adds two matrices.

Args: matrix_a: The first matrix as a list of lists. matrix_b: The second matrix as a list of lists.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> matrix_addition([[1, 2], [3, 4]], [[5, 6], [7, 8]]) {'result': [[6, 8], [10, 12]]}

Inputs: matrix_a (required), matrix_b (required).

matrix_determinantA

Computes the determinant of a square matrix.

Args: matrix: A square matrix as a list of rows.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> matrix_determinant([[1, 2], [3, 4]]) {'result': -2.0}

Inputs: matrix (required).

matrix_multiplicationA

Multiplies two matrices.

Args: matrix_a: The first matrix as a list of lists. matrix_b: The second matrix as a list of lists.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> matrix_multiplication([[1, 2], [3, 4]], [[5, 6], [7, 8]]) {'result': [[19, 22], [43, 50]]}

Inputs: matrix_a (required), matrix_b (required).

matrix_transposeA

Transposes a matrix.

Args: matrix: The matrix to transpose as a list of lists.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> matrix_transpose([[1, 2], [3, 4]]) {'result': [[1, 3], [2, 4]]}

Inputs: matrix (required).

meanB

Computes the mean of a list of numbers.

Args: data: A list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> mean([1, 2, 3, 4]) {'result': 2.5} >>> mean([10, 20, 30]) {'result': 20.0}

Inputs: data (required).

medianB

Computes the median of a list of numbers.

Args: data: A list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> median([1, 2, 3, 4]) {'result': 2.5}

Inputs: data (required).

modeA

Computes the mode of a list of numbers.

Args: data: A list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> mode([1, 2, 2, 3]) {'result': 2.0} >>> mode([1, 1, 2, 2]) {'result': 1.0} >>> mode([]) {'error': 'Cannot compute mode of empty array'}

Inputs: data (required).

plot_functionA

Plots a graph of y = f(x).

Args: expression: The function expression as a string. start: The first x value to plot. end: The final x value to plot. step: The number of x samples to render.

Returns: On success: {"result": "Plot generated successfully.", "format": "png", ...} On error: {"error": }

Notes: - Use 'x' as the variable (e.g., x2, not x^2) - Multiplication must be explicitly indicated with * (e.g., 2*x, not 2x) - Powers can be represented with ** or ^ (e.g., x2 or x^2)

Inputs: expression (required), end, step, start.

solve_equationA

Solves an algebraic equation for x and returns all solutions.

The equation must contain exactly one equality sign (=) and use a variable x. Can solve polynomial, trigonometric, and other equations supported by SymPy.

Args: equation: The equation to solve as a string. Format: ' = ' Examples: "x**2 - 5x + 6 = 0", "sin(x) = 0.5", "2x + 3 = 7"

Returns: On success: {"solutions": } On error: {"error": }

Examples: >>> solve_equation("x**2 - 5x + 6 = 0") {'solutions': '[2, 3]'} >>> solve_equation("2x + 3 = 7") {'solutions': '[2]'} >>> solve_equation("x = 0") {'solutions': '[0]'}

Notes: - Use 'x' as the variable (e.g., x2, not x^2) - Multiplication must be explicitly indicated with * (e.g., 2*x, not 2x) - Powers can be represented with ** or ^ (e.g., x2 or x^2)

Inputs: equation (required).

standard_deviationA

Computes the standard deviation of a list of numbers.

Args: data: A list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> standard_deviation([1, 2, 3, 4]) {'result': 1.118033988749895}

Inputs: data (required).

summationA

Calculates the summation of a function from start to end.

Args: expression: The expression of function x as a string. start: The starting value of the summation. end: The ending value of the summation.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> summation("x**2", 0, 10) {'result': 385}

Inputs: expression (required), end, start.

varianceB

Computes the variance of a list of numbers.

Args: data: A list of numerical values.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> variance([1, 2, 3, 4]) {'result': 1.25}

Inputs: data (required).

vector_cross_productB

Computes the cross product of two 2D or 3D vectors.

Args: vector_a: The first vector as a list of numbers. vector_b: The second vector as a list of numbers.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> vector_cross_product([1, 2, 3], [4, 5, 6]) {'result': [-3, 6, -3]}

Inputs: vector_a (required), vector_b (required).

vector_dot_productA

Computes the dot product of two equal-length vectors.

Args: vector_a: The first vector as a list of numbers. vector_b: The second vector as a list of numbers.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> vector_dot_product([1, 2], [7, 8]) {'result': 23}

Inputs: vector_a (required), vector_b (required).

vector_magnitudeA

Computes the magnitude of a vector.

Args: vector: A vector as a list of numbers.

Returns: On success: {"result": } On error: {"error": }

Examples: >>> vector_magnitude([1, 2, 3]) {'result': 3.7416573867739413}

Inputs: vector (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 23 tools

    Disambiguation4/5

    Each tool targets a distinct mathematical operation (e.g., mean/median/mode, differentiate/integrate, matrix vs vector ops) and names make the difference clear. A few tools all consume symbolic expressions (calculate, expand, factorize, summation, plot_function), which could occasionally cause hesitation, but their outputs and semantics are still distinguishable.

    Naming Consistency4/5

    All names use lowercase snake_case consistently, which is good. However the convention is not uniformly verb_noun: some are bare operation names (mode, median, calculate, expand) while others are category_operation (matrix_addition, vector_dot_product, correlation_coefficient), so the pattern varies although it stays readable.

    Tool Count3/5

    23 tools is on the heavy side for a calculator. Each tool covers a genuinely distinct operation and earns its place, but the surface is large enough that some grouping (e.g., a generic matrix tool) or sub-domain organization would improve usability.

    Completeness4/5

    Coverage is broad across statistics, calculus, symbolic algebra, matrices, vectors, and plotting, with no obvious dead ends for common workflows. Minor gaps exist such as matrix inverse/scalar ops, definite integrals, limits, and systems of equations, but these are workaround-able.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides comprehensive mathematical capabilities including basic arithmetic, advanced functions, statistical tools, and access to mathematical constants. It allows users to perform computations and generate math-related prompts through a standardized MCP interface.
      MIT
    • F
      license
      C
      quality
      D
      maintenance
      Exposes a broad mathematics toolkit including symbolic algebra, calculus, numerical methods, linear algebra, statistics, discrete math, graph theory, rendering, and optional GPU acceleration via MCP tools for use with Claude Desktop and other MCP hosts.
      51
      3
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides a comprehensive set of mathematical functions as MCP tools, enabling language models to perform calculations including arithmetic, trigonometry, logarithms, and more.
      10 npm
      1
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables advanced mathematics operations including linear algebra, vector math, symbolic computation, and calculus through MCP tools. Designed for use with Claude and other MCP-compatible LLMs.
      19
      2
      MIT