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

mcp-chatbot-server-leo

v1.0.1

Published

这是一个两数相加的mcp服务

Readme

项目初始化

https://docs.mcpservers.cn/quickstart/server#node

npm init -y
cnpm install @modelcontextprotocol/sdk [email protected]
cnpm install -D @types/node typescript

调试项目

 npx @modelcontextprotocol/inspector node ./build/index.js

src/index.ts

/**
 * 新手版 MCP 计算器服务器
 * 
 * 这是一个简化的MCP服务器示例,适合初学者学习
 * 提供基本的加减乘除运算功能
 * 
 * 安装依赖:
 * npm install @modelcontextprotocol/sdk zod
 * 
 * 编译运行:
 * npx tsc
 * node build/server/index.js
 */
 
// 导入需要的模块
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
 
// 创建服务器
const server = new McpServer({
  name: "simple-calculator",
  version: "1.0.0",
  capabilities: {
    resources: {},
    tools: {},
  },
});
 
// 定义数字验证规则
const NumberSchema = z.number().describe("数字");
 
// 加法工具
server.tool(
  "add",
  "计算两个数字相加",
  {
    a: NumberSchema,
    b: NumberSchema,
  },
  async ({ a, b }) => {
    const result = a + b;
    
    return {
      content: [
        {
          type: "text",
          text: `${a} + ${b} = ${result}`,
        },
      ],
    };
  }
);
 
// 减法工具
server.tool(
  "subtract",
  "计算两个数字相减",
  {
    a: NumberSchema,
    b: NumberSchema,
  },
  async ({ a, b }) => {
    const result = a - b;
    
    return {
      content: [
        {
          type: "text",
          text: `${a} - ${b} = ${result}`,
        },
      ],
    };
  }
);
 
// 乘法工具
server.tool(
  "multiply",
  "计算两个数字相乘",
  {
    a: NumberSchema,
    b: NumberSchema,
  },
  async ({ a, b }) => {
    const result = a * b;
    
    return {
      content: [
        {
          type: "text",
          text: `${a} × ${b} = ${result}`,
        },
      ],
    };
  }
);
 
// 除法工具
server.tool(
  "divide",
  "计算两个数字相除",
  {
    a: NumberSchema,
    b: NumberSchema,
  },
  async ({ a, b }) => {
    // 检查除数是否为零
    if (b === 0) {
      return {
        content: [
          {
            type: "text",
            text: "错误:不能除以零",
          },
        ],
      };
    }
    
    const result = a / b;
    
    return {
      content: [
        {
          type: "text",
          text: `${a} ÷ ${b} = ${result}`,
        },
      ],
    };
  }
);
 
// 启动服务器
async function main() {
  try {
    const transport = new StdioServerTransport();
    await server.connect(transport);
    console.error("计算器服务器已启动");
  } catch (error) {
    console.error("启动失败:", error);
    process.exit(1);
  }
}
 
main().catch((error) => {
  console.error("运行出错:", error);
  process.exit(1);
});
 
/*
使用方法:
1. 安装依赖包
   npm install @modelcontextprotocol/sdk zod
2. 编译 TypeScript
   npx tsc
3. 在 VS Code 中配置 .vscode/mcp.json:
   {
     "servers": {
       "calculator": {
         "type": "stdio",
         "command": "node",
         "args": ["你的绝对路径/server/index.js"]
       }
     }
   }
4. 重启 VS Code,然后就可以使用计算功能了
代码说明:
- McpServer: 创建 MCP 服务器
- server.tool(): 定义可用的工具/功能
- NumberSchema: 验证输入必须是数字
- async/await: 处理异步操作
- StdioServerTransport: 使用标准输入输出通信
每个工具包含:
- 名称 (如 "add")
- 描述 (如 "计算两个数字相加")
- 参数定义 (如 {a: NumberSchema, b: NumberSchema})
- 实现函数 (执行具体的计算逻辑)
*/
 

生成js文件并运行

执行如下代码编译ts文件为js文件,默认生成在同一路径

这将会将当前项目下的所有ts代码转换为js

npx tsc

使用inspector 启动客户端,并指定服务端代码路径

npx @modelcontextprotocol/inspector node ./build/index.js

结果

这样就可以在UI界面尽情测试了

MCP ChatBot项目

能够实现MCP调用的对话机器人

接口梳理

  • 创建MCP Server
  • 删除MCP Server
  • 更新MCP Server
  • 查询 MCP Server列表
  • 查询 MCP Server的详情
  • 刷新MCP Server的在线状态(相当于重新连接MCP Server)
  • 启用/停用MCP Server(让大模型更加精准的找到需要调用的函数)
  • 查询MCP Server的tools列表
  • 调用MCP Server的tool

安装库