MCP计算服务器
](https://smithery.ai/server/@611711Dark/mcp_calculate_server)
基于MCP协议和SymPy库的数学计算服务,提供强大的符号计算能力。
安全
截至版本 0.1.1,服务器通过受限制的仅SymPy计算器解析表达式。它不执行任意的Python代码,只支持一组精心策划的数学符号、函数和矩阵方法。
此版本还添加了对超大表达式和大型结果的验证,以降低昂贵的符号计算带来的拒绝服务风险。
主要特点
- 基本操作:加法、减法、乘法、除法、求幂
- 代数运算:表达式扩展、因子分解、简化
- 微积分:微分、积分(确定/不确定)、极限计算
- 方程求解:代数方程、方程组
- 矩阵运算:矩阵求逆、特征值/特征向量计算
- 级数展开:泰勒系列扩展
- 特殊功能:三角函数、对数函数、指数函数
使用示例
# Basic operations
"2 + 3*5" → 17
# Algebraic operations
"expand((x + 1)**2)" → x² + 2x + 1
"factor(x**2 - 2*x - 15)" → (x - 5)(x + 3)
# Calculus
"diff(sin(x), x)" → cos(x)
"integrate(exp(x), (x, 0, 1))" → E - 1
"integrate(exp(-x**2)*sin(x), (x, -oo, oo))" → 0
"limit(tan(x)/x, x, 0)" → 1
# Equation solving
"solve(x**2 - 4, x)" → [-2, 2]
"solve([x**2 + y**2 - 1, x + y - 1], [x, y])" → [(0, 1), (1, 0)]
# Matrix operations
"Matrix([[1, 2], [3, 4]]).inv()" → [[-2, 1], [3/2, -1/2]]
"Matrix([[1, 2, 3], [4, 5, 6]]).eigenvals()" → {9/2 - sqrt(33)/2: 1, 9/2 + sqrt(33)/2: 1}
"Sum(k, (k, 1, 10)).doit()" → 55
"series(cos(x), x, 0, 4)" → 1 - x²/2 + O(x⁴)安装
通过史密瑟里安装
通过以下方式自动安装克劳德桌面计算服务器 史密瑟里:
npx -y @smithery/cli install @611711Dark/mcp_sympy_calculate_server --client claude本地安装
- 克隆存储库:
git clone https://github.com/611711Dark/mcp_calculate_server.git
cd mcp_calculate_server- 创建虚拟环境并安装依赖关系:
uv venv
source .venv/bin/activate
uv pip install -e .- 配置:
"calculate_expression1": {
"isActive": false,
"command": "python",
"args": [
"server.py"
],
"cwd": "/path/to/mcp_calculate_server"
}API使用
呼叫 calculate_expression 通过MCP协议传递数学表达式字符串,解析器接受一组受限的SymPy表达式, expand, factor, simplify, diff, integrate, limit, series, solve, Matrix(...).det()/inv()/eigenvals()/eigenvects(),以及 Sum(...).doit().
支持的名称
- 符号:小写变量,如
x,y,z,以及k - 常量:
pi,E,oo,I - 功能:
Abs,sin,cos,tan,log,exp,sqrt,expand,factor,simplify,diff,integrate,limit,series,solve,Sum,Matrix - 矩阵法:
.det(),.inv(),.eigenvals(),.eigenvects() - SymPy方法:
.doit()关于支持的对象,例如Sum(...)
验证规则
有意拒绝依赖于任意Python特性、导入、文件系统访问或其他非数学构造的表达式。 非常大的扩展、高复杂度的解决方案和超大的结果也可能被拒绝,以降低拒绝服务风险。 关键字参数、私有属性、不支持的矩阵方法、格式错误的矩阵和不支持的名称将被拒绝,并显示错误消息。
依赖项
- mcp>=1.5.0
- sympy>=1.13.3
致谢
多亏了 这篇博客文章 介绍,以及 斯特凡诺 感谢他的帮助和负责任的披露。
许可证
该项目根据MIT许可证获得许可。看 许可证 文件。

