数学计算服务器

MCP Math Server是一个为大型语言模型提供精确数学运算的服务器,支持高精度算术、高级数学运算和统计分析。

  • by peter-abel
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 peter-abel/mcp-math-server

使用说明

MCP数学服务器

一种模型上下文协议(MCP)服务器,为大型语言模型(LLM)提供精确的数学运算。该服务器通过提供精确的计算工具消除了LLM中常见的数学错误。

特性

🔢 高精度算法

  • 任意精度十进制算术
  • 消除浮点错误
  • 支持非常大的数字

🧮 高等数学

  • 符号数学:方程求解、简化
  • 线性代数:矩阵运算、特征值、行列式
  • 统计:平均值、中位数、标准差、分位数
  • 微积分:导数、积分、极限
  • 数论:素数检验、因式分解、斐波那契

安装

  1. 克隆和设置:
git clone <your-repo>
cd mcp-math-server
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt
  1. 在开发模式下安装:
pip install -e .

用法

运行服务器

python src/math_server.py

与Claude Desktop集成

添加到您的Claude Desktop配置(claude_desktop_config.json):

{
  "mcpServers": {
    "math-server": {
      "command": "python",
      "args": ["/path/to/your/mcp-math-server/src/math_server.py"],
      "env": {}
    }
  }
}

可用工具

1.精确算术

# Example usage in Claude:
# "Calculate 0.1 + 0.2 with high precision"
precise_arithmetic("0.1 + 0.2", precision=50)

2.方程求解

# Solve quadratic equations
solve_equation("x**2 + 2*x - 3 = 0", "x")
# Solve system of equations
solve_equation("2*x + y - 5 = 0", "x")

3.矩阵运算

# Matrix multiplication
matrix_operations("multiply", [[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
# Eigenvalues
matrix_operations("eigenvalues", [[[4, -2], [1, 1]]])

4.统计分析

# Calculate statistics
statistics_calc([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], "mean")
statistics_calc([1, 2, 3, 4, 5], "stdev")

5.微积分运算

# Derivatives
calculus_operations("x**3 + 2*x**2 + x", "x", "derivative", order=2)
# Integrals
calculus_operations("x**2", "x", "integral", lower_limit=0, upper_limit=10)

6.数论

# Check if prime
number_theory(97, "is_prime")
# Prime factorization
number_theory(60, "prime_factors")
# Fibonacci numbers
number_theory(20, "fibonacci")

对话示例

用户“0.1+0.2等于多少?我需要确切的答案。”
克劳德与MCP:使用精确算术:0.1+0.2=0.3精确(不是0.30000000000000004)

用户所以,让我们求解x2加5x加6等于0。
克劳德与MCP:解为x=-2和x=-3

用户:“矩阵[[3,1],[0,2]]的特征值是什么?”
克劳德与MCP:特征值为3.0和2.0

益处

  • ✅ 消除浮点错误
  • ✅ 提供精确的符号解决方案
  • ✅ 处理任意大的数字
  • ✅ 支持复杂的数学运算
  • ✅ 维护计算的审计跟踪

发展

添加新的数学函数

  1. 添加新的工具方法 MathServer 类
  2. 使用 @self.server.call_tool() 装饰器
  3. 返回 List[TextContent] 有结果
  4. 包括适当的错误处理

测试

# Run the server and test with sample inputs
python src/math_server.py

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 添加新功能的测试
  4. 提交拉取请求

许可证

MIT许可证-有关详细信息,请参阅许可证文件。