Skip to main content

Production-grade MCP server for Telegram — dual-mode Bot API + MTProto, mega-tool pattern

Project description

better-telegram-mcp

PyPI Docker MCP Registry Glama Codecov License: MIT

Production-grade MCP server for Telegram with dual-mode support: Bot API (via httpx) for quick bot integrations and MTProto (via Telethon) for full user-account access including message search, history browsing, contact management, and group creation.

Features

  • 6 mega-tools with action dispatch: messages, chats, media, contacts, config, help
  • Dual mode: Bot API (httpx) for bots, MTProto (Telethon) for user accounts
  • 3-tier token optimization: Only 6 tools registered instead of 30+ individual endpoints
  • Tool annotations: Each tool declares readOnlyHint, destructiveHint, idempotentHint, openWorldHint
  • MCP Resources: Documentation available as telegram://docs/* resources
  • Auto-detect mode: Set bot token for bot mode, or API credentials for user mode

Quick Start

Bot Mode

Get a bot token from @BotFather, then:

TELEGRAM_BOT_TOKEN=123456:ABC-DEF uvx --python 3.13 better-telegram-mcp

User Mode

Get API credentials from my.telegram.org, then:

export TELEGRAM_API_ID=12345
export TELEGRAM_API_HASH=abcdef123456

# Authenticate once (interactive)
uvx --python 3.13 better-telegram-mcp auth

# Run the server
uvx --python 3.13 better-telegram-mcp

Configuration

All configuration is via environment variables with TELEGRAM_ prefix:

Variable Required Description
TELEGRAM_BOT_TOKEN Bot mode Bot token from @BotFather
TELEGRAM_API_ID User mode API ID from my.telegram.org
TELEGRAM_API_HASH User mode API hash from my.telegram.org
TELEGRAM_PHONE User mode (auth) Phone number for authentication
TELEGRAM_PASSWORD No 2FA password (if enabled)
TELEGRAM_SESSION_NAME No Session file name (default: default)
TELEGRAM_DATA_DIR No Data directory (default: ~/.better-telegram-mcp)

MCP Config Examples

Claude Code

claude mcp add telegram -- env TELEGRAM_BOT_TOKEN=123456:ABC-DEF uvx --python 3.13 better-telegram-mcp

Claude Desktop

{
  "mcpServers": {
    "telegram": {
      "command": "uvx",
      "args": ["--python", "3.13", "better-telegram-mcp"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "123456:ABC-DEF"
      }
    }
  }
}

Cursor

{
  "mcpServers": {
    "telegram": {
      "command": "uvx",
      "args": ["--python", "3.13", "better-telegram-mcp"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "123456:ABC-DEF"
      }
    }
  }
}

VS Code Copilot

Add to .vscode/mcp.json:

{
  "servers": {
    "telegram": {
      "command": "uvx",
      "args": ["--python", "3.13", "better-telegram-mcp"],
      "env": {
        "TELEGRAM_BOT_TOKEN": "123456:ABC-DEF"
      }
    }
  }
}

Docker

# Bot mode
docker run -e TELEGRAM_BOT_TOKEN=123456:ABC-DEF n24q02m/better-telegram-mcp

# User mode (mount session data)
docker run -e TELEGRAM_API_ID=12345 -e TELEGRAM_API_HASH=abcdef123456 \
  -v ~/.better-telegram-mcp:/data \
  n24q02m/better-telegram-mcp

Docker config for Claude Desktop:

{
  "mcpServers": {
    "telegram": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "TELEGRAM_BOT_TOKEN=123456:ABC-DEF",
        "n24q02m/better-telegram-mcp"
      ]
    }
  }
}

Mode Capabilities

Feature Bot Mode User Mode
Send messages Y Y
Edit messages Y Y
Delete messages Y Y
Forward messages Y Y
Pin messages Y Y
React to messages Y Y
Search messages - Y
Browse history - Y
List chats - Y
Get chat info Y Y
Create groups/channels - Y
Join/Leave chats Partial Y
Manage members Y Y
Admin promotion Y Y
Chat settings Y Y
Forum topics Y Y
Send media (photo/file/voice/video) Y Y
Download media - Y
List contacts - Y
Search contacts - Y
Add contacts - Y
Block/Unblock users - Y

Tool Reference

Use the help tool for full documentation:

help(topic="messages")  # Message operations
help(topic="chats")     # Chat management
help(topic="media")     # Media send/download
help(topic="contacts")  # Contact management
help(topic="all")       # Everything

Compatible With

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

better_telegram_mcp-1.0.0.tar.gz (62.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

better_telegram_mcp-1.0.0-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

Details for the file better_telegram_mcp-1.0.0.tar.gz.

File metadata

  • Download URL: better_telegram_mcp-1.0.0.tar.gz
  • Upload date:
  • Size: 62.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for better_telegram_mcp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f2cb627f4f6e3d90deb9020162b004bd109d9e20ed23465404e8b73969d723a7
MD5 2109b6cc019f86e171fc100a6f9e062d
BLAKE2b-256 f024674a751e98ef35277a353a3df865658e9e4d9a272cc08957d49af28f19b8

See more details on using hashes here.

File details

Details for the file better_telegram_mcp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: better_telegram_mcp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for better_telegram_mcp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea21570bb44c7d9fecfa698676d3a6a6dbd3e0d58f05799bafba69b0c826d161
MD5 f9421ba8e7f9d6131f8d1c505d4257b9
BLAKE2b-256 276598f1be55565142a1a00980d1ab76bf8aaffaf240884cf05b6b0e4b6d2cd1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page