Cover image
Try Now
2025-04-01

MCP(模型上下文协议)服务器的打字稿实现,用于通过MTPROTO使用电报

3 years

Works with Finder

0

Github Watches

0

Github Forks

1

Github Stars

MCP Telegram

A TypeScript implementation of an MCP (Model Context Protocol) server for working with Telegram through MTProto, built using FastMCP.

Overview

This project provides a set of tools for interacting with Telegram through the MTProto protocol, making them available via an MCP server for use with AI models like Claude.

Installation

# Install dependencies
npm install

# Build the project
npm run build

Usage

CLI Commands

The application provides the following CLI commands:

# Sign in to Telegram
npm run sign-in
# or
npx mcp-telegram sign-in

# Start the MCP server
npm run mcp
# or 
npx mcp-telegram mcp [options]

# Logout from Telegram
npm run logout
# or
npx mcp-telegram logout

CLI Options for the mcp command:

  • -t, --transport <type>: Transport type (stdio, sse), defaults to 'stdio'
  • -p, --port <number>: Port for HTTP/SSE transport, defaults to 3000
  • -e, --endpoint <path>: Endpoint for SSE transport, defaults to 'mcp'

Starting the MCP Server

Start the MCP server with stdio transport (default, used by Cursor AI):

npm run start
# or
npm run mcp

You can also run the server programmatically:

import server, { startServer } from 'mcp-telegram';

// Start the server with the configuration
startServer(server);

Environment Variables

The application uses the following environment variables:

  • TELEGRAM_API_ID: Your Telegram API ID
  • TELEGRAM_API_HASH: Your Telegram API Hash
  • TRANSPORT_TYPE: Transport type ('stdio', 'http', or 'sse'), defaults to 'stdio'
  • PORT: Port for HTTP or SSE transports, defaults to 3000
  • ENDPOINT: Endpoint for SSE transport, defaults to 'mcp'
  • LOG_LEVEL: Logging level, defaults to 'info'

These can be set in a .env file in the project root.

Development

Development requires Node.js version 18 or higher.

# Run in development mode
npm run dev

# Lint the code
npm run lint

# Run tests
npm run test

FastMCP Integration

The server is implemented using FastMCP, which provides a modern TypeScript implementation of the Model Context Protocol. It supports stdio and SSE transports, making it compatible with different client integration approaches.

Server Transports

  • stdio: Default transport, useful for direct integration with tools like Cursor AI
  • sse: Server-Sent Events transport for real-time communication

Available Tools

listDialogs

List available dialogs, chats and channels.

Parameters:

  • unread: Boolean, show only unread dialogs (default: false)
  • archived: Boolean, include archived dialogs (default: false)
  • ignorePinned: Boolean, ignore pinned dialogs (default: false)

listMessages

List messages in a given dialog, chat or channel.

Parameters:

  • dialogId: String, ID of the dialog to list messages from
  • unread: Boolean, show only unread messages (default: false)
  • limit: Number, maximum number of messages to retrieve (default: 100)

Project Structure

src/
├── config.ts               # Application configuration
├── index.ts                # Main server implementation
├── mcp.ts                  # CLI entry point
├── tools/                  # Tool implementations
│   ├── index.ts            # Tools export
│   └── telegramTools.ts    # Telegram tools
├── lib/           # Core Telegram functionality
│   ├── index.ts            # Module exports
│   ├── telegram.ts         # Telegram client functionality
└── utils/                  # Utilities
    ├── errorHandler.ts     # Error handling utilities
    └── logger.ts           # Logging utility

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • J. DE HARO OLLE
  • Especialista en juegos de palabras en varios idiomas.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • albert tan
  • Japanese education, creating tailored learning experiences.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • rahulc0dy
  • 测试您的MCP服务器。

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

    Reviews

    4 (1)
    Avatar
    user_1uJ99yPU
    2025-04-16

    As a dedicated user of mcp-telegram, I must say it significantly simplifies and enhances my Telegram experience. Its intelligent functions and ease of integration make it a standout tool in my daily routine. If you're looking for seamless interaction and automation within Telegram, this is a must-try! Great job by the team at tacticlaunch! Check it out at https://github.com/tacticlaunch/mcp-telegram.