Telegram API integration for accessing user data, managing dialogs (chats, channels, groups), retrieving messages, sending messages and handling read status.
Add to Claude Desktop config.json
{
"mcpServers": {
"chigwell-telegram-mcp": {
"command": "python",
"args": [
"-m",
"telegram_mcp"
]
}
}
} Get the source and run locally
git clone https://github.com/chigwell/telegram-mcp.git ~/.mcp/telegram-mcp
cd ~/.mcp/telegram-mcp A Telegram integration for Claude, Cursor, and other MCP-compatible clients. It exposes Telegram account, chat, message, contact, media, folder, and admin operations through the Model Context Protocol using Telethon.
Basic Telegram MCP usage in Claude:

Asking Claude to analyze chat history and send a response:

Message sent successfully:

The server currently includes 80+ MCP tools grouped into these areas:
All tool results that include Telegram user-controlled content are sanitized and, where practical, returned as structured JSON.
Do not install this server with
uvx telegram-mcp,uvx --from telegram-mcp, orpip install telegram-mcp. Thetelegram-mcpname on PyPI is currently owned by a different project and does not install this repository. PassingTELEGRAM_API_ID,TELEGRAM_API_HASH, orTELEGRAM_SESSION_STRINGto that package can expose Telegram account credentials to unrelated third-party code.
git clone https://github.com/chigwell/telegram-mcp.git
cd telegram-mcp
uv sync
uv run session_string_generator.py
Follow the prompts. Save the generated session string securely.
For scripted setup or operational runbooks, choose the login method explicitly:
# QR login, recommended when you already have Telegram open on another device
uv run session_string_generator.py --qr
# Phone number + verification code login
uv run session_string_generator.py --phone
Without a flag, the generator keeps the interactive method prompt.
Copy the example file and fill in your real values:
cp .env.example .env
Single-account setup:
TELEGRAM_API_ID=your_api_id_here
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_SESSION_STRING=your_session_string_here
By default, all Telegram MCP tools are exposed. If you want to prevent MCP
clients from sending messages or performing chat/account mutations, set
TELEGRAM_EXPOSED_TOOLS=read-only to expose only tools annotated with
readOnlyHint=True:
TELEGRAM_EXPOSED_TOOLS=read-only
This is an MCP tool-surface restriction, not a Telegram session sandbox or
reduced Telegram account permission. The Telegram session string still has its
normal authority inside the server process; read-only mode only prevents
non-read-only tools from being registered and exposed through MCP. Accepted
values are all (the default) and read-only.
Run the server locally:
uv run main.py
For Claude Desktop or Cursor, point the MCP server at a cloned checkout of this project:
{
"mcpServers": {
"telegram-mcp": {
"command": "uv",
"args": [
"--directory",
"/full/path/to/telegram-mcp",
"run",
"main.py"
],
"env": {
"TELEGRAM_API_ID": "your_api_id_here",
"TELEGRAM_API_HASH": "your_api_hash_here",
"TELEGRAM_SESSION_STRING": "your_session_string_here"
}
}
}
}
To expose only read-only tools in Claude Desktop or Cursor, add this to the
server env block:
"TELEGRAM_EXPOSED_TOOLS": "read-only"
Alternatively, install this repository directly from GitHub into a virtual environment using a specific release tag or commit:
python -m venv .venv
. .venv/bin/activate
pip install "git+https://github.com/chigwell/telegram-mcp.git@<tag-or-commit>"
Then configure your MCP client to run the installed console script:
{
"mcpServers": {
"telegram-mcp": {
"command": "/full/path/to/.venv/bin/telegram-mcp",
"env": {
"TELEGRAM_API_ID": "your_api_id_here",
"TELEGRAM_API_HASH": "your_api_hash_here",
"TELEGRAM_SESSION_STRING": "your_session_string_here"
}
}
}
}
Generate a session string without cloning the repo by sourcing this repository from GitHub explicitly:
uvx --from "git+https://github.com/chigwell/telegram-mcp.git@<pinned-release-tag-or-commit>" telegram-mcp-generate-session
Use suffixed session variables to configure multiple Telegram accounts:
TELEGRAM_API_ID=your_api_id_here
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_SESSION_STRING_WORK=session_string_for_work
TELEGRAM_SESSION_STRING_PERSONAL=session_string_for_personal
Labels are lowercased and become the account parameter value in tools.
account is optional.account.account is omitted.Example prompts:
Route Telegram traffic through a proxy by setting the TELEGRAM_PROXY_*
environment variables. Supported types are socks5, socks4, http, and
mtproxy.
SOCKS and HTTP proxies require the optional python-socks package:
uv sync --extra proxy
# or
pip install python-socks
Single-account configuration:
TELEGRAM_PROXY_TYPE=socks5
TELEGRAM_PROXY_HOST=127.0.0.1
TELEGRAM_PROXY_PORT=1080
TELEGRAM_PROXY_USERNAME=optional_user
TELEGRAM_PROXY_PASSWORD=optional_pass
TELEGRAM_PROXY_RDNS=true
MTProxy:
TELEGRAM_PROXY_TYPE=mtproxy
TELEGRAM_PROXY_HOST=mtproxy.example
TELEGRAM_PROXY_PORT=443
TELEGRAM_PROXY_SECRET=ee0123456789abcdef...
Per-account overrides use the same _<LABEL> suffix as session variables and
take precedence over the unsuffixed defaults:
TELEGRAM_PROXY_TYPE=socks5
TELEGRAM_PROXY_HOST=127.0.0.1
TELEGRAM_PROXY_PORT=1080
TELEGRAM_PROXY_TYPE_WORK=http
TELEGRAM_PROXY_HOST_WORK=proxy.work.example
TELEGRAM_PROXY_PORT_WORK=3128
Misconfigured proxy settings (unknown type, missing host/port, invalid port,
missing MTProxy secret, or a missing python-socks package) cause the server
to fail fast at startup with a clear error message instead of silently
bypassing the proxy.
File-path tools are disabled until allowed roots are configured. This affects tools such as send_file, download_media, upload_file, send_voice, send_sticker, set_profile_photo, and edit_chat_photo.
Allowed roots can come from:
Security behavior:
<first_root>/downloads/.Run with allowed roots:
uv run main.py /data/telegram /tmp/telegram-mcp
From an MCP client configuration, pass the same roots after main.py:
{
"mcpServers": {
"telegram-mcp": {
"command": "uv",
"args": [
"--directory",
"/full/path/to/telegram-mcp",
"run",
"main.py",
"/data/telegram",
"/tmp/telegram-mcp"
],
"env": {
"TELEGRAM_API_ID": "your_api_id_here",
"TELEGRAM_API_HASH": "your_api_hash_here",
"TELEGRAM_SESSION_STRING": "your_session_string_here"
}
}
}
}
Build the image:
docker build -t telegram-mcp:latest .
Run with Compose:
docker compose up --build
Run directly:
docker run -it --rm \
-e TELEGRAM_API_ID="YOUR_API_ID" \
-e TELEGRAM_API_HASH="YOUR_API_HASH" \
-e TELEGRAM_SESSION_STRING="YOUR_SESSION_STRING" \
telegram-mcp:latest
For multiple accounts, pass variables such as TELEGRAM_SESSION_STRING_WORK and TELEGRAM_SESSION_STRING_PERSONAL.
The implementation is split into a small compatibility entrypoint and modular package code:
main.py # historical entrypoint and compatibility exports
telegram_mcp/runtime.py # shared MCP setup, account routing, validation, file safety
telegram_mcp/runner.py # application startup
telegram_mcp/tools/ # tool modules grouped by domain
sanitize.py # output sanitization helpers
tests/ # pytest suite
Run tests:
uv run pytest
Run tests with coverage:
uv run pytest --cov --cov-report=term-missing --cov-report=xml
Coverage is configured in pyproject.toml with an 80% minimum gate for deterministic unit-testable core modules. GitHub Actions runs the same coverage command and uploads coverage.xml.
Run formatting checks:
uv run black --check .
uv run flake8 .
.env, session strings, or .session files.telegram-mcp package name on PyPI is not controlled by this project.
Avoid PyPI-based telegram-mcp install commands unless ownership changes and
the package is verified.telegram-mcp distributions without a source checkout or direct git/file
install record. That guard cannot run when the unrelated PyPI package itself
is launched, so use clone-based or explicit git installs.TELEGRAM_PROXY_* is configured, Telegram traffic is routed through the
configured SOCKS/HTTP/MTProxy proxy instead.Telegram messages, display names, chat titles, and button labels are untrusted content. The server mitigates prompt-injection risk with:
sanitize_user_content(), sanitize_name(), and sanitize_dict() for control-character stripping, invisible-character stripping, and length limits.TELEGRAM_SESSION_STRING, TELEGRAM_SESSION_NAME, or suffixed multi-account variants.uv run session_string_generator.py --qr outside
the MCP server when you can scan from an existing Telegram app, or
uv run session_string_generator.py --phone when you need phone-code login.
Then set TELEGRAM_SESSION_STRING in .env. The MCP server does not perform
interactive phone-code login over stdio.TELEGRAM_API_ID and TELEGRAM_API_HASH at my.telegram.org/apps.mcp_errors.log.uv syncuv run pre-commit install --hook-type pre-commit --hook-type pre-pushuv run pre-commit run --all-filesuv run pre-commit run --hook-stage pre-push --all-filesThis project is licensed under the Apache 2.0 License.
Maintained by @chigwell and @l1v0n1. PRs welcome.
An MCP server for Inbox Zero. Adds functionality on top of Gmail like finding out which emails you need to reply to or need to follow up on.
An MCP server for searching your personal WhatsApp messages, contacts and sending messages to individuals or groups
The most powerful MCP server for Slack Workspaces.
MCP server that connects to Microsoft Office and the whole Microsoft 365 suite using Graph API (including Outlook, mail, files, Excel, calendar)
MCP Server for Integrating LINE Official Account
MCP server to interact with browser-based meeting platforms (Zoom, Teams, Google Meet). Enables AI agents to send bots to online meetings, gather live transcripts, speak text, and send messages in the meeting chat.