Provides basic arithmetic operations and advanced mathematical functions through the Model Context Protocol (MCP), with features like calculation history tracking and expression evaluation.
这是一个使用 Model Context Protocol (MCP) 开发的计算器服务器,提供基本的算术运算功能。
pip install -r requirements.txt
python calculator_server.py
或者使用 MCP 命令:
mcp run calculator_server.py
python advanced_calculator_server.py
python calculator_client.py
add(a, b)
: 计算 a + bsubtract(a, b)
: 计算 a - bmultiply(a, b)
: 计算 a * bdivide(a, b)
: 计算 a / bpower(base, exponent)
: 计算 base 的 exponent 次幂sqrt(value)
: 计算平方根evaluate_expression(expression)
: 计算数学表达式字符串calculator://help
: 获取帮助信息calculator://history
: 获取计算历史记录from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client import asyncio async def main(): server_params = StdioServerParameters( command="python", args=["advanced_calculator_server.py"], ) async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: await session.initialize() # 调用加法工具 result = await session.call_tool("add", {"a": 5, "b": 3}) print(f"5 + 3 = {result}") # 读取计算历史 history, _ = await session.read_resource("calculator://history") print(history) if __name__ == "__main__": asyncio.run(main())
calculator_server.py
: 基本计算器 MCP 服务器advanced_calculator_server.py
: 高级计算器 MCP 服务器,带有更多功能calculator_client.py
: 计算器客户端示例requirements.txt
: 项目依赖README.md
: 项目文档你可以通过以下方式扩展这个计算器服务器:
MIT 许可证
Discover shared experiences
Shared threads will appear here, showcasing real-world applications and insights from the community. Check back soon for updates!