Telegram User MCP
Provides tools for interacting with a personal Telegram account via MTProto, enabling AI agents to list dialogs, fetch chat history, search messages, send and edit messages, mark chats as read, and retrieve user profile information.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Telegram User MCPSend a Telegram message to my friend with @username saying I'll be 10 minutes late."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
✈️ Telegram User MCP
Production-Grade Model Context Protocol (MCP) Server for Full Personal Telegram Account (Userbot / MTProto) Control via Telethon & FastMCP
🇺🇸 English | 🇷🇺 Русский | 🇨🇳 中文
Overview • System Architecture • MCP Tools • Quick Start • Configuration
🇺🇸 Overview
Telegram User MCP is a high-performance, asynchronous Model Context Protocol (MCP) server engineered in Python using FastMCP and Telethon. Unlike standard Bot API integrations that are restricted to bot accounts and limited group visibility, Telegram User MCP connects directly to Telegram's native MTProto API on behalf of a personal user account (Userbot).
This grants AI assistants (Claude Desktop, Cursor, Goose, Windsurf) seamless, structured access to your personal chats, private groups, channels, saved messages, global search, and message management over local stdio with zero third-party cloud relays.
Related MCP server: Telegram MCP Server
🧠 System Architecture
Telegram User MCP enforces strict separation between JSON-RPC Stdio Transport, Resilient Error & Rate-Limit Middleware, Entity Resolution & Peer Cache, and MTProto Session Management.
flowchart TD
subgraph Clients ["1. AI Host Clients (Local Stdio)"]
CLAUDE["Claude Desktop"]
CURSOR["Cursor IDE"]
GOOSE["Block Goose / Windsurf"]
end
subgraph MCPServer ["2. FastMCP Server Layer (server.py)"]
STDIO["Pure JSON-RPC Stdio Transport (stderr-isolated logging)"]
TOOLS["7 Strictly-Typed Async MCP Tools"]
SAFE["Resilient Execution Wrapper (_execute_safely)"]
end
subgraph CoreEngine ["3. Telethon MTProto Client Manager"]
LIFESPAN["Async Lifespan Singleton & Lock"]
RESOLVER["Smart Entity Resolver (int ID / @username / 'me')"]
WARMUP["Auto StringSession Dialog Cache Warm-up"]
FLOOD["FloodWait Auto-Sleep & Retry Guard"]
end
subgraph AuthLayer ["4. Auth & Storage (.env / auth.py)"]
AUTH_CLI["Interactive CLI Wizard (auth.py + 2FA Support)"]
STR_SESS["In-Memory StringSession / Local .session"]
TG_CLOUD["Telegram MTProto Cloud DCs"]
end
CLAUDE & CURSOR & GOOSE <-->|JSON-RPC 2.0 over stdio| STDIO
STDIO --> TOOLS
TOOLS --> SAFE
SAFE --> FLOOD
FLOOD --> LIFESPAN
LIFESPAN --> RESOLVER
RESOLVER -.->|Cache Miss Fallback| WARMUP
AUTH_CLI -->|Generates TELEGRAM_SESSION_STRING| STR_SESS
LIFESPAN --> STR_SESS
LIFESPAN <-->|Encrypted MTProto TCP| TG_CLOUD✨ Key Features
🔐 Native Personal Account Control (MTProto): Full access to personal dialogs, archived folders, private supergroups, channels, and Saved Messages (
me).🛡️ Zero Stdio Pollution: All server and Telethon diagnostic logs are strictly routed to
sys.stderr, guaranteeing 100% corruption-free JSON-RPC 2.0 communication overstdout.⚡ Smart
StringSessionEntity Resolution: Automatically resolves numeric peer IDs (-100...,12345678), stringified numbers,@usernames, and'me'. Includes automatic dialog cache warm-up whenaccess_hashentries are cold inStringSession.⏱️ Adaptive
FloodWaitErrorRecovery: Automatically sleeps and retries transient rate limits (up toTELEGRAM_MAX_FLOOD_WAIT_SLEEP=15s) while returning structured retry telemetry for longer blocks without crashing the server.🔑 One-Time Interactive 2FA Auth Wizard (
auth.py): Standalone CLI utility supporting SMS/App codes and hidden cloud 2FA passwords (getpass), automatically exportingTELEGRAM_SESSION_STRINGdirectly into.env.🧱 Strict Pydantic Validation & Typing: Comprehensive parameter bounds checking (
limit,offset_id,folder,message_id) and structured JSON schemas for reliable LLM tool calling.
🧰 MCP Tools Reference
Tool Name | Signature | Description | Key Returned Fields |
|
| Lists active chats, private dialogs, groups, and channels ( |
|
|
| Fetches recent messages from any chat with pagination support. |
|
|
| Performs global search across all dialogs ( |
|
|
| Sends a new text message or replies to a specific message ID. |
|
|
| Edits an existing message sent by the authenticated user. |
|
|
| Acknowledges unread messages, mentions, and reactions in a chat. |
|
|
| Retrieves full user profile via |
|
🛡️ Fault Tolerance & Error Handling Matrix
Telegram / Runtime Exception | Server Behavior | Crash Free? |
| Automatically awaits | ✅ Yes |
| Returns | ✅ Yes |
| Returns actionable instruction to regenerate session via | ✅ Yes |
| Triggers automatic | ✅ Yes |
| Gracefully returns | ✅ Yes |
| Returns structured permission error to the LLM without interrupting the session. | ✅ Yes |
🚀 Quick Start
1. Prerequisites
Python 3.10+ (or uv package manager)
Telegram API credentials (
API_IDandAPI_HASH) from https://my.telegram.org/apps
2. Installation
# Clone the repository
git clone https://github.com/oladikezz/telegram-user-mcp.git
cd telegram-user-mcp
# Option A: Using uv (Recommended)
uv venv
uv pip install -r requirements.txt
# Option B: Using standard venv + pip
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # macOS / Linux
pip install -r requirements.txt3. Authenticate & Generate TELEGRAM_SESSION_STRING
Copy .env.example to .env (or let auth.py prompt you interactively):
cp .env.example .env
python auth.pyauth.py will ask for your phone number, the login code sent via Telegram/SMS, and your 2FA cloud password (if enabled), then automatically write TELEGRAM_SESSION_STRING to .env.
⚙️ MCP Client Configuration
Add the server to your claude_desktop_config.json (Claude Desktop) or .cursor/mcp.json (Cursor IDE):
Option A: Launch via uv (Recommended)
{
"mcpServers": {
"telegram-user": {
"command": "uv",
"args": [
"run",
"--directory",
"C:/Users/user/Desktop/telegram-user-mcp",
"--with",
"mcp[cli]",
"--with",
"telethon",
"--with",
"python-dotenv",
"python",
"server.py"
],
"env": {
"TELEGRAM_API_ID": "12345678",
"TELEGRAM_API_HASH": "your_api_hash_here",
"TELEGRAM_SESSION_STRING": "your_session_string_from_auth_py"
}
}
}
}Option B: Launch via Direct Virtual Environment Python
{
"mcpServers": {
"telegram-user": {
"command": "C:/Users/user/Desktop/telegram-user-mcp/.venv/Scripts/python.exe",
"args": [
"C:/Users/user/Desktop/telegram-user-mcp/server.py"
]
}
}
}📁 Project Structure
telegram-user-mcp/
├── auth.py # Interactive CLI wizard for 2FA auth & StringSession generation
├── server.py # FastMCP stdio server with 7 Telethon userbot tools
├── requirements.txt # Python dependencies (mcp[cli], telethon, python-dotenv, cryptg)
├── claude_desktop_config.json # Ready-to-use configuration template for Claude / Cursor
├── .env.example # Environment variables template
├── .gitignore # Protects .env and *.session files from Git tracking
├── README.md # Documentation (English)
├── README.ru.md # Documentation (Russian)
└── README.zh-CN.md # Documentation (Chinese)🇷🇺 Русский
Полная документация на русском языке доступна в README.ru.md.
Telegram User MCP — это готовый к продакшену асинхронный MCP-сервер на Python (FastMCP + Telethon), предоставляющий ИИ-ассистентам (Claude Desktop, Cursor, Goose) прямой доступ к личному аккаунту Telegram по протоколу MTProto.
Основные возможности:
Полный набор из 7 инструментов:
list_dialogs,get_chat_history,search_messages,send_message,edit_message,mark_as_read,get_user_info.Одноразовый CLI-авторизатор (
auth.py): поддержка кода подтверждения, облачного пароля 2FA и автосохраненияTELEGRAM_SESSION_STRINGв.env.Устойчивость к сбоям: автоматический прогрев кэша диалогов для
StringSession, авто-ожидание короткихFloodWaitErrorи строгая изоляция логов вstderr.
🇨🇳 中文
完整中文文档请参阅 README.zh-CN.md。
Telegram User MCP 是一个基于 Python(FastMCP 与 Telethon)构建的生产级 Model Context Protocol (MCP) 服务器,允许 AI 助手(Claude Desktop、Cursor、Goose)通过原生 MTProto 协议安全地控制您的个人 Telegram 账号(Userbot)。
This server cannot be deployed
Maintenance
Related MCP Connectors
Multi-tenant Telegram gateway for AI agents — HTTP+stdio, 8 tools, MTProto User API
Your personal data for AI — Telegram, bank, courses, Zoom & more, scoped to you.
Your own LinkedIn, WhatsApp, Instagram, Telegram, Email and Calendar accounts, usable from any agent
Remote MCP server for AI.TV creators — delegate account operations to your AI agent over MCP.
Related MCP Servers
- FlicenseNot gradedqualityBmaintenanceEnables AI agents to control a real Telegram user account via MTProto, allowing message sending, chat reading/searching, and message management through MCP tools.25 npm-
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants to control a personal Telegram account for sending/reading messages, media, group management, and more via the MTProto API.MIT
- AlicenseNot gradedqualityCmaintenanceGives an AI assistant full control of a real Telegram user account over MTProto, enabling it to read chats, search history, send and manage messages, and dynamically create new tools as needed.MIT
- FlicenseBqualityBmaintenanceEnables AI assistants to manage Telegram files, messages, and dialogs directly via MTProto, supporting upload, download, search, forwarding, and storage overview operations.19-