Mathematics MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Mathematics MCP Server add 15 and 27"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Mathematics MCP Server ๐งฎ
A comprehensive FastMCP server providing 22 mathematical operations for AI assistants like Claude.
A Model Context Protocol (MCP) server that provides mathematical operations as tools for AI assistants like Claude. This server enables Claude to perform accurate arithmetic calculations through a standardized interface.
๐ Table of Contents
Related MCP server: MCP Mathematics
What is Mathematics MCP Server?
Mathematics MCP Server is a lightweight server that exposes mathematical operations through the Model Context Protocol (MCP). It allows AI assistants to perform precise calculations by calling dedicated tools rather than relying on their internal reasoning capabilities.
Why Use This?
Accuracy: Ensures precise mathematical calculations
Reliability: Eliminates calculation errors that can occur with AI reasoning
Extensibility: Easy to add new mathematical operations
Logging: All operations are logged for debugging and audit purposes
Features
22 Mathematical Operations:
Basic (8): Addition, subtraction, multiplication, division, modulus, power, square, square root
Advanced (2): Factorial, absolute value
Logarithms (2): Logarithm (custom base), natural log
Trigonometry (3): Sine, cosine, tangent (degree-based)
Number Theory (2): GCD, LCM
Statistics (3): Mean, median, standard deviation
Rounding (2): Ceiling, floor
Error Handling: Robust error handling for edge cases (division by zero, negative square roots, etc.)
Comprehensive Logging: All operations logged to both file and stderr
Type Safety: Built with Pydantic models for input validation
MCP Compliant: Fully compatible with the Model Context Protocol standard
How It Works
โโโโโโโโโโโโโโโโโโโ
โ Claude Desktop โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โ JSON-RPC over stdio
โ
โโโโโโโโโโผโโโโโโโโโ
โ FastMCP โ
โ Mathematics โ
โ MCP Server โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โ Python Functions
โ
โโโโโโโโโโผโโโโโโโโโ
โ Math Operationsโ
โ (add, subtract,โ
โ multiply...) โ
โโโโโโโโโโโโโโโโโโโClaude sends a tool call request via JSON-RPC
FastMCP receives and validates the request
Python functions perform the calculation
Result is returned to Claude in structured format
Logging records the operation for debugging
Installation
Prerequisites
Python 3.8 or higher
uv package manager (recommended)
Step 1: Clone the Repository
git clone https://github.com/tanishra/math-mcp-server.git
cd mathematics-mcpStep 2: Install uv (if not already installed)
# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# On Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Or using pip
pip install uvStep 3: Install Dependencies
The project uses pyproject.toml for dependency management:
# Install all dependencies (uv automatically reads pyproject.toml)
uv sync
# Or using pip
pip install -e .Alternatively, you can install dependencies directly:
uv pip install fastmcp pydanticStep 4: Test the Server
Using the MCP Inspector (recommended for development):
# This opens an interactive web interface to test your MCP server
uv run fastmcp dev main.pyOr run the server directly:
# This runs the server in production mode
uv run fastmcp run main.pyYou should see:
Starting Mathematics MCP Server...Usage
Testing with MCP Inspector (Recommended)
The MCP Inspector provides a web-based interface to test your server:
uv run fastmcp dev main.pyThis will:
Start the MCP server
Open a web interface in your browser
Allow you to test all tools interactively
Show request/response details in real-time
Running the Server in Production Mode
uv run fastmcp run main.pyThe server will start and listen for MCP protocol messages on stdin/stdout.
Using with Claude Desktop
See the Integration with Claude Desktop section below.
Integration with Claude Desktop
Quick Installation (Recommended)
The easiest way to integrate with Claude Desktop is using the FastMCP installer:
uv run fastmcp install claude-desktop main.pyThis command will:
Automatically locate your Claude Desktop configuration file
Add the Mathematics MCP server configuration
Use the correct paths for your system
Restart Claude Desktop if needed
Manual Installation (Alternative)
If you prefer to configure manually or the automatic installation doesn't work:
Step 1: Locate Claude Desktop Configuration
The configuration file location depends on your operating system:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Step 2: Update Configuration
Open the configuration file and add the Mathematics MCP server:
{
"mcpServers": {
"mathematics": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mathematics-mcp",
"run",
"fastmcp",
"run",
"main.py"
]
}
}
}Important: Replace /absolute/path/to/mathematics-mcp with the actual path to your project directory.
Example for macOS/Linux:
{
"mcpServers": {
"mathematics": {
"command": "uv",
"args": [
"--directory",
"/Users/yourusername/projects/mathematics-mcp",
"run",
"fastmcp",
"run",
"main.py"
]
}
}
}Example for Windows:
{
"mcpServers": {
"mathematics": {
"command": "uv",
"args": [
"--directory",
"C:\\Users\\YourUsername\\projects\\mathematics-mcp",
"run",
"fastmcp",
"run",
"main.py"
]
}
}
}Step 3: Restart Claude Desktop
Quit Claude Desktop completely (Cmd+Q on Mac, Alt+F4 on Windows)
Relaunch Claude Desktop
Look for the ๐ icon in the bottom right indicating MCP servers are connected
Click the icon to see "mathematics" server listed
Step 4: Verify Installation
In Claude, try asking:
"What's 12345 + 67890?"
"Calculate the square root of 144"
"What's 25 to the power of 3?"
"Calculate the factorial of 10"
"What's the sine of 30 degrees?"
"Find the GCD of 48 and 18"
"Calculate the mean of these numbers: 10, 20, 30, 40, 50"
Claude should use the Mathematics MCP tools to provide accurate answers.
Troubleshooting Installation
If the automatic installation fails:
# Check if uv is installed correctly
uv --version
# Verify the server works
uv run fastmcp dev main.py
# Try manual configuration following the steps aboveAvailable Tools
1. Addition (add)
Input: {"a": 10, "b": 5}
Output: {"status": "success", "operation": "add", "result": 15}2. Subtraction (subtract)
Input: {"a": 10, "b": 5}
Output: {"status": "success", "operation": "subtract", "result": 5}3. Multiplication (multiply)
Input: {"a": 10, "b": 5}
Output: {"status": "success", "operation": "multiply", "result": 50}4. Division (divide)
Input: {"a": 10, "b": 5}
Output: {"status": "success", "operation": "divide", "result": 2.0}Note: Throws error on division by zero
5. Modulus (modulus)
Input: {"a": 10, "b": 3}
Output: {"status": "success", "operation": "modulus", "result": 1}Note: Throws error on modulus by zero
6. Power (power)
Input: {"base": 2, "exponent": 8}
Output: {"status": "success", "operation": "power", "result": 256}7. Square (square)
Input: {"a": 5}
Output: {"status": "success", "operation": "square", "result": 25}8. Square Root (sqrt)
Input: {"a": 144}
Output: {"status": "success", "operation": "sqrt", "result": 12.0}Note: Throws error on negative numbers
9. Factorial (factorial)
Input: {"a": 5}
Output: {"status": "success", "operation": "factorial", "result": 120}Note: Only works with non-negative integers
10. Absolute Value (absolute)
Input: {"a": -15}
Output: {"status": "success", "operation": "absolute", "result": 15}11. Logarithm (logarithm)
Input: {"value": 100, "base": 10}
Output: {"status": "success", "operation": "logarithm", "result": 2.0}Note: Default base is 10 if not specified
12. Natural Logarithm (natural_log)
Input: {"a": 2.718281828}
Output: {"status": "success", "operation": "natural_log", "result": 1.0}Note: Uses base e (approximately 2.718)
13. Sine (sine)
Input: {"angle": 90}
Output: {"status": "success", "operation": "sine", "result": 1.0}Note: Input angle in degrees
14. Cosine (cosine)
Input: {"angle": 0}
Output: {"status": "success", "operation": "cosine", "result": 1.0}Note: Input angle in degrees
15. Tangent (tangent)
Input: {"angle": 45}
Output: {"status": "success", "operation": "tangent", "result": 1.0}Note: Input angle in degrees, undefined at 90ยฐ, 270ยฐ, etc.
16. Greatest Common Divisor (gcd)
Input: {"a": 48, "b": 18}
Output: {"status": "success", "operation": "gcd", "result": 6}Note: Both numbers must be integers
17. Least Common Multiple (lcm)
Input: {"a": 12, "b": 18}
Output: {"status": "success", "operation": "lcm", "result": 36}Note: Both numbers must be integers
18. Mean (mean)
Input: {"numbers": [10, 20, 30, 40, 50]}
Output: {"status": "success", "operation": "mean", "result": 30.0}Note: Calculates average of all numbers in the list
19. Median (median)
Input: {"numbers": [1, 3, 5, 7, 9]}
Output: {"status": "success", "operation": "median", "result": 5}Note: Middle value when sorted; average of two middle values for even-length lists
20. Standard Deviation (standard_deviation)
Input: {"numbers": [2, 4, 4, 4, 5, 5, 7, 9]}
Output: {"status": "success", "operation": "standard_deviation", "result": 2.138}Note: Uses sample standard deviation (n-1); requires at least 2 numbers
21. Ceiling (ceiling)
Input: {"a": 3.2}
Output: {"status": "success", "operation": "ceiling", "result": 4}Note: Always rounds up
22. Floor (floor)
Input: {"a": 3.8}
Output: {"status": "success", "operation": "floor", "result": 3}Note: Always rounds down
Contributing
Contributions are welcome! Here's how you can help:
Reporting Bugs
Check if the issue already exists
Create a new issue with:
Clear description
Steps to reproduce
Expected vs actual behavior
Log output from
math_mcp.log
Suggesting Features
Open an issue describing the feature
Explain the use case
Provide examples if possible
Pull Requests
Fork the repository
Create a feature branch:
git checkout -b feature/amazing-featureMake your changes
Add tests if applicable
Commit with clear messages:
git commit -m "Add: New trigonometric functions"Push to your fork:
git push origin feature/amazing-featureOpen a Pull Request
Troubleshooting
Server Not Appearing in Claude Desktop
Problem: MCP server doesn't show up in Claude Desktop
Solutions:
Check the configuration file path is correct
Verify JSON syntax in
claude_desktop_config.jsonEnsure absolute paths are used (not relative paths)
Restart Claude Desktop completely
Check
math_mcp.logfor startup errors
"Unexpected non-whitespace character after JSON" Error
Problem: Claude Desktop shows JSON parsing errors
Solutions:
Ensure logging is NOT writing to
sys.stdoutUse
sys.stderror file logging onlyRemove any
print()statements from the code
Import Errors
Problem: ModuleNotFoundError: No module named 'fastmcp'
Solutions:
Activate your virtual environment
Install dependencies:
pip install fastmcp pydanticIf using venv, point to venv Python in config
Permission Errors
Problem: Cannot write to log file
Solutions:
Check write permissions on the directory
Use a different log location:
LOG_FILE = Path.home() / "math_mcp.log"Testing Connection
To test if the server is working:
# Run the server
python main.py
# In another terminal, send a test message (requires jq)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | python main.pyFuture Enhancement Ideas
Add complex number support
Implement matrix operations
Add unit conversion tools
Support for symbolic math (using SymPy)
Inverse trigonometric functions (arcsin, arccos, arctan)
Hyperbolic functions (sinh, cosh, tanh)
License
This project is licensed under the MIT License - see the LICENSE file for details.
Star โญ this repo if you find it helpful!
Available Tools
22 toolsabsoluteA
Calculate the absolute value of a given number.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Notes:
- Returns the absolute (non-negative) value of the input.
- Logs the operation and result.
Inputs: data (required). Returns: object
addA
Perform addition of two numbers provided in the data object.
Args:
data (TwoNumberOperation): An object containing two numbers a and b
to be added.
Returns:
Dict[str, Any]: A dictionary containing the operation name ("add") and
the result of the addition if successful, or an error
message if an exception occurs.
Logs:
Logs the operation and result in the format:
"ADD | {data.a} + {data.b} = {result}"
Inputs: data (required). Returns: object
ceilingA
Round a number up to the nearest integer.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Notes:
- Always rounds up (e.g., 3.1 -> 4, -3.1 -> -3).
- Logs the operation and result.
Inputs: data (required). Returns: object
cosineA
Calculate the cosine of an angle in degrees. Args: data (AngleOperation): An object containing the angle in degrees. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Notes: - Input angle should be in degrees (not radians). - Result is between -1 and 1. - Logs the operation and result.
Inputs: data (required). Returns: object
divideA
Perform division of two numbers provided in the TwoNumberOperation object.
Args:
data (TwoNumberOperation): An object containing two numbers, a and b,
where a is the numerator and b is the denominator.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Raises:
ZeroDivisionError: If the denominator (b) is zero.
Notes:
- Logs the division operation and its result.
- Returns a success response if the operation is successful.
- Returns an error response if an exception occurs.
Inputs: data (required). Returns: object
factorialA
Calculate the factorial of a given number.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Raises:
ValueError: If the input is negative or not an integer.
Notes:
- Only works with non-negative integers.
- Logs the operation and result.
Inputs: data (required). Returns: object
floorA
Round a number down to the nearest integer.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Notes:
- Always rounds down (e.g., 3.9 -> 3, -3.1 -> -4).
- Logs the operation and result.
Inputs: data (required). Returns: object
gcdA
Calculate the Greatest Common Divisor (GCD) of two numbers.
Args:
data (TwoNumberOperation): An object containing two numbers, a and b.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Raises:
ValueError: If inputs are not integers.
Notes:
- Both numbers must be integers.
- Returns the largest number that divides both inputs.
- Logs the operation and result.
Inputs: data (required). Returns: object
lcmA
Calculate the Least Common Multiple (LCM) of two numbers.
Args:
data (TwoNumberOperation): An object containing two numbers, a and b.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Raises:
ValueError: If inputs are not integers.
Notes:
- Both numbers must be integers.
- Returns the smallest number that is divisible by both inputs.
- Logs the operation and result.
Inputs: data (required). Returns: object
logarithmA
Calculate the logarithm of a value with a specified base. Args: data (LogOperation): An object containing the value and base for logarithm. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Raises: ValueError: If value is non-positive or base is invalid. Notes: - Default base is 10 (common logarithm). - Use base 'e' (2.718...) for natural logarithm. - Logs the operation and result.
Inputs: data (required). Returns: object
meanA
Calculate the mean (average) of a list of numbers. Args: data (ListOperation): An object containing a list of numbers. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Raises: ValueError: If the list is empty. Notes: - Mean is the sum of all numbers divided by count. - Logs the operation and result.
Inputs: data (required). Returns: object
medianA
Calculate the median of a list of numbers. Args: data (ListOperation): An object containing a list of numbers. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Raises: ValueError: If the list is empty. Notes: - Median is the middle value when numbers are sorted. - For even-length lists, returns average of two middle values. - Logs the operation and result.
Inputs: data (required). Returns: object
modulusA
Calculate the modulus (remainder) of two numbers provided in the data object.
Args:
data (TwoNumberOperation): An object containing two numbers, a and b.
Returns:
Dict[str, Any]: A dictionary containing the operation result if successful,
or an error message if an exception occurs.
Raises:
ZeroDivisionError: If the second number (b) is zero, as modulus by zero is not allowed.
Logs:
Logs the operation and result in the format "MOD | a % b = result" if successful.
Example:
data = TwoNumberOperation(a=10, b=3)
result = modulus(data)
# result -> {"status": "success", "operation": "modulus", "result": 1}
Inputs: data (required). Returns: object
multiplyA
Perform multiplication of two numbers provided in the data object.
Args:
data (TwoNumberOperation): An object containing two numbers a and b
to be multiplied.
Returns:
Dict[str, Any]: A dictionary containing the result of the multiplication
operation or an error message in case of failure.
Logs:
Logs the multiplication operation in the format:
"MUL | {data.a} * {data.b} = {result}"
Exceptions:
Catches any exceptions that occur during the operation and returns an
error response with the exception message.
Inputs: data (required). Returns: object
natural_logA
Calculate the natural logarithm (base e) of a given number.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation result or an error message.
Raises:
ValueError: If the input is non-positive.
Notes:
- Natural log uses base e (approximately 2.718).
- Logs the operation and result.
Inputs: data (required). Returns: object
powerA
Calculate the power of a given base raised to a given exponent. Args: data (PowerOperation): An object containing the base and exponent values. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Logs: Logs the operation in the format "POW | base ^ exponent = result". Exceptions: Catches any exceptions during the calculation and returns an error response.
Inputs: data (required). Returns: object
sineA
Calculate the sine of an angle in degrees. Args: data (AngleOperation): An object containing the angle in degrees. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Notes: - Input angle should be in degrees (not radians). - Result is between -1 and 1. - Logs the operation and result.
Inputs: data (required). Returns: object
sqrtA
Calculate the square root of a given number.
Args:
data (SingleNumberOperation): An object containing the input number a.
Returns:
Dict[str, Any]: A dictionary containing the operation name, result,
and status of the operation.
Raises:
ValueError: If the input number a is negative.
Notes:
- Logs the operation and result using the logger.
- Returns a success response if the operation is successful.
- Returns an error response if an exception occurs.
Inputs: data (required). Returns: object
squareA
Calculate the square of a given number. Args: data (SingleNumberOperation): An object containing the number to be squared. Returns: Dict[str, Any]: A dictionary containing the operation name ("square") and the result of squaring the input number. In case of an error, returns an error response. Logs: Logs the operation and the result in the format "SQUARE | ^2 = ". Raises: Exception: If an error occurs during the calculation.
Inputs: data (required). Returns: object
standard_deviationA
Calculate the standard deviation of a list of numbers. Args: data (ListOperation): An object containing a list of numbers. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Raises: ValueError: If the list has fewer than 2 numbers. Notes: - Measures the amount of variation in the dataset. - Uses sample standard deviation (n-1 denominator). - Logs the operation and result.
Inputs: data (required). Returns: object
subtractB
Perform subtraction of two numbers provided in the data object.
Args:
data (TwoNumberOperation): An object containing two numbers, a and b.
Returns:
Dict[str, Any]: A dictionary containing the operation name ("subtract")
and the result of the subtraction if successful, or an error message
if an exception occurs.
Logs:
Logs the subtraction operation and its result in the format:
"SUB | {data.a} - {data.b} = {result}".
Inputs: data (required). Returns: object
tangentA
Calculate the tangent of an angle in degrees. Args: data (AngleOperation): An object containing the angle in degrees. Returns: Dict[str, Any]: A dictionary containing the operation result or an error message. Notes: - Input angle should be in degrees (not radians). - Undefined at 90ยฐ, 270ยฐ, etc. (will return very large values). - Logs the operation and result.
Inputs: data (required). Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
TDQS
Scored across 22 tools
Most tools target distinct mathematical operations with clear boundaries. The main overlap is `logarithm` and `natural_log`, since natural_log is just a special case of logarithm with base e.
Tool names are mostly lowercase single-word operation names like add, divide, sine, and median. Minor deviations include the abbreviation `sqrt`, and snake_case names `natural_log` and `standard_deviation`, but the naming style is still predictable and readable.
At 22 tools, this is on the heavier side for a math operation server. Most tools are individually useful, but the redundancy between logarithm and natural_log suggests the set could be slightly trimmed.
The tool surface covers arithmetic, powers, roots, logs, trig, rounding, number theory, and basic statistics, which is a solid range for a mathematics server. Minor gaps like inverse trig or hyperbolic functions are not critical for a general-purpose math toolkit.
Maintenance
Related MCP Connectors
Hosted OpenAI Ads MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
MCP server unifying ERPs, CRMs, APIs and knowledge base for Claude, ChatGPT and Gemini.
Hosted SQL Server MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Hosted WordPress MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- FlicenseAqualityDmaintenanceA basic MCP server built with the FastMCP framework that provides fundamental mathematical operations like addition, subtraction, multiplication, and division. It serves as a demonstration for integrating math-based tools into MCP-compatible environments like Cursor IDE.4-
- AlicenseCqualityDmaintenanceA comprehensive MCP server that turns any AI assistant into a powerful mathematical computation engine, providing 52 advanced functions, 158 unit conversions, financial calculations, and secure AST-based evaluation.1816MIT
- FlicenseNot gradedqualityDmaintenanceA FastMCP server that provides mathematical tools (addition, multiplication, temperature conversion) for Claude to execute via natural language.-
- FlicenseNot gradedqualityDmaintenanceA simple MCP server that provides basic arithmetic operations like add and multiply, enabling Claude to perform math calculations.-