首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页
学习
活动
专区
圈层
工具
MCP广场
MCP广场 >详情页
mcp-communicator-telegram2025-05-290分享
github
一种通过 Telegram 与用户进行通信的 MCP 服务器。该服务器提供了一种通过 Telegram 机器人向用户提问并接收其回复的工具。
By qpd-v
2025-05-290
github
详情内容

MCP 通讯器(Telegram)

一个MCP服务器,支持通过Telegram与用户进行通信。该服务器提供了通过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(可以使用包含的实用工具获取)

安装

  1. 克隆仓库:
git clone https://github.com/qpd-v/mcp-communicator-telegram.git
cd mcp-communicator-telegram
  1. 安装依赖:
npm install
  1. 创建Telegram机器人:

    • 打开Telegram并搜索@BotFather
    • 发送/newbot并按照指示操作
    • 保存您收到的机器人令牌
  2. 获取您的聊天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": "向用户提问的问题"
    }
  },
  "required": ["question"]
}

示例用法:

const response = await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "ask_user",
  arguments: {
    question: "你最喜欢的颜色是什么?"
  }
});

notify_user

通过Telegram向用户发送通知消息(无需回复)。

输入模式:

{
  "type": "object",
  "properties": {
    "message": {
      "type": "string",
      "description": "发送给用户的消息"
    }
  },
  "required": ["message"]
}

示例用法:

await use_mcp_tool({
  server_name: "mcp-communicator-telegram",
  tool_name: "notify_user",
  arguments: {
    message: "任务成功完成!"
  }
});

send_file

通过Telegram向用户发送文件。

输入模式:

{
  "type": "object",
  "properties": {
    "filePath": {
      "type": "string",
      "description": "要发送的文件路径"
    }
  },
  "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": "要压缩的目录(默认为当前工作目录)"
    }
  },
  "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工具

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档