Back to Directory/Developer Tools

io.github.n24q02m/better-telegram-mcp

Telegram MCP server — dual-mode Bot API + MTProto, 6 composite tools.

Developer ToolsPythonv4.9.0

Better Telegram MCP

mcp-name: io.github.n24q02m/better-telegram-mcp

MCP server for Telegram with dual-mode support: Bot API (httpx) for quick bot integrations and MTProto (Telethon) for full user-account access.

CI codecov PyPI Docker License: MIT

Python Telegram MCP semantic-release Renovate

<a href="https://glama.ai/mcp/servers/n24q02m/better-telegram-mcp"> </a>

Features

  • Dual mode -- Bot API (httpx) for bots, MTProto (Telethon) for user accounts
  • 6 mega-tools with action dispatch: messages, chats, media, contacts, config, help
  • Auto-detect mode -- Set bot token for bot mode, or API credentials for user mode
  • Web-based OTP auth -- Browser-based authentication with remote relay support for headless environments
  • Tool annotations -- Each tool declares readOnlyHint, destructiveHint, idempotentHint, openWorldHint
  • MCP Resources -- Documentation available as telegram://docs/* resources
  • Security hardened -- SSRF protection, path traversal prevention, error sanitization

Quick Start

Claude Code Plugin (Recommended)

Via marketplace (includes skills: /setup-bot, /channel-post):

bash
/plugin marketplace add n24q02m/claude-plugins
/plugin install better-telegram-mcp@claude-plugins

Or install this plugin only:

bash
/plugin marketplace add n24q02m/better-telegram-mcp
/plugin install better-telegram-mcp

Set credentials in ~/.claude/settings.local.json or shell profile. See Environment Variables.

MCP Server

Python 3.13 required -- Python 3.14+ is not supported.

Bot Mode Setup

  1. Open Telegram, search for @BotFather
  2. Send /newbot, follow prompts to name your bot
  3. Copy the token (format: 123456789:ABCdefGHI-JKLmnoPQRstUVwxyz)

User Mode Setup

  1. Go to my.telegram.org, login with your phone number
  2. Click "API development tools", create an app
  3. Note your api_id (integer) and api_hash (32-char hex string)
  4. On first run, a local web page opens for OTP authentication

Option 1: uvx

jsonc
{
  "mcpServers": {
    "telegram": {
      "command": "uvx",
      "args": ["--python", "3.13", "better-telegram-mcp"]
    }
  }
}
<details> <summary>Other MCP clients (Cursor, Codex, Gemini CLI)</summary>
jsonc
// Cursor (~/.cursor/mcp.json), Windsurf, Cline, Amp, OpenCode
{
  "mcpServers": {
    "telegram": {
      "command": "uvx",
      "args": ["--python", "3.13", "better-telegram-mcp"]
    }
  }
}
toml
# Codex (~/.codex/config.toml)
[mcp_servers.telegram]
command = "uvx"
args = ["--python", "3.13", "better-telegram-mcp"]
</details>

Option 2: Docker

jsonc
{
  "mcpServers": {
    "telegram": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "TELEGRAM_BOT_TOKEN",
        "-v", "telegram-data:/data",
        "n24q02m/better-telegram-mcp"
      ]
    }
  }
}

Configure credentials in ~/.claude/settings.local.json or your shell profile. See Environment Variables below.

For user mode in Docker, mount the session directory with -v ~/.better-telegram-mcp:/data so the session persists across container restarts.

Tools

ToolActionsDescription
messagessend, edit, delete, forward, pin, react, search, historySend, edit, delete, forward messages. Pin, react, search, browse history
chatslist, info, create, join, leave, members, admin, settings, topicsList and manage chats, groups, channels. Members, admin, forum topics
mediasend_photo, send_file, send_voice, send_video, downloadSend photos, files, voice notes, videos. Download media from messages
contactslist, search, add, blockList, search, add contacts. Block/unblock users (user mode only)
configstatus, set, cache_clearServer status, update runtime settings, clear cache
help--Full documentation for any tool

Mode Capabilities

FeatureBotUser
Send/Edit/Delete/Forward messagesYY
Pin messages, ReactYY
Search messages, Browse history--Y
List chats, Create groups/channels--Y
Get chat info, Manage membersYY
Send media (photo/file/voice/video)YY
Download media--Y
Contacts (list/search/add/block)--Y

MCP Resources

URIContent
telegram://docs/messagesMessage operations reference
telegram://docs/chatsChat management reference
telegram://docs/mediaMedia send/download reference
telegram://docs/contactsContact management reference
telegram://statsAll documentation combined

Configuration

VariableRequiredDefaultDescription
TELEGRAM_BOT_TOKENBot mode--Bot token from @BotFather
TELEGRAM_API_IDUser mode--API ID from my.telegram.org (integer)
TELEGRAM_API_HASHUser mode--API hash from my.telegram.org (32-char hex)
TELEGRAM_PHONEUser mode--Phone number with country code (e.g., +84912345678)
TELEGRAM_AUTH_URLNohttps://better-telegram-mcp.n24q02m.comAuth relay URL. Set local for localhost-only mode
TELEGRAM_SESSION_NAMENodefaultSession file name (useful for multiple accounts)
TELEGRAM_DATA_DIRNo~/.better-telegram-mcpData directory for session files

Mode detection: If TELEGRAM_API_ID + TELEGRAM_API_HASH are set, user mode is used. Otherwise, TELEGRAM_BOT_TOKEN is used. No silent fallback -- if neither is set, the server exits with an error.

Auth Flow (User Mode Only)

  1. On first run, a web-based auth UI opens in your browser (or URL is logged for headless)
  2. Click "Send OTP Code" -- code is sent to the Telegram app (not SMS)
  3. Enter the OTP code; if 2FA is enabled, enter your password
  4. Session file is saved at ~/.better-telegram-mcp/<name>.session (600 permissions)
  5. Tools become active immediately -- no restart needed
Auth ModeTELEGRAM_AUTH_URLUse case
Remote (default)https://better-telegram-mcp.n24q02m.comHeadless, SSH, Docker
Self-hostedhttps://your-domain.comCustom relay deployment
LocallocalDesktop, offline

Headless auth (Docker/SSH) -- use curl against the auth URL shown in logs:

bash
curl -X POST http://127.0.0.1:PORT/send-code
curl -X POST http://127.0.0.1:PORT/verify -d '{"code":"12345"}'
curl -X POST http://127.0.0.1:PORT/verify -d '{"password":"your-2fa-password"}'  # if 2FA

Security

  • SSRF Protection -- All URLs validated against internal/private IP ranges, DNS rebinding blocked
  • Path Traversal Prevention -- File paths validated, sensitive directories blocked
  • Session File Security -- 600 permissions, 2FA via web UI only (never stored in env vars)
  • Error Sanitization -- Credentials never leaked in error messages

Build from Source

bash
git clone https://github.com/n24q02m/better-telegram-mcp.git
cd better-telegram-mcp
uv sync
uv run better-telegram-mcp

Compatible With

Claude Code Claude Desktop Cursor VS Code Copilot Antigravity Gemini CLI OpenAI Codex OpenCode

Also by n24q02m

ServerDescription
wet-mcpWeb search, content extraction, and documentation indexing
mnemo-mcpPersistent AI memory with hybrid search and cross-machine sync
better-notion-mcpMarkdown-first Notion API with 9 composite tools
better-email-mcpEmail (IMAP/SMTP) with multi-account and auto-discovery
better-godot-mcpGodot Engine 4.x with 18 tools for scenes, scripts, and shaders
better-code-review-graphKnowledge graph for token-efficient code reviews

Contributing

See CONTRIBUTING.md.

License

MIT -- See LICENSE.

Learn More