返回市场
MCP通信器-Telegram

MCP通信器-Telegram

作者:qpd-v41 星标更新:2025-01-24

项目介绍

MCP Communicator (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(可以使用附带的实用程序获取)

安装步骤

  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 工具