Calculator MCP Server

Calculator MCP Server

Provides basic arithmetic operations (add, subtract, multiply, divide) through MCP, enabling AI clients to perform calculations via natural language.

Category
Visit Server

README

Calculator MCP Server

一个简单的计算器 MCP 服务器,基于 Model Context Protocol 协议,提供加减乘除四则运算功能。

项目简介

Calculator MCP Server 是一个基于 TypeScript 开发的 Model Context Protocol 服务器,为 AI 客户端提供标准化的计算工具能力。通过 MCP 协议,AI 助手可以自动调用加、减、乘、除四则运算工具,无需用户手动计算。

功能特性

  • ➕ 加法运算: 计算两个数的和
  • ➖ 减法运算: 计算两个数的差
  • ✖️ 乘法运算: 计算两个数的积
  • ➗ 除法运算: 计算两个数的商(自动校验除数不为零)
  • 🔒 参数校验: 基于 zod 的自动参数类型校验
  • 📝 调用日志: 服务器端输出每次工具调用的详细日志

工具列表

工具名 功能 参数
add 加法 a: number, b: number
subtract 减法 (a - b) a: number, b: number
multiply 乘法 a: number, b: number
divide 除法 (a ÷ b) a: number, b: number

技术栈

  • TypeScript + Node.js
  • @modelcontextprotocol/sdk(McpServer 高层 API)
  • zod(参数校验)

部署指南

环境依赖

  • Node.js >= 18

本地构建

# 安装依赖
npm install

# 构建
npm run build

构建完成后生成 dist/index.js,MCP 客户端会通过 stdio 方式调用它,无需手动启动。

服务配置

在 MCP 客户端中添加以下 STDIO 类型服务配置:

{
  "mcpServers": {
    "calculator": {
      "command": "npx",
      "args": [
        "-y",
        "calculator-mcp-server"
      ]
    }
  }
}

Windows 系统下,建议使用以下配置:

{
  "mcpServers": {
    "calculator": {
      "command": "cmd",
      "args": [
        "/c",
        "npx",
        "-y",
        "calculator-mcp-server"
      ]
    }
  }
}

如果使用本地源码运行,请将 args 替换为实际路径:

{
  "mcpServers": {
    "calculator": {
      "command": "node",
      "args": ["D:\\project\\open-mcp\\dist\\index.js"]
    }
  }
}

各客户端配置示例

Trae

打开 Trae 设置 → MCP 服务器,添加以下配置:

{
  "mcpServers": {
    "calculator": {
      "command": "node",
      "args": ["D:\\project\\open-mcp\\dist\\index.js"]
    }
  }
}

MCP Inspector 调试

npx @modelcontextprotocol/inspector node dist/index.js

浏览器打开后,可以在可视化界面中直接测试所有工具。

命令行测试

项目提供了测试脚本 test.cjs:

# 查看所有工具
node test.cjs list

# 调用具体工具(参数:工具名 a b)
node test.cjs call add 3 5
node test.cjs call multiply 123 456
node test.cjs call divide 100 3

使用示例

示例 1:加法运算

在 AI 客户端中输入:

帮我算一下 3 + 5 等于多少?

AI 自动调用 add 工具,返回结果:

3 + 5 = 8

示例 2:乘法运算

帮我算一下 123 × 456 等于多少?

AI 自动调用 multiply 工具,返回结果:

123 × 456 = 56088

示例 3:除法运算

帮我算一下 100 ÷ 3 等于多少?

AI 自动调用 divide 工具,返回结果:

100 ÷ 3 = 33.333333333333336

服务器运行日志

工具调用时,服务器终端会输出调用日志:

计算器 MCP 服务器已启动
[2026-08-04T05:46:55.953Z] 收到调用: multiply {"a":123,"b":456}
[2026-08-04T05:46:55.954Z] 结果(multiply): 123 × 456 = 56088

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured