MCP Telegram

Telegram MCP server with 20 tools — read chats, search messages, download media via MTProto

MCP Telegram

npm npm downloads Node.js TypeScript MCP SDK License: MIT mcp-telegram MCP server

Hosted version available! Don't want to self-host? Use mcp-telegram.com -- connect Telegram to Claude.ai or ChatGPT in 30 seconds with QR code. No API keys needed.

MCP Telegram demo — connect and summarize chats in Claude

An MCP (Model Context Protocol) server that connects AI assistants like Claude to Telegram via the MTProto protocol. Unlike bots, this runs as a userbot -- it operates under your personal Telegram account using GramJS, giving full access to your chats, contacts, and message history.

Features

  • MTProto protocol -- direct Telegram API access, not the limited Bot API
  • Userbot -- operates as your personal account, not a bot
  • Full-featured -- messaging, reactions, polls, scheduled messages, media, contacts, and more
  • Forum Topics -- list topics, read per-topic messages, send to specific topics, per-topic unread counts
  • QR code login -- authenticate by scanning a QR code in the Telegram app
  • Session persistence -- login once, stay connected across restarts
  • Human-readable output -- sender names are resolved, not just numeric IDs
  • Works with any MCP client -- Claude Code, Claude Desktop, ChatGPT, Cursor, VS Code, Mastra, etc.

Prerequisites

  • Node.js 18 or later
  • Telegram API credentials -- API_ID and API_HASH from my.telegram.org

Quick Start

1. Get Telegram API credentials

  1. Go to my.telegram.org and log in with your phone number.
  2. Navigate to API development tools.
  3. Create a new application (any name and platform).
  4. Copy the App api_id and App api_hash.

2. Login

TELEGRAM_API_ID=YOUR_ID TELEGRAM_API_HASH=YOUR_HASH npx @overpod/mcp-telegram login

A QR code will appear in the terminal. Open Telegram on your phone, go to Settings > Devices > Link Desktop Device, and scan the code. The session is saved to ~/.mcp-telegram/session and reused automatically.

Custom session path: set TELEGRAM_SESSION_PATH=/path/to/session to store the session file elsewhere.

3. Add to Claude

claude mcp add telegram -s user \
  -e TELEGRAM_API_ID=YOUR_ID \
  -e TELEGRAM_API_HASH=YOUR_HASH \
  -- npx @overpod/mcp-telegram

That's it! Ask Claude to run telegram-status to verify.

Multiple Accounts

Use TELEGRAM_SESSION_PATH to run separate Telegram accounts side by side:

# Login each account with a unique session path
TELEGRAM_API_ID=ID1 TELEGRAM_API_HASH=HASH1 TELEGRAM_SESSION_PATH=~/.mcp-telegram/session-work npx @overpod/mcp-telegram login
TELEGRAM_API_ID=ID2 TELEGRAM_API_HASH=HASH2 TELEGRAM_SESSION_PATH=~/.mcp-telegram/session-personal npx @overpod/mcp-telegram login

Then add each as a separate MCP server:

claude mcp add telegram-work -s user \
  -e TELEGRAM_API_ID=ID1 \
  -e TELEGRAM_API_HASH=HASH1 \
  -e TELEGRAM_SESSION_PATH=~/.mcp-telegram/session-work \
  -- npx @overpod/mcp-telegram

claude mcp add telegram-personal -s user \
  -e TELEGRAM_API_ID=ID2 \
  -e TELEGRAM_API_HASH=HASH2 \
  -e TELEGRAM_SESSION_PATH=~/.mcp-telegram/session-personal \
  -- npx @overpod/mcp-telegram

Each account gets its own session file — no conflicts.

Installation Options

npx (recommended, zero install)

No need to clone or install anything. Just use npx @overpod/mcp-telegram.

Global install

npm install -g @overpod/mcp-telegram
mcp-telegram          # run server
mcp-telegram login    # QR login

From source

git clone https://github.com/overpod/mcp-telegram.git
cd mcp-telegram
npm install && npm run build

Usage with MCP Clients

Claude Code (CLI)

claude mcp add telegram -s user \
  -e TELEGRAM_API_ID=YOUR_ID \
  -e TELEGRAM_API_HASH=YOUR_HASH \
  -- npx @overpod/mcp-telegram

Claude Desktop

  1. Open your config file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. Add the Telegram server:

{
  "mcpServers": {
    "telegram": {
      "command": "npx",
      "args": ["@overpod/mcp-telegram"],
      "env": {
        "TELEGRAM_API_ID": "YOUR_ID",
        "TELEGRAM_API_HASH": "YOUR_HASH"
      }
    }
  }
}
  1. Restart Claude Desktop.

  2. Ask Claude: "Run telegram-login" -- a QR code will appear. If the image is not visible, Claude will provide a browser link to view the QR code. Scan it in Telegram (Settings > Devices > Link Desktop Device).

  3. Ask Claude: "Run telegram-status" to verify the connection.

Note: No terminal required! Login works entirely through Claude Desktop.

Cursor / VS Code

Add the same JSON config above to your MCP settings (Cursor Settings > MCP, or VS Code MCP config).

Mastra

import { MCPClient } from "@mastra/mcp";

const telegramMcp = new MCPClient({
  id: "telegram-mcp",
  servers: {
    telegram: {
      command: "npx",
      args: ["@overpod/mcp-telegram"],
      env: {
        TELEGRAM_API_ID: process.env.TELEGRAM_API_ID!,
        TELEGRAM_API_HASH: process.env.TELEGRAM_API_HASH!,
      },
    },
  },
});

Available Tools

Connection

ToolDescription
telegram-statusCheck connection status and current account info
telegram-loginAuthenticate via QR code

Messaging

ToolDescription
telegram-send-messageSend a text message to a chat
telegram-send-fileSend a file (photo, document, video, etc.) to a chat
telegram-send-reactionSend or remove an emoji reaction on a message
telegram-send-scheduledSchedule a message for future delivery
telegram-create-pollCreate a poll (multiple choice or quiz mode)
telegram-edit-messageEdit a previously sent message
telegram-delete-messageDelete messages in a chat
telegram-forward-messageForward messages between chats

Reading

ToolDescription
telegram-list-chatsList recent dialogs with unread counts, bot/contact markers
telegram-read-messagesRead recent messages from a chat
telegram-search-chatsSearch for chats, users, or channels by name
telegram-search-messagesSearch messages in a chat by text
telegram-get-unreadGet chats with unread messages; forums show per-topic unread breakdown
telegram-get-contact-requestsGet incoming messages from non-contacts with preview

Forum Topics

ToolDescription
telegram-list-topicsList forum topics in a group with unread counts and status
telegram-read-topic-messagesRead messages from a specific forum topic

Chat Management

ToolDescription
telegram-mark-as-readMark a chat as read
telegram-get-chat-infoGet detailed info about a chat (name, type, members, bot/contact status)
telegram-get-chat-membersList members of a group or channel
telegram-join-chatJoin a group or channel by username or invite link
telegram-pin-messagePin a message in a chat
telegram-unpin-messageUnpin a message in a chat

Contacts & Moderation

ToolDescription
telegram-add-contactAdd a user to your contacts (accept contact request)
telegram-block-userBlock a user from sending you messages
telegram-report-spamReport a chat as spam to Telegram

User Info

ToolDescription
telegram-get-contactsGet your contacts list with phone numbers
telegram-get-profileGet detailed profile info for a user (bio, photo, last seen)

Media

ToolDescription
telegram-download-mediaDownload media from a message to a local file

Tool Parameters

Common patterns

Most tools accept chatId as a string -- either a numeric ID (e.g., "-1001234567890") or a username (e.g., "@username").

telegram-send-message

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
textstringyesMessage text
replyTonumbernoMessage ID to reply to
parseMode"md" / "html"noMessage formatting mode
topicIdnumbernoForum topic ID to send into (for groups with Topics)

telegram-list-topics

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username (group with Topics enabled)
limitnumbernoMax topics to return (default: 100)

telegram-read-topic-messages

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
topicIdnumberyesTopic ID (from telegram-list-topics)
limitnumbernoNumber of messages (default: 20)
offsetIdnumbernoMessage ID for pagination

telegram-list-chats

ParameterTypeRequiredDescription
limitnumbernoNumber of chats to return (default: 20)
offsetDatenumbernoUnix timestamp for pagination
filterType"private" / "group" / "channel" / "contact_requests"noFilter by chat type

telegram-read-messages

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
limitnumbernoNumber of messages (default: 10)
offsetIdnumbernoMessage ID for pagination

telegram-send-file

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
filePathstringyesAbsolute path to the file
captionstringnoFile caption

telegram-download-media

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
messageIdnumberyesMessage ID containing media
downloadPathstringyesAbsolute path to save the file

telegram-forward-message

ParameterTypeRequiredDescription
fromChatIdstringyesSource chat ID or @username
toChatIdstringyesDestination chat ID or @username
messageIdsnumber[]yesArray of message IDs to forward

telegram-edit-message

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
messageIdnumberyesID of the message to edit
textstringyesNew message text

telegram-delete-message

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
messageIdsnumber[]yesArray of message IDs to delete

telegram-pin-message

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
messageIdnumberyesMessage ID to pin
silentbooleannoPin without notification (default: false)

telegram-join-chat

ParameterTypeRequiredDescription
targetstringyesUsername (@group), link (t.me/group), or invite link (t.me/+xxx)

telegram-send-reaction

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
messageIdnumberyesMessage ID to react to
emojistringnoReaction emoji (e.g. 👍❤️🔥😂🎉). Omit to remove reaction

telegram-send-scheduled

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username (use "me" or "self" for Saved Messages)
textstringyesMessage text
scheduleDatenumberyesUnix timestamp when to send (must be in the future)
replyTonumbernoMessage ID to reply to
parseMode"md" / "html"noMessage formatting mode

telegram-create-poll

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
questionstringyesPoll question
answersstring[]yesAnswer options (2-10 items)
multipleChoicebooleannoAllow multiple answers (default: false)
quizbooleannoQuiz mode with one correct answer (default: false)
correctAnswernumbernoIndex of correct answer, 0-based (required for quiz mode)

telegram-search-messages

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
querystringyesSearch text
limitnumbernoMax results (default: 20)

telegram-search-chats

ParameterTypeRequiredDescription
querystringyesSearch query (name or username)
limitnumbernoMax results (default: 10)

telegram-get-chat-members

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username
limitnumbernoNumber of members (default: 50)

telegram-get-contacts

ParameterTypeRequiredDescription
limitnumbernoNumber of contacts (default: 50)

telegram-get-profile

ParameterTypeRequiredDescription
userIdstringyesUser ID or @username

telegram-get-unread

ParameterTypeRequiredDescription
limitnumbernoNumber of unread chats (default: 20)

telegram-get-contact-requests

ParameterTypeRequiredDescription
limitnumbernoNumber of contact requests (default: 20)

telegram-add-contact

ParameterTypeRequiredDescription
userIdstringyesUser ID or @username to add
firstNamestringyesFirst name for the contact
lastNamestringnoLast name for the contact
phonestringnoPhone number for the contact

telegram-block-user

ParameterTypeRequiredDescription
userIdstringyesUser ID or @username to block

telegram-report-spam

ParameterTypeRequiredDescription
chatIdstringyesChat ID or @username to report

Development

npm run dev        # Start with file watching (tsx)
npm start          # Start the MCP server
npm run login      # QR code login in terminal
npm run build      # Compile TypeScript
npm run lint       # Check code with Biome
npm run lint:fix   # Auto-fix lint issues
npm run format     # Format code with Biome

Project Structure

src/
  index.ts            -- MCP server entry point, tool definitions
  telegram-client.ts  -- TelegramService class (GramJS wrapper)
  qr-login-cli.ts     -- CLI utility for QR code login

Tech Stack

  • TypeScript -- ES2022, ESM modules
  • GramJS (telegram) -- Telegram MTProto client
  • @modelcontextprotocol/sdk -- MCP server framework
  • Zod -- Runtime schema validation for tool parameters
  • Biome -- Linter and formatter
  • tsx -- TypeScript execution without a build step
  • dotenv -- Environment variable management

Security

  • API credentials are stored in .env (gitignored)
  • Session is stored in ~/.mcp-telegram/session with 0600 permissions (owner-only access)
  • Session directory is created with 0700 permissions
  • Phone number is not required -- QR-only authentication
  • This is a userbot (personal account), not a bot -- respect the Telegram Terms of Service

License

MIT

Server Terkait