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.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。