npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

demo-calculator-mcp-server

v1.0.1

Published

MCP服务器实现的简单计算器

Readme

Calculator MCP Server

这是一个基于MCP SDK的计算器服务器实现,可以执行基本的数学计算。

功能

  • 支持基本数学表达式计算(加减乘除和括号)
  • 支持单独的加、减、乘、除操作
  • 可用作MCP服务器提供给大语言模型调用

安装

npm install calculator-mcp-server

使用方法

作为HTTP服务器运行

import express from 'express';
import { randomUUID } from 'node:crypto';
import { createCalculatorServer, StreamableHTTPServerTransport } from 'calculator-mcp-server';

const app = express();
app.use(express.json());

// 创建计算器服务器
const server = createCalculatorServer({
  name: 'calculator-server',
  version: '1.0.0',
  logging: true
});

// 处理MCP请求
app.all('/mcp', async (req, res) => {
  try {
    const transport = new StreamableHTTPServerTransport({
      sessionIdGenerator: () => randomUUID(),
    });
    
    await server.connect(transport);
    await transport.handleRequest(req, res, req.body);
  } catch (error) {
    console.error("处理请求时出错:", error);
    if (!res.headersSent) {
      res.status(500).json({
        jsonrpc: "2.0",
        error: {
          code: -32603,
          message: "内部服务器错误",
        },
        id: null,
      });
    }
  }
});

const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
  console.log(`计算器MCP服务器运行在端口 ${PORT}`);
});

在标准输入/输出中使用

import { createCalculatorServer, StdioServerTransport } from 'calculator-mcp-server';

async function main() {
  const server = createCalculatorServer();
  const transport = new StdioServerTransport();
  
  await server.connect(transport);
  console.error("计算器MCP服务器已启动,通过stdin/stdout通信");
}

main().catch(console.error);

可用工具

服务器提供以下工具:

  1. calculate:计算任意数学表达式

    • 参数:
      • expression:要计算的数学表达式,如 "2+2" 或 "5*(3+1)"
  2. perform-operation:执行特定类型的数学运算

    • 参数:
      • operation:操作类型("add", "subtract", "multiply", "divide")
      • a:第一个数字
      • b:第二个数字

许可

ISC