MCP Calculator Server

MCP Calculator Server

Provides basic and advanced mathematical operations including addition, subtraction, multiplication, division, power, square root, and factorial calculations through an SSE-based MCP interface.

Category
Visit Server

README

MCP 计算器服务器

一个基于 SSE (Server-Sent Events) 的 Model Context Protocol 计算器服务器,运行在 8000 端口。

功能特性

✨ 支持的计算操作:

  • 加法 (add): 计算两个数的和
  • 减法 (subtract): 计算两个数的差
  • ✖️ 乘法 (multiply): 计算两个数的积
  • 除法 (divide): 计算两个数的商
  • 🔢 幂运算 (power): 计算 a 的 b 次方
  • 平方根 (sqrt): 计算一个数的平方根
  • 🎯 阶乘 (factorial): 计算非负整数的阶乘
  • 👤 启动者信息 (get_operator_info): 查看服务器启动者和配置信息

🔒 安全特性

  • 必须设置启动者姓名才能启动服务器
  • 环境变量验证,确保配置正确

技术栈

  • 🚀 Node.js + TypeScript
  • 📡 SSE (Server-Sent Events) 传输协议
  • 🌐 Express 作为 HTTP 服务器
  • 🔧 MCP SDK (@modelcontextprotocol/sdk)

安装

# 安装依赖
npm install

# 构建项目
npm run build

配置

⚠️ 必须设置环境变量才能启动服务器!

创建 .env 文件:

cp .env.example .env

编辑 .env 文件,设置启动者姓名:

# 启动者姓名(必需)
OPERATOR_NAME=张三

# 服务器端口
PORT=8000

# Node 环境
NODE_ENV=development

运行

# 启动服务器
npm start

# 或者直接在命令行设置环境变量
OPERATOR_NAME=张三 npm start

# 开发模式(自动重新构建)
npm run dev

服务器将运行在 http://localhost:8000

API 端点

健康检查

GET http://localhost:8000/health

返回服务器状态信息。

SSE 连接

GET http://localhost:8000/sse

建立 SSE 连接,用于 MCP 通信。

使用示例

连接到服务器

// 客户端连接示例
const eventSource = new EventSource('http://localhost:8000/sse');

eventSource.onmessage = (event) => {
  console.log('收到消息:', event.data);
};

可用工具

  1. 加法运算

    {
      "name": "add",
      "arguments": {
        "a": 10,
        "b": 5
      }
    }
    

    返回: 10 + 5 = 15

  2. 减法运算

    {
      "name": "subtract",
      "arguments": {
        "a": 10,
        "b": 5
      }
    }
    

    返回: 10 - 5 = 5

  3. 乘法运算

    {
      "name": "multiply",
      "arguments": {
        "a": 10,
        "b": 5
      }
    }
    

    返回: 10 × 5 = 50

  4. 除法运算

    {
      "name": "divide",
      "arguments": {
        "a": 10,
        "b": 5
      }
    }
    

    返回: 10 ÷ 5 = 2

  5. 幂运算

    {
      "name": "power",
      "arguments": {
        "a": 2,
        "b": 3
      }
    }
    

    返回: 2^3 = 8

  6. 平方根

    {
      "name": "sqrt",
      "arguments": {
        "a": 16
      }
    }
    

    返回: √16 = 4

  7. 阶乘

    {
      "name": "factorial",
      "arguments": {
        "n": 5
      }
    }
    

    返回: 5! = 120

  8. 获取启动者信息

    {
      "name": "get_operator_info",
      "arguments": {}
    }
    

    返回服务器信息,包括启动者姓名、版本、端口等

项目结构

mcp-calculator/
├── src/
│   └── index.ts          # 主服务器文件
├── dist/                  # 编译输出目录
├── package.json
├── tsconfig.json
├── .env.example
├── .gitignore
└── README.md

开发

# 监听文件变化,自动重新编译
npm run watch

# 在另一个终端运行
npm start

许可证

MIT

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
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

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