math-mcp
A small Model Context Protocol (MCP) server that gives an LLM a set of reliable math tools — expression evaluation, statistics, number theory, linear algebra, and symbolic math — instead of asking it to do arithmetic in its head.
Every tool runs real, deterministic code. The expression evaluator is
sandboxed: it parses input into an AST and only allows a whitelist of
operators, constants, and functions. It never calls Python's eval. Symbolic
tools parse input with SymPy's tokenizing parser (also no eval).
Tools
Numeric & number theory
| Tool | Description |
|---|---|
evaluate |
Evaluate an expression like sqrt(2) * sin(pi / 4). Supports + - * / // % **, parentheses, constants (pi, e, tau) and functions (sqrt, sin, log, factorial, gcd, hypot, …). |
descriptive_statistics |
Count, sum, min, max, mean, median, variance and standard deviation (population and sample) of a list of numbers. |
is_prime |
Test whether an integer is prime. |
prime_factorization |
Factor a positive integer into primes with exponents. |
gcd_lcm |
Greatest common divisor and least common multiple of two or more integers. |
solve_quadratic |
Roots of a·x² + b·x + c = 0, real or complex, with the discriminant. |
convert_base |
Convert an integer between bases 2–36. |
Linear algebra
Matrices are lists of rows, e.g. [[1, 2], [3, 4]].
| Tool | Description |
|---|---|
matrix_multiply |
Matrix product A @ B. |
matrix_transpose |
Transpose of a matrix. |
matrix_determinant |
Determinant of a square matrix. |
matrix_inverse |
Inverse of a square, non-singular matrix. |
solve_linear_system |
Solve A x = b for x. |
Symbolic (SymPy)
| Tool | Description |
|---|---|
simplify_expression |
Simplify, e.g. sin(x)**2 + cos(x)**2 → 1. |
expand_expression |
Expand, e.g. (x + 1)**2 → x**2 + 2*x + 1. |
factor_expression |
Factor, e.g. x**2 - 1 → (x - 1)*(x + 1). |
differentiate |
Derivative w.r.t. a variable (any order). |
integrate |
Indefinite integral w.r.t. a variable. |
definite_integral |
Definite integral over [lower, upper] (bounds may be oo). |
limit |
Limit as a variable approaches a point (oo allowed; left/right/two-sided). |
taylor_series |
Taylor series about a point, up to N terms. |
solve_symbolic_equation |
Solve an equation, e.g. x**2 = 4 → ["-2", "2"]. |
Resources & prompts
Beyond tools, the server exposes:
- Resources — mathematical constants to 50 digits:
math://constants(an index) andmath://constants/{name}forpi,e,tau,phi(golden ratio) andgamma(Euler–Mascheroni). - Prompts — reusable templates a client can offer to the user:
solve_step_by_stepandsolve_linear_system_prompt.
Install
Requires Python 3.10+.
Once published to PyPI (distribution name math-mcp-ay):
pip install math-mcp-ay
The import package is math_mcp and the command is math-mcp regardless of
the distribution name.
From source (for development):
git clone https://github.com/AbderY/math-mcp.git
cd math-mcp
pip install -e ".[dev]"
Run
The server speaks MCP over stdio:
math-mcp
# or
python -m math_mcp
Use with an MCP client
Add it to your client's MCP configuration. For example (Claude Desktop /
claude_desktop_config.json, or any MCP client that launches servers):
{
"mcpServers": {
"math": {
"command": "math-mcp"
}
}
}
If math-mcp is not on your PATH, use the interpreter form instead:
{
"mcpServers": {
"math": {
"command": "python",
"args": ["-m", "math_mcp"]
}
}
}
Examples
evaluate("2 ** 10 + factorial(5)")→1144.0descriptive_statistics([2, 4, 4, 4, 5, 5, 7, 9])→ mean5.0,pstdev2.0prime_factorization(360)→2³ · 3² · 5solve_quadratic(1, -3, 2)→ roots1.0and2.0convert_base("ff", 16, 2)→"11111111"matrix_inverse([[4, 7], [2, 6]])→[[0.6, -0.7], [-0.2, 0.4]]solve_linear_system([[1, 1], [1, -1]], [3, 1])→[2.0, 1.0]differentiate("x**3", "x", 2)→"6*x"definite_integral("exp(-x)", "x", "0", "oo")→"1"limit("sin(x)/x", "x", "0")→"1"taylor_series("exp(x)", "x", "0", 4)→"x**3/6 + x**2/2 + x + 1"solve_symbolic_equation("x**2 = 4")→["-2", "2"]
Development
pip install -e ".[dev]"
pytest
Releasing to PyPI
Publishing is automated via GitHub Actions using PyPI Trusted Publishing (OIDC), so no API token is stored in the repo.
One-time setup on pypi.org:
- Create (or claim) the project name
math-mcp-ay. - Under the project's Publishing settings, add a trusted publisher:
- Owner:
AbderY, repository:math-mcp - Workflow:
publish.yml - Environment:
pypi
- Owner:
Then, to release: bump the version in pyproject.toml and
src/math_mcp/__init__.py, tag it, and publish a GitHub Release. The
publish.yml workflow builds the sdist + wheel and uploads them to PyPI.
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file math_mcp_ay-0.3.0.tar.gz.
File metadata
- Download URL: math_mcp_ay-0.3.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57724fe7cd0685653ed257bd67bbcd859a0742c48f161f999275a994f52deb6d
|
|
| MD5 |
b6c1d5c6f67763138737498e90969dd0
|
|
| BLAKE2b-256 |
5677d389fea653f321d0746c7f0c8f2cae9d822e9e224ec02baff688fe839dd7
|
Provenance
The following attestation bundles were made for math_mcp_ay-0.3.0.tar.gz:
Publisher:
publish.yml on AbderY/math-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
math_mcp_ay-0.3.0.tar.gz -
Subject digest:
57724fe7cd0685653ed257bd67bbcd859a0742c48f161f999275a994f52deb6d - Sigstore transparency entry: 2794943438
- Sigstore integration time:
-
Permalink:
AbderY/math-mcp@f9e3ebe9e4cb21ba5d08b3c3528733e084261831 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/AbderY
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9e3ebe9e4cb21ba5d08b3c3528733e084261831 -
Trigger Event:
release
-
Statement type:
File details
Details for the file math_mcp_ay-0.3.0-py3-none-any.whl.
File metadata
- Download URL: math_mcp_ay-0.3.0-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1383701ab06c31f6894026aabef1ea8a05df24028cc9bf25f97fd24af85b0e26
|
|
| MD5 |
d948795886ca81b3dcad8f4e8fb51aaa
|
|
| BLAKE2b-256 |
973ef45e26680970254862095631883f78ab3f7980df7459afa3cc3869d2b535
|
Provenance
The following attestation bundles were made for math_mcp_ay-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on AbderY/math-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
math_mcp_ay-0.3.0-py3-none-any.whl -
Subject digest:
1383701ab06c31f6894026aabef1ea8a05df24028cc9bf25f97fd24af85b0e26 - Sigstore transparency entry: 2794943521
- Sigstore integration time:
-
Permalink:
AbderY/math-mcp@f9e3ebe9e4cb21ba5d08b3c3528733e084261831 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/AbderY
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9e3ebe9e4cb21ba5d08b3c3528733e084261831 -
Trigger Event:
release
-
Statement type: