MCP计算服务器

一个基于MCP协议的计算服务器,提供基本的数学运算功能,适用于实验和开发场景。

  • by gfidente
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 gfidente/mcp-server

使用说明

这是什么?

这是我尝试编写一个基本的MCP服务器来尝试使用 主控程序 LLMs。

此服务器是使用编写的 FastMCP 并将一些基本的数学函数导出为工具供消费。

它是如何工作的?

显示可用功能的典型对流如下:

Query: hello there, I am Giulio. What can you do for me?
Answer:

Hello Giulio! I'm an AI, and I can help with a variety of tasks using the functions you've provided as a calculator. Here are some things I can do:

 1 Addition: calculator.add(a, b) - This will return the sum of numbers 'a' and 'b'.
 2 Subtraction: calculator.subtract(a, b) - This will return the difference between 'a' and 'b'.
 3 Multiplication: calculator.multiply(a, b) - This will return the product of 'a' and 'b'.
 4 Division: calculator.divide(a, b) - This will return the quotient of 'a' divided by 'b', provided that 'b' is not zero.
 5 Exponentiation: calculator.power(a, b) - This will return 'a' raised to the power of 'b'.
 6 Remainder: calculator.remainder(a, b) - This will return the remainder when 'a' is divided by 'b'.

Please provide me with the numbers and operation you'd like to perform, using these function names along with their respective parameters.

Query: Great, can you calculate the power of 4 by 4?
Answer:

Absolutely! Using the calculator.power function:


 calculator.power(4, 4)


The result is 256. This is because 4 raised to the power of 4 equals 256.

如何尝试和测试它?

我的方法是使用IBM的granite3.1密集模型来尝试这一点,该模型旨在支持基于工具的用例。例如,要使用ollama运行granite3.1-density并将其与calculator.py MCP服务器连接:

  1. 按照以下步骤安装OLAMAhttps://github.com/ollama/ollama/blob/main/docs/linux.md

  2. 启动ollama服务:

ollama serve
  1. 拉动模型:
ollama pull granite3.1-dense:2b
  1. 在虚拟环境中下载并安装MCP服务器及其依赖项:
git clone https://github.com/gfidente/mcp-server.git
cd mcp-server
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
  1. 同时安装 用于ollama的MCP客户端库:
pip install ollmcp
  1. 启动服务器并开始与LLM交互:
ollmcp --mcp-server calculator.py --model granite3.1-dense:2b