Calculator MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Calculator MCP Server 🧮
基于 Python AST 的安全表达式计算器 MCP 服务,支持基础数学运算和错误防护机制。
功能特性
✅ 支持加减乘除四则运算(
+,-,*,/)✅ 支持幂运算(
**)✅ 支持正负号处理(
+5,-3)✅ 智能格式化计算结果:
整数结果直接显示整数
小数结果保留最多15位有效数字
自动去除末尾多余的零
⚠️ 安全防护:
拦截代码注入风险(通过 AST 解析而非
eval)除零错误防护
语法错误提示
类型安全检查
幂运算安全检查
Related MCP server: Mathematical MCP Server
安装方式
pip install mcp-calculate-server快速使用
from mcp.server.fastmcp import FastMCP
# 启动计算器服务
calculator = FastMCP("CalculatorServer")
calculator.run(transport='stdio')API 接口
perform_calculation(expression: str) -> str
接收数学表达式字符串,返回格式化结果或错误信息
>>> perform_calculation("5+3")
"🧮 计算结果:5+3 = 8"
>>> perform_calculation("10/3")
"🧮 计算结果:10/3 = 3.333333333333333"
>>> perform_calculation("10**20")
"🧮 计算结果:10**20 = 100000000000000000000"
>>> perform_calculation("2**3")
"🧮 计算结果:2**3 = 8"
>>> perform_calculation("10/0")
"❌ 错误:除数不能为零"
>>> perform_calculation("0**-1")
"❌ 错误:零的负数次幂未定义"
>>> perform_calculation("(-1)**0.5")
"❌ 错误:负数的非整数次幂未定义"支持的运算符
操作符 | 说明 | 示例 |
+ | 加法 |
|
- | 减法 |
|
* | 乘法 |
|
/ | 除法 |
|
** | 幂运算 |
|
-x | 取负 |
|
+x | 取正 |
|
错误码说明
错误类型 | 示例输出 |
语法错误 |
|
不支持的运算符 |
|
除零错误 |
|
非法操作数类型 |
|
零的负数次幂 |
|
负数的非整数次幂 |
|
依赖环境
Python 3.13+
mcp-server库(自动安装)
开源协议
MIT License,详情见 LICENSE
源码地址
GitHub: https://github.com/xiaoyingv/mcp_calculate_server
贡献指南
欢迎提交 PR 和报告 issue,提交前请阅读 CONTRIBUTING.md
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Safe scientific calculator MCP for numeric expressions
Evaluate mathematical expressions and propagate measurement uncertainty.
Evaluate, simplify, and differentiate mathematical expressions.
Unofficial Math.js MCP — wraps the mathjs.org API (free, no auth)
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides mathematical operation tools including basic arithmetic (add, subtract, multiply, divide), power and square root calculations, and safe evaluation of mathematical expressions.-
- FlicenseNot gradedqualityDmaintenanceA 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.-
- AlicenseAqualityDmaintenanceEnables safe math expression evaluation, unit conversion, statistical analysis, number formatting, and percentage calculations for AI agents via MCP.548 npmMIT
- AlicenseAqualityBmaintenanceProvides LLMs with deterministic math tools for sandboxed expression evaluation, descriptive statistics, primality testing, prime factorization, GCD/LCM, quadratic solving, and base conversion. Every operation runs real code rather than relying on the model's arithmetic, with expression parsing restricted to a whitelist of operators, constants, and functions.211MIT