LLM工具调用助手

通过MCP协议将本地LLM连接到现实世界的工具、知识库和API,实现自动化工具调用和知识查询。

  • by o6-webwork
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 o6-webwork/mcp-template

使用说明

🧠 LLM Tool-Calling Assistant with MCP Integration

Connect your local LLM to real-world tools, knowledge bases, and APIs via MCP.

该项目通过以下方式将本地LLM(如Qwen)连接到计算器或知识库等工具 主控程序 协议。助手会自动检测并调用这些工具来帮助回答用户查询。


📦 特性

  • 🔧 通过MCP服务器执行工具
  • 🧠 通过HTTP或OpenAI SDK进行本地LLM集成
  • 📚 知识库支持(data.json)
  • ⚡ 支持 stdio 和 sse 运输

🗂 项目文件

文件 描述
server.py 注册工具并启动MCP服务器
client-http.py 用途 aiohttp 与当地LLM沟通
clientopenai.py 使用OpenAI兼容的SDK进行LLM+工具调用逻辑
client-stdio.py 使用stdio的MCP客户端
client-see.py 使用SSE的MCP客户端
data.json 问答知识库

📥 安装

需求

Python 3.8+

安装依赖项:

pip install -r requirements.txt

requirements.txt

aiohttp==3.11.18
nest_asyncio==1.6.0
python-dotenv==1.1.0
openai==1.77.0
mcp==1.6.0

🚀 入门指南

1.运行MCP服务器

python server.py

这将启动您的工具服务器,其功能如下 add, multiply,以及 get_knowledge_base.

2.启动客户端

选项A:HTTP客户端(通过原始API的本地LLM)

python client-http.py

选项B:OpenAI SDK客户端

python client-openai.py

选项C:stdio传输

python client-stdio.py

选项D:SSE运输

确保 server.py 设置:

transport = "sse"

然后运行:

python client-sse.py

💬 示例提示

数学工具调用

What is 8 times 3?

答复:

Eight times three is 24.

知识库问题

What are the healthcare benefits available to employees in Singapore?

回复将包括以下相关答案 data.json.


📁 例子: data.json

[
  {
    "question": "What is Singapore's public holiday schedule?",
    "answer": "Singapore observes several public holidays..."
  },
  {
    "question": "How do I apply for permanent residency in Singapore?",
    "answer": "Submit an online application via the ICA website..."
  }
]

🔧 配置

内部 client-http.py 或 clientopenai.py,更新以下内容:

LOCAL_LLM_URL = "..."
TOKEN = "your-api-token"
LOCAL_LLM_MODEL = "your-model"

请确保您的LLM正在为兼容OpenAI的API终结点提供服务。


🧹 清理

客户端自动处理工具调用和响应。您可以使用以下命令停止服务器或客户端 Ctrl+C.


🪪 许可证

MIT许可证。看 许可证 文件。