返回 MCP 目录
public公开dns本地运行

calculator

一个基于MCP框架的计算器服务项目,提供工具开发模板和快速启动指南,支持通过npm发布并与Claude桌面客户端集成。

article

README

🚀 计算器

这是一个使用 mcp-framework 构建的模型上下文协议(MCP)服务器,可用于执行各类计算任务,为用户提供便捷的计算服务。

🚀 快速开始

# 安装依赖
npm install

# 构建项目
npm run build

📁 项目结构

calculator/
├── src/
│   ├── tools/        # MCP 工具
│   │   └── ExampleTool.ts
│   └── index.ts      # 服务器入口文件
├── package.json
└── tsconfig.json

➕ 添加组件

项目在 src/tools/ExampleTool.ts 中附带了一个示例工具。你可以使用 CLI 添加更多工具:

# 添加一个新的工具
mcp add tool my-tool

# 例如,你可以创建以下工具:
mcp add tool data-processor
mcp add tool api-client
mcp add tool file-handler

💻 使用示例

基础用法

示例工具结构:

import { MCPTool } from "mcp-framework";
import { z } from "zod";

interface MyToolInput {
  message: string;
}

class MyTool extends MCPTool<MyToolInput> {
  name = "my_tool";
  description = "描述你的工具的功能";

  schema = {
    message: {
      type: z.string(),
      description: "此输入参数的描述",
    },
  };

  async execute(input: MyToolInput) {
    // 你的工具逻辑在这里
    return `处理后:${input.message}`;
  }
}

export default MyTool;

📦 发布到 npm

  1. 更新 package.json:

    • 确保 name 唯一且符合 npm 命名规范
    • 设置适当的 version
    • 添加 descriptionauthorlicense 等信息
    • 检查 bin 是否指向正确的入口文件
  2. 本地构建和测试:

    npm run build
    npm link
    calculator  # 在本地测试你的 CLI
    
  3. 登录到 npm(如果需要创建账户):

    npm login
    
  4. 发布你的包:

    npm publish
    

发布后,用户可以通过以下方式使用:

npx calculator

🤝 与 Claude Desktop 结合使用

通过 Smithery 安装

要通过 Smithery 自动安装计算器到 Claude 桌面客户端:

npx -y @smithery/cli install @QuantGeekDev/mcp-add-sse --client claude

本地开发

在你的 Claude Desktop 配置文件中添加以下内容:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "calculator": {
      "command": "node",
      "args":["/绝对路径/to/calculator/dist/index.js"]
    }
  }
}

发布后

在你的 Claude Desktop 配置文件中添加以下内容:

MacOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "calculator": {
      "command": "npx",
      "args": ["calculator"]
    }
  }
}

🔨 构建和测试

  1. 修改你的工具代码
  2. 运行 npm run build 进行构建
  3. 服务器启动后会自动加载你的工具
help

运行方式说明

cloud

托管运行

托管运行通常表示这个 MCP Server 由服务方环境承载,用户一般按页面提供的连接方式或授权流程接入,不需要在本地长期启动一个 MCP 进程

  1. 打开服务方连接页
  2. 完成授权或复制端点
  3. 在 MCP 客户端中连接
terminal

本地运行 / 其它方式

本地运行通常需要用户在自己的电脑或服务器上安装依赖,把 server_config 复制到 MCP 客户端,并按 env_schema 补齐环境变量、密钥或其它配置

  1. 复制 server_config
  2. 安装所需依赖
  3. 补齐环境变量后重启客户端