Skip to main content
Glama
souravjai

Calculator MCP Server

by souravjai

Calculator MCP Server

一个基于 Model Context Protocol (MCP) 的小型服务器,可通过 stdio 提供基本的计算器操作。

计算器 MCP 服务器教程

功能

该服务器提供以下工具:

工具

说明

参数

add

将两个数字相加

op1, op2

sub

用第一个数字减去第二个数字

op1, op2

mul

将两个数字相乘

op1, op2

div

将第一个数字除以第二个数字

op1, op2

所有参数都必须为数字。当 op2 为 0 时,div 会返回错误。

Related MCP server: Simple Calculator MCP

环境要求

  • Node.js 18 或更高版本

  • npm

安装

从当前目录安装依赖:

npm install

运行服务器

通过 stdio 启动 MCP 服务器:

npm start

服务器会等待 MCP 客户端连接,因此不会在终端中打印正常的应用程序输出。

使用示例客户端进行测试

示例客户端会启动服务器、列出其工具,并以 10 和 0 调用 div,以演示除以零错误:

npm run test-client

要测试成功运算,请更新 mcp-client-test.ts 中的 callTool 参数,例如:

arguments: { op1: 10, op2: 2 },

使用 MCP Inspector

使用以下命令运行交互式 MCP Inspector:

npm run mcp-inspect

打开命令输出的 URL,然后选择一个计算器工具,并为 op1 和 op2 提供值。

项目文件

  • mcp-server.ts - MCP 服务器和计算器工具定义

  • mcp-client-test.ts - 示例 MCP 客户端

  • mcp-calculator.gif - 教程演示

  • package.json - 脚本和依赖

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    D
    maintenance
    Provides basic mathematical operations including addition, subtraction, multiplication, division, and power calculations through a Model Context Protocol interface.
    5
    1
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides file reading and mathematical calculation tools through the Model Context Protocol. Enables reading file contents and evaluating mathematical expressions via stdio transport.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides basic arithmetic operations (add, multiply, divide) for AI assistants through the Model Context Protocol.
    -