Mathematics MCP Server
Click on "Install 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 Serveradd 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: Test FastMCP
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!
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tanishra/math-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server