Skip to main content
Glama
telegram-user-mcp

telegram-user-mcp

by tarikra1

telegram-user-mcp

CI Version License: MIT Python 3.10+ MCP

An asynchronous Model Context Protocol (MCP) server and CLI that connects AI coding agents (Claude Code, Claude Desktop, Cursor, Gemini, and custom MCP hosts) directly to a personal Telegram MTProto account via Telethon.

Unlike standard Telegram Bot API wrappers—which can only see chats where a bot was explicitly invited—telegram-user-mcp operates through your authenticated user session with automatic SQLite session-lock recovery, idle auto-disconnect, and a server-enforced TELEGRAM_READ_ONLY safety guard.


Key Capabilities

  • 19 MCP Tools Out of the Box: Full coverage for authentication (OTP + 2FA cloud password), custom chat folders (DialogFilter), unread dialog filtering, global cross-chat search, message sending/editing/forwarding/pinning, and media uploads/downloads.

  • Read-Only Safety Guard (TELEGRAM_READ_ONLY=true): Safely grant agents full read/search access across your Telegram workspace while blocking all mutating tools (send, edit, forward, delete, pin) at the server layer.

  • Zero-Lock Session Lifecycle: Automatically disconnects idle Telethon SQLite sessions after 20 seconds of inactivity and retries transient SQLite locks with exponential backoff.

  • Smart Entity Resolution: Target any chat seamlessly using "me" (Saved Messages), @username, t.me/ links, numeric IDs, or fuzzy dialog titles.

  • Clean stdio Transport & CLI Parity: Directs all diagnostic logging strictly to stderr and exposes every tool from the terminal via telegram-mcp-cli.


Related MCP server: telegram-mcp

Installation

git clone https://github.com/tarikra1/telegram-user-mcp.git
cd telegram-user-mcp
python -m venv .venv
# Windows: .venv\Scripts\activate | macOS/Linux: source .venv/bin/activate
pip install -e .

Configuration

  1. Create an application at https://my.telegram.org/apps to obtain your api_id and api_hash.

  2. Copy .env.example to .env and fill in your credentials:

cp .env.example .env
TELEGRAM_API_ID=12345678
TELEGRAM_API_HASH=your_32_character_telegram_api_hash
TELEGRAM_PHONE=+15550109999
TELEGRAM_READ_ONLY=false

Connecting to Claude Code / Claude Desktop / Cursor

Add the server to your MCP configuration (claude_desktop_config.json or .mcp.json):

{
  "mcpServers": {
    "telegram": {
      "command": "telegram-user-mcp",
      "env": {
        "TELEGRAM_API_ID": "12345678",
        "TELEGRAM_API_HASH": "your_api_hash",
        "TELEGRAM_PHONE": "+15550109999",
        "TELEGRAM_READ_ONLY": "false"
      }
    }
  }
}

On first use, ask your agent to call auth_send_code followed by auth_verify_code (including Two-Step Verification password support if 2FA is enabled on your Telegram account).


Available MCP Tools (19)

Category

Tool

Description

Auth & Profile

auth_status

Check session auth state and read_only guard status

auth_send_code

Request an OTP login code via Telegram / SMS

auth_verify_code

Complete sign-in with OTP code and optional 2FA password

get_me

Retrieve profile details of the authenticated account

Discovery & Folders

list_folders

List custom Telegram chat folders (DialogFilter tabs)

get_folder_chats

List all peers pinned/included inside a specific folder

list_chats

List dialogs filtered by all, user, bot, 'group', channel, or unread_only

search_chats

Search local dialogs + global Telegram directory

get_chat_info

Fetch bio, participant count, and metadata for any entity

Reading & Search

get_messages

Read recent or filtered messages from a specific chat

search_messages_global

Full-text search across all chats, groups, and channels

Messaging & Media

send_message

Send Markdown, HTML, or plain-text messages (blocked in read-only mode)

send_file

Upload documents, images, or videos with captions (blocked in read-only mode)

download_media

Download attachments from any message ID to disk

forward_messages

Forward message batches across chats (blocked in read-only mode)

edit_message

Edit previously sent messages (blocked in read-only mode)

delete_messages

Delete/revoke messages (blocked in read-only mode)

mark_as_read

Acknowledge unread messages in a dialog

pin_message

Pin a message silently or with notification (blocked in read-only mode)


CLI Usage

# List all registered tools
telegram-mcp-cli list

# List top 10 unread channels
telegram-mcp-cli list_chats --chat-type channel --unread-only --limit 10

# Search across all chats
telegram-mcp-cli search_messages_global --query "deployment" --limit 5

Running Tests

python -m unittest discover -s tests -v

License

Released under the MIT License.

Available Tools

19 tools
auth_send_codeC

Send a Telegram login verification code to your phone/Telegram app.

Inputs: phone. Returns: result

auth_statusB

Check whether the Telegram personal account session is authorized.

Inputs: no named parameters. Returns: result

auth_verify_codeA

Complete Telegram login with the verification code (and optional 2FA cloud password).

Inputs: code (required), password. Returns: result

delete_messagesB

Delete one or more messages in a chat.

Inputs: target (required), message_ids (required), revoke. Returns: result

download_mediaC

Download the attached file/photo/video/archive from a specific message_id in target chat.

Inputs: target (required), message_id (required), output_dir. Returns: result

edit_messageC

Edit the text of a message you previously sent.

Inputs: target (required), new_text (required), message_id (required). Returns: result

forward_messagesC

Forward one or more messages from one chat to another (e.g. to 'me' Saved Messages).

Inputs: to_target (required), from_target (required), message_ids (required). Returns: result

get_chat_infoB

Get detailed info about a user, group, or channel by ID, @username, or chat title.

Inputs: target (required). Returns: result

get_folder_chatsA

List all chats/channels/groups inside a custom Telegram folder (by folder title like 'Work' or folder ID).

Inputs: folder (required). Returns: result

get_meA

Get profile information of the currently logged-in Telegram user.

Inputs: no named parameters. Returns: result

get_messagesA

Read messages from a chat/group/channel ('me', @username, numeric ID, or chat title). Optionally filter messages inside that chat using 'search'.

Inputs: target (required), limit, search, offset_id. Returns: result

list_chatsC

List recent Telegram dialogs/chats. chat_type: 'all', 'user', 'bot', 'group', or 'channel'.

Inputs: limit, archived, chat_type, unread_only. Returns: result

list_foldersA

List custom Telegram chat folders (filters) such as work, courses, graphics, etc.

Inputs: no named parameters. Returns: result

mark_as_readC

Mark unread messages in a chat/group/channel as read.

Inputs: target (required). Returns: result

pin_messageC

Pin a message in a chat/group/channel.

Inputs: target (required), message_id (required), notify. Returns: result

search_chatsB

Search your Telegram dialogs and global directory by name or @username.

Inputs: query (required), limit. Returns: result

search_messages_globalC

Search messages across ALL your Telegram chats, groups, and channels.

Inputs: query (required), limit. Returns: result

send_fileC

Upload and send a local file, image, video, or document to a Telegram chat or 'me'.

Inputs: target (required), file_path (required), caption, force_document, +1 more. Returns: result

send_messageC

Send a text message to a user, group, channel, or 'me' (Saved Messages). parse_mode: 'md' (Markdown), 'html', or 'none'.

Inputs: target (required), message (required), parse_mode, reply_to_msg_id. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 19 tools

    Disambiguation4/5

    Most tools target a distinct resource+action pair (send/edit/delete/forward/pin messages), and descriptions clarify the boundaries between list_chats, search_chats, and get_chat_info. Minor overlap remains between search_chats and get_chat_info (both resolve a chat by name/@username) and between get_messages and search_messages_global, but the wording makes the intended selection clear.

    Naming Consistency4/5

    All names are snake_case and follow a verb_noun pattern (send_message, edit_message, delete_messages, list_chats, get_chat_info), with an auth_ namespace prefix used consistently for the three login tools. The only deviations are the noun-phrase auth_status and the terse get_me, which are minor and readable.

    Tool Count4/5

    At 19 tools the set is on the heavy side but each tool maps to a real operation in a personal Telegram client (auth, chats, folders, messages, media). No obviously redundant tools inflate the count, though a few message-management operations could arguably be collapsed.

    Completeness4/5

    Core messaging lifecycle is well covered: send text/file, read, search (per-chat and global), edit, delete, forward, pin, mark read, and media download, plus auth and folder browsing. Gaps exist around chat membership operations (join/leave), contact/participant listing, reactions, and folder creation/deletion, but agents can work around most of these.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to interact with a user's Telegram account: list chats, read history, search, and send messages through Telegram's MTProto API.
      2
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to control a real Telegram user account via MTProto, allowing message sending, chat reading/searching, and message management through MCP tools.
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to interact with a personal Telegram account via MCP, offering tools for reading and searching chats, summarizing unread messages, sending and editing messages, handling files and voice transcripts, and managing groups and channels, with read-only mode by default.
      Apache 2.0