MCP Telegram 通讯器
一种通过 Telegram 与用户进行通信的 MCP 服务器。该服务器提供了一种通过 Telegram 机器人向用户提问并接收其回复的工具。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"mcp-communicator-telegram": {
"args": [
"path/to/mcp-communicator-telegram/build/index.js"
],
"command": "node",
"env": {
"CHAT_ID": "your_chat_id_here",
"TELEGRAM_TOKEN": "your_bot_token_here"
}
}
}
}
该服务需要配置环境变量:CHAT_ID、TELEGRAM_TOKEN
服务介绍
MCP 通信器 (Telegram)
一个通过 Telegram 与用户进行通信的 MCP 服务器。该服务器提供了通过 Telegram 机器人与用户交互的工具,包括提问、发送通知、分享文件和创建项目归档。
安装
通过 npm (全局)
npm install -g mcp-communicator-telegram
通过 npx (按需)
npx mcptelegram
获取您的 Telegram 聊天 ID:
npx mcptelegram-chatid
功能
- 通过 Telegram 向用户提问
- 发送通知给用户(无需回复)
- 通过 Telegram 向用户发送文件
- 创建并发送项目压缩文件(尊重 .gitignore)
- 异步接收响应(无限期等待响应)
- 支持基于回复的消息跟踪
- 安全的聊天 ID 验证
- 错误处理和日志记录
前提条件
- Node.js (v14 或更高版本)
- Telegram 机器人令牌(从 @BotFather 获取)
- 您的 Telegram 聊天 ID(可以使用附带的实用程序获取)
安装
- 克隆仓库:
git clone https://github.com/qpd-v/mcp-communicator-telegram.git
cd mcp-communicator-telegram
- 安装依赖项:
npm install
-
创建 Telegram 机器人:
- 打开 Telegram 并搜索 @BotFather
- 发送
/newbot并按照指示操作 - 保存您收到的机器人令牌
-
获取您的聊天 ID:
- 复制
.env.example到.env - 将您的机器人令牌添加到
.env文件中:TELEGRAM_TOKEN=your_bot_token_here - 运行聊天 ID 实用程序:
npm run build node build/get-chat-id.js - 向您的机器人发送任何消息
- 复制控制台中显示的聊天 ID
- 将聊天 ID 添加到您的
.env文件中:TELEGRAM_TOKEN=your_bot_token_here CHAT_ID=your_chat_id_here
- 复制
配置
将服务器添加到您的 MCP 设置文件中(通常位于 Windows 上的 %APPDATA%\Code\User\globalStorage\rooveterinaryinc.roo-cline\settings\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",
"CHAT_ID": "your_chat_id_here"
}
}
}
}
可用工具
ask_user
通过 Telegram 向用户提问并等待其回复。
输入模式:
{
"type": "object",
"properties": {
"question": {
"type": "string",
"description": "The question to ask the user"
}
},
"required": ["question"]
}
示例用法:
const response = await use_mcp_tool({
server_name: "mcp-communicator-telegram",
tool_name: "ask_user",
arguments: {
question: "What is your favorite color?"
}
});
notify_user
通过 Telegram 向用户发送通知消息(无需回复)。
输入模式:
{
"type": "object",
"properties": {
"message": {
"type": "string",
"description": "The message to send to the user"
}
},
"required": ["message"]
}
示例用法:
await use_mcp_tool({
server_name: "mcp-communicator-telegram",
tool_name: "notify_user",
arguments: {
message: "Task completed successfully!"
}
});
send_file
通过 Telegram 向用户发送文件。
输入模式:
{
"type": "object",
"properties": {
"filePath": {
"type": "string",
"description": "The path to the file to send"
}
},
"required": ["filePath"]
}
示例用法:
await use_mcp_tool({
server_name: "mcp-communicator-telegram",
tool_name: "send_file",
arguments: {
filePath: "path/to/file.txt"
}
});
zip_project
创建一个项目目录的压缩文件(尊重 .gitignore 模式),并通过 Telegram 发送给用户。
输入模式:
{
"type": "object",
"properties": {
"directory": {
"type": "string",
"description": "Directory to zip (defaults to current working directory)"
}
},
"required": []
}
使用默认目录(当前工作目录)的示例用法:
await use_mcp_tool({
server_name: "mcp-communicator-telegram",
tool_name: "zip_project",
arguments: {}
});
指定目录的示例用法:
await use_mcp_tool({
server_name: "mcp-communicator-telegram",
tool_name: "zip_project",
arguments: {
directory: "/path/to/your/project"
}
});
功能:
- 根据目录名称创建名为
[project-name]-project.zip的压缩文件 - 可以压缩任何指定的目录或当前工作目录
- 尊重 .gitignore 模式
- 在归档中保持正确的文件路径
- 自动在发送后清理压缩文件
- 支持最大 2GB 的文件
开发
构建项目:
npm run build
以开发模式运行:
npm run dev
监视文件变化:
npm run watch
清理构建目录:
npm run clean
安全性
- 服务器仅响应来自已配置聊天ID的消息
- 敏感配置使用环境变量
- 使用消息ID来跟踪问题/答案对
- 机器人忽略没有适当上下文的消息
许可证
ISC
作者
qpd-v
版本
0.2.1 # 因新增功能进行主版本升级:notify_user, send_file, 和 zip_project 工具