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
-
更新 package.json:
- 确保
name唯一且符合 npm 命名规范 - 设置适当的
version - 添加
description、author、license等信息 - 检查
bin是否指向正确的入口文件
- 确保
-
本地构建和测试:
npm run build npm link calculator # 在本地测试你的 CLI -
登录到 npm(如果需要创建账户):
npm login -
发布你的包:
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"]
}
}
}
🔨 构建和测试
- 修改你的工具代码
- 运行
npm run build进行构建 - 服务器启动后会自动加载你的工具
微信扫一扫