使用说明
项目简介
'mcp-communicator-telegram' 是一个MCP服务器,它允许大型语言模型(LLM)通过Telegram与用户进行交互。该服务器提供了一个工具,可以向Telegram用户发送问题并异步接收他们的回复,从而扩展了LLM与外部环境互动的能力。
主要功能点
- 提问用户: 允许LLM通过Telegram Bot向指定用户发送问题。
- 异步接收回复: 服务器能够等待用户在Telegram上的回复,并将回复内容返回给LLM客户端,实现异步的用户交互。
- Chat ID验证: 仅处理来自预先配置的Telegram Chat ID的消息,增强了安全性和定向交互能力。
- 工具集成: 提供 'ask_user' 工具,方便LLM客户端调用以发起用户提问。
安装步骤
- 安装 Node.js: 确保你的系统已安装 Node.js (v14 或更高版本) 和 npm。
- 克隆仓库: 从 GitHub 克隆仓库到本地:
git clone https://github.com/MCP-Mirror/qpd-v_mcp-communicator-telegram.git - 进入目录: 进入项目目录:
cd qpd-v_mcp-communicator-telegram - 安装依赖: 安装项目所需的 npm 依赖包:
npm install - 创建 Telegram Bot:
- 在 Telegram 中搜索 '@BotFather' 并按照指示创建一个新的 Bot。
- 复制 BotFather 提供的 Bot Token。
- 获取 Chat ID:
- 复制 '.env.example' 文件并重命名为 '.env'。
- 在 '.env' 文件中,将你的 Bot Token 填入 'TELEGRAM_TOKEN' 变量。
- 运行获取 Chat ID 的工具:
npm run build node build/get-chat-id.js - 向你的 Telegram Bot 发送任意消息。
- 在控制台中复制输出的 Chat ID,并将其填入 '.env' 文件的 'CHAT_ID' 变量。
- 构建项目: 编译 TypeScript 代码:
npm run build
服务器配置
为了让 MCP 客户端能够连接到 'mcp-communicator-telegram' 服务器,需要在 MCP 客户端的服务器配置文件中添加以下配置信息。通常,这个文件名为 'cline_mcp_settings.json',位于用户配置目录下。
{ "mcpServers": { "mcp-communicator-telegram": { "command": "node", "args": ["path/to/mcp-communicator-telegram/build/index.js"], "env": { "TELEGRAM_TOKEN": "your_bot_token_here", // 替换为你的 Telegram Bot Token "CHAT_ID": "your_chat_id_here" // 替换为你的 Telegram Chat ID } } } }
请务必将 'your_bot_token_here' 替换为你从 BotFather 获取的 Telegram Bot Token,'your_chat_id_here' 替换为你通过 'get-chat-id.js' 工具获取的 Chat ID。
基本使用方法
配置完成后,MCP 客户端即可通过 'mcp-communicator-telegram' 服务器提供的 'ask_user' 工具与 Telegram 用户进行交互。客户端可以使用如下方式调用该工具:
const response = await use_mcp_tool({ server_name: "mcp-communicator-telegram", tool_name: "ask_user", arguments: { question: "你想问用户的问题" } }); console.log("用户回复:", response.content[0].text);
这段代码示例展示了如何通过 'use_mcp_tool' 函数调用 'ask_user' 工具,向 Telegram 用户提问,并将用户的回复打印到控制台。实际使用中,你需要根据你的 MCP 客户端的具体 API 和使用方式进行调用。
信息
分类
通信与社交