数学计算工具

为LLM提供精确数学计算能力的服务器,支持算术、代数、微积分等多种数学运算。

  • by nerdo
  • TypeScript
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 nerdo/precision-math-mcp

使用说明

精密数学mcp

法学硕士不会做数学。 他们预测令牌,而不是计算答案。要求法学硕士乘法或求解方程,你可能会得到听起来很自信的错误答案。

这个MCP服务器通过给你的LLM一个真正的计算器来解决这个问题。它的动力来自 math.js,一个经过实战考验的数学库,拥有14k+GitHub star,处理从基本算术到符号微积分的所有内容。

所有表达式都使用 math.js语法 -看 math.js文档 供完整表达参考。

特性

  • 6数学工具:

    • calculate -计算数学表达式
    • simplify -简化代数表达式
    • derivative -计算符号导数
    • solve -求解变量方程
    • format -用精度/符号格式化数字
    • convert -单位间转换
  • 3种运输方式:

    • stdio -标准I/O(默认,适用于Claude Desktop)
    • http -可流式HTTP传输
    • sse -服务器发送事件(向后兼容性)

快速开始

无需安装即可直接运行(需要Bun、npm、yarn或pnpm):

# Using bunx (recommended)
bunx -y @nerdo/precision-math-mcp

# Using npx
npx -y @nerdo/precision-math-mcp

# Using yarn
yarn dlx @nerdo/precision-math-mcp

# Using pnpm
pnpm dlx @nerdo/precision-math-mcp

安装

全局安装

# Using bun
bun add -g @nerdo/precision-math-mcp

# Using npm
npm install -g @nerdo/precision-math-mcp

# Using yarn
yarn global add @nerdo/precision-math-mcp

# Using pnpm
pnpm add -g @nerdo/precision-math-mcp

然后运行:

precision-math-mcp

本地开发

git clone https://github.com/nerdo/precision-math-mcp
cd precision-math-mcp
bun install
bun run src/index.ts

用法

运输方式

# Stdio mode (default)
bunx -y @nerdo/precision-math-mcp --stdio

# HTTP mode
PORT=3141 bunx -y @nerdo/precision-math-mcp --http

# HTTP mode with authentication
PORT=3141 MCP_AUTH_TOKEN=your-secret bunx -y @nerdo/precision-math-mcp --http

环境变量

变量 默认值 描述
PORT 3141 HTTP服务器端口
MCP_AUTH_TOKEN (无) HTTP的可选身份验证令牌
MCP_TRANSPORT stdio 传输模式:stdio、http、sse
DESCRIPTION_MODE 强制 工具描述模式:强制(AI必须用于所有数学)或宽松(可选使用)

MCP客户端配置

克劳德桌面版

添加到您的Claude Desktop配置文件中:

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

{
  "mcpServers": {
    "precision-math": {
      "command": "bunx",
      "args": ["-y", "@nerdo/precision-math-mcp"]
    }
  }
}

或者使用npx:

{
  "mcpServers": {
    "precision-math": {
      "command": "npx",
      "args": ["-y", "@nerdo/precision-math-mcp"]
    }
  }
}

克劳德代码

添加到您的Claude Code MCP设置中:

{
  "mcpServers": {
    "precision-math": {
      "command": "bunx",
      "args": ["-y", "@nerdo/precision-math-mcp"]
    }
  }
}

工具示例

计算

使用可选变量计算数学表达式。

{
  "name": "calculate",
  "arguments": {
    "expression": "sqrt(a^2 + b^2)",
    "scope": { "a": 3, "b": 4 }
  }
}
// Returns: { "result": "5", "type": "number" }

支持:

  • 基本算术: 2 + 2 * 3 → 8
  • 功能: sin(pi/4), log(100), factorial(5)
  • 复数: sqrt(-1) → i
  • 矩阵: [[1,2],[3,4]] * [[1,0],[0,1]]
  • 单位: 2 inch to cm → 5.08 cm

简化

简化代数表达式。

{
  "name": "simplify",
  "arguments": {
    "expression": "2x + 3x - x"
  }
}
// Returns: { "result": "4 * x" }

衍生物

计算符号导数。

{
  "name": "derivative",
  "arguments": {
    "expression": "x^3 + 2*x",
    "variable": "x"
  }
}
// Returns: { "result": "3 * x ^ 2 + 2", "simplified": "3 * x ^ 2 + 2" }

解决

求解变量的方程式。

{
  "name": "solve",
  "arguments": {
    "equation": "x^2 - 4 = 0",
    "variable": "x"
  }
}
// Returns: { "solutions": ["2", "-2"], "type": "exact" }

格式

用特定精度或符号格式化数字。

{
  "name": "format",
  "arguments": {
    "value": "pi",
    "precision": 4
  }
}
// Returns: { "result": "3.142" }

转换

在单位之间转换。

{
  "name": "convert",
  "arguments": {
    "value": "100 km/h",
    "toUnit": "m/s"
  }
}
// Returns: { "result": "27.77777777777778 m / s", "numericValue": 27.77777777777778 }

测试

# Run all tests
bun test

# Run specific test file
bun test tests/tools/calculate.test.ts

MCP检验员测试

npx @modelcontextprotocol/inspector bun run src/index.ts

打开MCP检查器http://localhost:6274您可以在哪里:

  • 查看所有可用工具
  • 使用自定义参数调用工具
  • 请参阅JSON-RPC通信日志

发展

# Type check
bunx tsc --noEmit

# Run in watch mode
bun --watch run src/index.ts

许可证

麻省理工学院