数学计算服务器

一个提供高级数学计算能力的服务器,包括符号数学、统计分析和矩阵运算。

  • by huhabla
  • Python
  • 本地部署
  • 63 星标
  • 更新于
在 GitHub 查看 huhabla/calculator-mcp-server

使用说明

数学计算器MCP服务器

这是一个模型上下文协议(MCP)服务器,为Claude提供高级数学计算功能,包括符号数学、统计分析和矩阵运算。

特性

数学计算器MCP服务器提供以下工具:

  • 基本计算:安全地计算数学表达式
  • 符号数学:
    • 求解方程(线性、二次、多项式等)
    • 计算表达式的导数
    • 计算表达式的积分
  • 统计分析:
    • 平均值、中位数、众数
    • 方差、标准差
    • 相关系数
    • 线性回归
    • 置信区间
  • 矩阵运算:
    • 矩阵加法
    • 矩阵乘法
    • 矩阵转置

安装

先决条件

  • Python 3.10+(推荐使用:Python 3.11+)
  • 紫外线 (推荐)或pip
  • Claude桌面应用程序(与Claude一起使用MCP服务器)

安装步骤

  1. 克隆存储库:

    git clone https://github.com/huhabla/calculator-mcp-server.git
    cd calculator-mcp-server
    
  2. (选项1)使用提供的脚本进行设置:

    chmod +x setup_venv.sh
    ./setup_venv.sh
    

    (选项2)或手动设置虚拟环境:

    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  3. 运行文档测试以验证一切正常:

    bash run_doctests.sh
    

与Claude Desktop集成

方法1:在Claude Desktop中配置

将服务器添加到Claude Desktop配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json

将以下内容添加到 mcpServers 章节:

{
  "mcpServers": {
    "calculator": {
      "command": "uvx",
      "args": [
        "--from",
        "calculator-mcp-server@git+https://github.com/huhabla/calculator-mcp-server.git",
        "--",
        "calculator-mcp-server",
        "--stdio"
      ]
    }
  }
}

备注:The --stdio 需要标志才能与Claude Desktop正确集成。这 -- 将uvx参数与计算器服务器参数分开。

方法2:使用FastMCP进行安装

  1. 确保你安装了紫外线(安装指南)

  2. 在Claude Desktop中安装MCP服务器:

    fastmcp install calculator_server.py
    

    或者使用自定义名称:

    fastmcp install calculator_server.py --name "Math Calculator"
    
  3. 安装后,Claude将自动访问所有数学工具和函数。

使用示例

与Claude Desktop集成后,您可以让Claude执行各种数学运算。以下是一些示例:

基本计算

Can you calculate 3.5^2 * sin(pi/4)?

求解方程

Solve the following equation: x^2 - 5x + 6 = 0

计算导数

What's the derivative of sin(x^2) with respect to x?

计算积分

Calculate the integral of x^2 * e^x

统计分析

Find the mean, median, mode, and standard deviation of this dataset: [23, 45, 12, 67, 34, 23, 18, 95, 41, 23]

线性回归

Perform a linear regression on these points: (1,2), (2,3.5), (3,5.1), (4,6.5), (5,8.2)

矩阵运算

Multiply these two matrices:
[1, 2, 3]
[4, 5, 6]

and

[7, 8]
[9, 10]
[11, 12]

发展

测试

运行全面的doctest套件:

bash run_doctests.sh

互动式开发模式

对于开发和调试,您可以使用FastMCP开发模式:

fastmcp dev calculator_server.py

这将启动一个本地web界面,您可以在其中交互式地测试所有工具。

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

致谢