M

MCP:计算器

MCYJYA/mcp-calculator
0 Stars 44 次浏览 ENFJ 更新于 2026-08-23

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "calculator": {
      "args": [
        "string"
      ],
      "command": "python mcp_server.py",
      "env": {
        "PYTHONPATH": "/app"
      }
    }
  }
}

服务介绍

MCP Mathematical Expression Calculator Server

A mathematical expression calculator server based on FastMCP framework implementing the Model Context Protocol (MCP) standard.

Project Introduction

This project implements a secure mathematical expression calculator that can be called as an MCP tool by other applications. It uses Abstract Syntax Tree (AST) to parse expressions, avoiding code injection risks, while supporting various basic mathematical operations.

Features

  1. Secure Calculation - Uses AST to parse expressions, avoiding code injection risks
  2. Basic Operations Support - Supports basic mathematical operations such as addition, subtraction, multiplication, division, modulo, and power operations
  3. Error Handling - Comprehensive exception handling mechanism, including division by zero and illegal expression detection
  4. MCP Tool Integration - Can be called as an MCP tool by other applications

Requirements

  • Python 3.7+
  • fastmcp>=0.1.0
  • Flask==2.3.2
  • requests==2.31.0

Installation

pip install -r requirements.txt

Usage

Start the server:

python mcp_server.py

Testing

Run the test script:

python test_calculator.py

Supported Operators

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Floor division: //
  • Modulo: %
  • Power: **
  • Parentheses: ()

Example Expressions

  • 2 + 3 * 4
  • (2 + 3) * 4
  • 3.14 * 2.5
  • 2 ** 3
  • 10 // 3
  • 10 % 3

Project Structure

.
├── mcp_server.py           # Main server file
├── test_calculator.py      # Test script
├── requirements.txt        # Dependencies file
├── README.md               # English documentation
└── README_zh.md            # Chinese documentation

Contributing

Issues and Pull Requests are welcome for contributions.

相关 MCP 服务