Skip to main content
Glama

MCP 计算服务器

一个基于 MCP 协议和 SymPy 库的数学计算服务,提供强大的符号计算能力。

安全性

从 0.1.1 版本开始,服务器通过受限的 SymPy 专用评估器解析表达式。它不会执行任意 Python 代码,并且仅支持一组精选的数学符号、函数和矩阵方法。

此版本还增加了对超大表达式和大型结果的验证,以降低因昂贵的符号计算而导致的拒绝服务风险。

Related MCP server: mcp-sympy

主要功能

  • 基本运算:加法、减法、乘法、除法、幂运算

  • 代数运算:表达式展开、因式分解、化简

  • 微积分:微分、积分(定积分/不定积分)、极限计算

  • 方程求解:代数方程、方程组

  • 矩阵运算:矩阵求逆、特征值/特征向量计算

  • 级数展开:泰勒级数展开

  • 特殊函数:三角函数、对数函数、指数函数

使用示例

# 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⁴)

安装

通过 Smithery 安装

要通过 Smithery 自动为 Claude Desktop 安装 Calculate Server:

npx -y @smithery/cli install @611711Dark/mcp_sympy_calculate_server --client claude

本地安装

  1. 克隆仓库:

    git clone https://github.com/611711Dark/mcp_calculate_server.git
    cd mcp_calculate_server
  2. 创建虚拟环境并安装依赖:

    uv venv
    source .venv/bin/activate
    uv pip install -e .
  3. 配置:

    "calculate_expression1": {
       "isActive": false,
       "command": "python",
       "args": [
         "server.py"
       ],
       "cwd": "/path/to/mcp_calculate_server"
     }

API 使用

通过 MCP 协议调用 calculate_expression 工具,并传入一个数学表达式字符串。解析器接受受限的 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 方法:在受支持的对象(如 Sum(...))上使用 .doit()

验证规则

依赖于任意 Python 特性、导入、文件系统访问或其他非数学构造的表达式会被刻意拒绝。 非常大的展开式、高复杂度的求解以及超大的结果也可能会被拒绝,以降低拒绝服务风险。 关键字参数、私有属性、不支持的矩阵方法、格式错误的矩阵以及不支持的名称会被拒绝并返回错误消息。

依赖项

  • mcp>=1.5.0

  • sympy>=1.13.3

致谢

感谢 这篇博客文章 的介绍,以及 Stefano 的帮助和负责任的披露。

许可证

本项目采用 MIT 许可证。请参阅 LICENSE 文件。

中文版本

Available Tools

1 tool
calculate_expressionA

calculate mathematical expressions using the sympify function from sympy, parse and compute the input mathematical expression string, supports direct calls to SymPy functions (automatically recognizes x, y, z as symbolic variables) Parameters: expression (str): Mathematical expression, e.g., "223 - 344 * 6" or "sin(pi/2) + log(10)".Replace special symbols with approximate values, e.g., pi → 3.1415" Example expressions: "2 + 3*5" # Basic arithmetic → 17 "expand((x + 1)2)" # Expand → x² + 2x + 1 "diff(sin(x), x)" # Derivative → cos(x) "integrate(exp(x), (x, 0, 1))" # Definite integral → E - 1 "solve(x2 - 4, x)" # Solve equation → [-2, 2] "limit(tan(x)/x, x, 0)" # Limit → 1 "Sum(k, (k, 1, 10)).doit()" # Summation → 55 "Matrix([[1, 2], [3, 4]]).inv()" # Matrix inverse → [[-2, 1], [3/2, -1/2]] "simplify((x2 - 1)/(x + 1))" # Simplify → x - 1 "factor(x2 - 2*x - 15)" # Factorize → (x - 5)(x + 3) "series(cos(x), x, 0, 4)" # Taylor series → 1 - x²/2 + x⁴/24 + O(x⁴) "integrate(exp(-x*2)*sin(x), (x, -oo, oo))" # Complex integral "solve([x**2 + y*2 - 1, x + y - 1], [x, y])" # Solve system of equations "Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).eigenvals()" # Matrix eigenvalues Returns: str: Calculation result. If the expression cannot be parsed or computed, returns an error message (str).

ParametersJSON Schema
NameRequiredDescriptionDefault
expressionYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses key behavioral traits: it uses sympify from sympy, supports symbolic variables (x, y, z), handles special symbols (e.g., pi → 3.1415), and returns a string result or error message. It also lists many example behaviors (e.g., derivatives, integrals). However, it doesn't mention potential limitations like performance, complexity bounds, or specific error conditions beyond 'cannot be parsed or computed.'

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose and parameter explanation, but it includes a lengthy list of 14 example expressions. While these examples are informative, they make the description verbose and could be trimmed or summarized. The structure is logical but not optimally concise, as some examples might be redundant for conveying the tool's capabilities.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (mathematical computation with sympy), the description is highly complete. It explains the purpose, parameter semantics in detail, behavioral traits, and includes an output schema (returns str or error). With no annotations, it covers all necessary aspects: how to use it, what it does, and what to expect, making it sufficient for an AI agent to invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must fully compensate. It adds rich semantics: it defines the 'expression' parameter as a 'Mathematical expression' with examples (e.g., '2 + 3*5'), explains special symbol handling (pi → 3.1415), and provides numerous detailed examples showing syntax and usage. This goes far beyond the basic schema, making the parameter's meaning and format clear.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'calculate mathematical expressions using the `sympify` function from `sympy`, parse and compute the input mathematical expression string.' It specifies the exact method (sympify from sympy) and scope (mathematical expressions), making it highly specific. With no sibling tools, differentiation isn't needed, but the description is precise about what it does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage through extensive examples (e.g., 'Example expressions:') that show various mathematical operations, suggesting when to use it for different types of calculations. However, it lacks explicit guidance on when not to use it or alternatives, and there are no sibling tools to compare against. The examples serve as implicit guidance but aren't structured as explicit rules.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool update
    • First observedcalculate_expression

TDQS

A4.1/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or confusion between tools. The single tool 'calculate_expression' has a clearly defined purpose that cannot be mistaken for any other tool in this server.

Naming Consistency5/5

The single tool name 'calculate_expression' follows a clear verb_noun pattern. With only one tool, naming consistency is inherently perfect as there are no other tools to compare against or create inconsistencies with.

Tool Count2/5

A single tool server is generally too minimal for most practical purposes, even for a focused domain like mathematical calculation. While the tool is powerful, having only one tool feels thin and limiting for what appears to be a comprehensive mathematical computation server.

Completeness3/5

The single tool covers a wide range of mathematical operations through expression parsing, but there are notable gaps in the surface area. For a calculation server, one might expect separate tools for different mathematical domains (algebra, calculus, matrix operations) or at least tools for common specific operations beyond general expression evaluation.

Maintenance

ActivityInactive
ResponsivenessResponsive

Related MCP Connectors

Related MCP Servers

  • A
    license
    C
    quality
    F
    maintenance
    A Mathematical Computation Protocol server providing 286 mathematical functions across multiple domains with flexible transport options (STDIO/HTTP) and streaming capabilities.
    100
    4
    Apache 2.0
  • A
    license
    C
    quality
    C
    maintenance
    An MCP server that provides access to SymPy's symbolic mathematics library for advanced algebraic computations. It enables users to perform complex tasks such as symbolic simplification, calculus, equation solving, matrix operations, and number theory.
    100
    61 PyPI
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    A Python-based MCP server providing mathematical computation tools and plotting utilities for a wide range of math topics including calculus, matrix operations, statistics, and more.
    22
    5
    MIT