MCP Calculator 计算器服务器
这是一个基于MCP (Model Context Protocol) 官方SDK的计算器演示项目,采用模块化架构设计。
项目特点
模块化架构: 每个功能模块独立成文件,便于维护和扩展
MCP规范: 完全符合MCP官方SDK规范
中文支持: 提供中文界面和错误提示
资源模板: 支持动态URI资源访问
错误处理: 完善的错误处理和用户提示
项目结构
功能模块
1. 计算器工具 (calculate)
支持加法、减法、乘法、除法
完善的错误处理(如除零检查)
中文运算符号显示
2. 配置资源 (config://calculator)
服务器基本信息
支持的功能列表
资源模板说明
3. 历史记录资源 (history://{operation}/{a}/{b})
动态URI模板
运算历史示例
运算技巧提示
4. 帮助资源 (help://resource-templates)
Resource Template使用说明
详细的使用示例
5. 小数计算提示词 (decimal-calc)
支持指定小数位数
详细的计算步骤指导
使用方法
启动服务器
在MCP Inspector中测试
启动MCP Inspector
连接到计算器服务器
测试各种工具和资源
模块化设计优势
可维护性: 每个功能独立,修改不影响其他模块
可扩展性: 新增功能只需添加新模块,无需修改现有代码
可测试性: 每个模块可以独立测试
代码复用: 工具方法可以在多个模块间共享
团队协作: 不同开发者可以并行开发不同模块
开发指南
添加新工具
在
tools/目录下创建新文件定义工具配置和处理函数
在
registrar.js中注册新工具
添加新资源
在
resources/目录下创建新文件定义资源配置和处理函数
在
registrar.js中注册新资源
添加新提示词
在
prompts/目录下创建新文件定义提示词配置和处理函数
在
registrar.js中注册新提示词
依赖项
@modelcontextprotocol/sdk: MCP官方SDKzod: 数据验证库
许可证
MIT License
This server cannot be installed
Related Resources
Related MCP Servers
- AsecurityFlicenseAqualityA numerical calculator based on Model Context Protocol (MCP) that provides simple arithmetic operations including addition, subtraction, multiplication, division, power, square root and integer factorial calculations.Last updated -71
- -security-license-qualityA calculator server that exposes mathematical functions as tools (add, subtract, multiply, divide, square, power, square root), enabling language models to perform calculations through Model Context Protocol (MCP).Last updated -
- -security-license-qualityA server that provides basic mathematical operations (addition, subtraction, multiplication, division, power, square root) through MCP tools for use with AI assistants like Claude.
- -securityFlicense-qualityA simple calculator MCP server that provides basic arithmetic functions (add and subtract) through HTTP transport, designed to be cloud-ready and easily deployable.Last updated -