计算器MCP服务器
使用与构建的模型上下文协议(MCP)的简单计算器实现。NET 9和MCPSharp。
 
特性
此MCP服务器提供以下计算器工具:
- 添加:将两个数字相加
- 减去:从第一个数字中减去第二个数字
- 乘:将两个数字相乘
- 分割:将第一个数字除以第二个数字(具有除零保护)
- 正方形:将一个数字平方
安装
选项1:下载预构建的二进制文件
从以下网址下载适用于您平台的最新版本 发布页面:
- 视窗:
CalculatorMcpServer-win-x64.zip或CalculatorMcpServer-win-arm64.zip - Linux:
CalculatorMcpServer-linux-x64.tar.gz或CalculatorMcpServer-linux-arm64.tar.gz - macOS:
CalculatorMcpServer-osx-x64.tar.gz或CalculatorMcpServer-osx-arm64.tar.gz
解压缩存档并直接运行可执行文件-否。NET运行时安装是必需的!
选项2:Docker容器
拉取并运行最新的Docker镜像:
# Pull from GitHub Container Registry
docker pull ghcr.io/jamesburton/calculatormcpserver:latest
# Run the container
docker run -it ghcr.io/jamesburton/calculatormcpserver:latest选项3:从源代码构建
要求:
- .NET 9.0 SDK或更高版本
git clone https://github.com/jamesburton/CalculatorMcpServer.git
cd CalculatorMcpServer
dotnet build --configuration Release
dotnet run --project CalculatorMcpServer用法
基本用法
运行计算器MCP服务器:
# From extracted binary
./CalculatorMcpServer
# From Docker
docker run -it ghcr.io/jamesburton/calculatormcpserver:latest
# From source
dotnet run --project CalculatorMcpServer服务器将启动并监听MCP连接。您将看到:
Calculator MCP Server is running. Press Enter to exit.MCP客户端集成
Claude桌面配置
将以下内容添加到您的Claude Desktop配置文件中:
视窗: %APPDATA%\Claude\claude_desktop_config.json macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"calculator": {
"command": "/path/to/CalculatorMcpServer",
"args": []
}
}
}替换 /path/to/CalculatorMcpServer 带有可执行文件的实际路径。
Docker集成
{
"mcpServers": {
"calculator": {
"command": "docker",
"args": ["run", "-i", "ghcr.io/jamesburton/calculatormcpserver:latest"]
}
}
}可用工具
连接后,您可以使用以下计算器功能:
- 添加(a,b) -加两个数字
add(5, 3) → 8- 减去(a,b) -从a中减去b
subtract(10, 4) → 6- 乘(a,b) -将两个数字相乘
multiply(6, 7) → 42- 分割(a,b) -将a除以b
divide(15, 3) → 5.0- 正方形(a) -将一个数字平方
square(4) → 16发展
项目结构
CalculatorMcpServer/
├── CalculatorMcpServer/ # Main project
│ ├── Calculator.cs # Calculator implementation
│ ├── Program.cs # Entry point
│ └── CalculatorMcpServer.csproj
├── CalculatorMcpServer.Tests/ # Unit tests
│ ├── CalculatorTests.cs # Test cases
│ └── CalculatorMcpServer.Tests.csproj
├── .github/workflows/ # CI/CD pipelines
├── Dockerfile # Container definition
└── README.md # This file建筑
# Build the solution
dotnet build
# Run tests
dotnet test
# Create a release build
dotnet publish --configuration Release --runtime win-x64 --self-contained测试
该项目包括全面的单元测试:
# Run all tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"Docker开发
# Build the Docker image
docker build -t calculator-mcp-server .
# Run the container
docker run -it calculator-mcp-server与跨平台支持
该项目支持以下平台:
- 视窗:x64,ARM64
- Linux:x64,ARM64
- macOS:x64,ARM64(苹果硅)
所有构建都可以作为不需要的自包含可执行文件提供。NET运行时安装。
CI/CD管道
该项目使用GitHub Actions进行自动化:
- 测试:对每个推送和PR运行单元测试
- 跨平台构建:为所有支持的平台创建二进制文件
- Docker构建:多架构容器映像(AMD64、ARM64)
- 发布:在版本标签上自动发布二进制文件和容器映像
集装箱登记处
Docker镜像发布到GitHub容器注册表:
ghcr.io/jamesburton/calculatormcpserver:latest-主分行最新消息ghcr.io/jamesburton/calculatormcpserver:v1.0.0-特定版本标签
备注:CI/CD管道使用内置 GITHUB_TOKEN 用于GitHub容器注册表的身份验证。
贡献
- 分叉存储库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
请确保您的代码:
- 包括适当的单元测试
- 遵循现有代码样式
- 有明确的提交消息
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
依赖项
支持
- 问题:
- 讨论:
更新日志
看 更改日志.md 查看版本历史和更改。
