Mathematical MCP Server
A mathematical MCP server exposing 6 basic arithmetic and secure symbolic expression evaluation tools (add, subtract, multiply, divide, power, evaluate_expression) with structured JSON responses, input validation, and safe AST-based parsing.
README
Mathematical MCP Server
A small, secure Model Context Protocol (MCP) server that exposes 6 basic mathematical tools to any MCP-compatible AI client (e.g., Claude Desktop, Cursor, VS Code).
Built using Python, FastMCP, Pydantic, and SymPy, this server performs basic arithmetic and safe symbolic expression evaluation.
Features
- Standardized Structured Responses: Returns structured JSON responses containing
success,result(properly serialized to JSON-friendly types),error, andexecution_time_ms. - Input Validation: Enforces strict type checking using Pydantic.
- Safe Expression Evaluation: Parses and evaluates string equations (e.g.,
(5+7)*9/3) using a secure whitelist-based SymPy AST walker. - Robust Error Handling: Intercepts and formats errors like division-by-zero and complex roots.
- Strict I/O Logging: Automatically logs incoming requests, runtime arguments, execution speeds, and errors strictly to
stderrto preserve stdout for MCP JSON-RPC protocol transport.
Folder Structure
Calculator_MCP_Server/
├── config.py # Computational boundaries and whitelists
├── schemas.py # Pydantic response models
├── utils.py # Logging configurations and tool execution wrappers
├── calculator.py # Pure mathematical algorithms
├── tools.py # MCP tools definitions and binding using FastMCP
├── server.py # Application entry point
├── requirements.txt # Python dependencies
├── pyproject.toml # Formatter (black/ruff) and pytest config
├── .gitignore # Git files pattern exclusions
└── tests/
├── test_calculator.py # Unit tests for core algorithms
└── test_tools.py # Integration tests for tool wrappers
Installation & Setup
1. Prerequisites
- Python 3.12+
- pip (Python package installer)
2. Set Up Virtual Environment
Clone this repository and navigate into the folder:
cd Calculator_MCP_Server
Create a virtual environment:
# On Windows
python -m venv .venv
.venv\Scripts\activate
# On macOS/Linux
python3 -m venv .venv
source .venv/bin/activate
3. Install Dependencies
pip install -r requirements.txt
Running the MCP Server
The server communicates via standard I/O (stdio) by default, making it ideal for local LLM integrations.
# Run server
python server.py
To run with live reloading and access the MCP Inspector web interface (ideal for testing tools in the browser):
fastmcp dev server.py
Connecting to MCP Clients
Claude Desktop
To integrate this mathematical server with Claude Desktop, add it to your configuration file:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Add the following to the mcpServers object:
{
"mcpServers": {
"math-server": {
"command": "python",
"args": [
"c:/Users/Admin/OneDrive/Documents/Projects/Calculator_MCP_Server/server.py"
],
"env": {
"LOG_LEVEL": "INFO",
"MAX_FACTORIAL_N": "10000"
}
}
}
}
Note: Make sure to specify the absolute path to your Python executable if it's not globally available in your environment's PATH.
Available Tools
add(a, b): Returns $a + b$.subtract(a, b): Returns $a - b$.multiply(a, b): Returns $a \times b$.divide(a, b): Returns $a / b$ (raises division-by-zero errors).power(base, exponent): Returns $base^{exponent}$ (handles negative bases/exponent calculations).evaluate_expression(expression): Safely parses and evaluates mathematical expression strings (e.g.(5+7)*9/3). Supports basic math operators and trigonometric/root functions.
Example AI Prompts
You can write naturally to any MCP client equipped with this server:
- "What is 567 × 897?" (calls
multiply) - "What is 2 raised to the power of 10?" (calls
power) - "Calculate (12 + 8) * 3 / 2" (calls
evaluate_expression) - "What is sin(0) + cos(0)?" (calls
evaluate_expression)
Testing
To run the automated tests:
pytest
To run with coverage or verbose mode:
pytest -v
Future Improvements
- Caching Layer: Cache expensive symbolic evaluations and factorial queries.
- Extended Solvers: Implement solvers for cubic equations and system of linear equations (using SymPy's
linsolve). - Advanced Matrix Algorithms: Eigenvalue and eigenvector calculations using NumPy/SciPy.
- Calculus Tools: Symbolic derivative and integration tools.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.