Back to MCP directory
publicPublicdnsLocal runtime

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

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client