使用说明
计算器MCP服务器
一种模型上下文协议(MCP)服务器,为数学运算提供计算器工具。
特性
计算器服务器提供以下工具:
- 添加:将两个或多个数字相加
- 减去:减去数字(从第一个数字中减去所有后续数字)
- 乘:将两个或多个数字相乘
- 分割:除以数字(将第一个数字除以所有后续数字)
- 力量:将数字提高到幂
- 平方根:计算一个数字的平方根
- 评估:安全地计算数学表达式(支持基本的数学运算和函数)
安装
- 安装所需的依赖项:
pip install -r requirements.txt
或直接安装:
pip install mcp
用法
运行服务器:
python calculator_server.py
服务器通过stdio进行通信,并遵循MCP协议。
配置
要将此服务器与MCP客户端一起使用,请将以下内容添加到MCP客户端配置中:
{
"mcpServers": {
"calculator": {
"command": "python",
"args": ["/path/to/calculator_server.py"],
"transport": "stdio"
}
}
}
或者,如果你在同一个目录中:
{
"mcpServers": {
"calculator": {
"command": "python",
"args": ["calculator_server.py"],
"transport": "stdio"
}
}
}
示例工具
添加
{
"name": "add",
"arguments": {
"numbers": [1, 2, 3, 4]
}
}
结果:10
减去
{
"name": "subtract",
"arguments": {
"numbers": [100, 20, 5]
}
}
结果:75
乘
{
"name": "multiply",
"arguments": {
"numbers": [2, 3, 4]
}
}
结果:24
分割
{
"name": "divide",
"arguments": {
"numbers": [100, 5, 2]
}
}
结果:10.0
力量
{
"name": "power",
"arguments": {
"base": 2,
"exponent": 8
}
}
结果:256
平方根
{
"name": "sqrt",
"arguments": {
"number": 16
}
}
结果:4.0
计算表达式
{
"name": "evaluate",
"arguments": {
"expression": "2 + 2 * 3"
}
}
结果:8
评估工具还支持以下数学函数 sin, cos, tan, sqrt, log, exp, pi, e等等。
安全
这 evaluate 该工具使用Python compile() 和 eval() 为了安全起见,使用受限命名空间的函数。只允许使用基本的数学运算和函数。
许可证
此项目按原样提供,用于模型上下文协议。
