Telegram MCP Server
Telegram MCP server scaffold that logs in to Telegram using a QR code before starting the MCP server.
This project uses:
telethonto connect to Telegramqrcodeto print a login QR code in the terminalpython-dotenvto load private keys from a local.envfile
مهم: لا ترفع مفاتيح Telegram الخاصة بك أو ملف
.sessionإلى GitHub.
Requirements
- Python 3.10+
- Telegram account
- Telegram API credentials from https://my.telegram.org
1. Get Telegram API ID and API Hash
- Open https://my.telegram.org
- Login with your Telegram phone number
- Go to API development tools
- Create an app
- Copy:
api_idapi_hash
2. Install dependencies
Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
Install packages:
pip install telethon qrcode python-dotenv
3. Configure environment variables
Copy the example file:
cp .env.example .env
Edit .env:
TELEGRAM_API_ID=123456
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_SESSION=telegram_mcp
Replace the values with your real Telegram credentials.
4. How QR login works
When the server starts, it checks if your Telegram session is already authorized.
- If authorized, it continues normally.
- If not authorized, it prints a QR code in the terminal.
To login:
- Open Telegram on your phone
- Go to Settings
- Go to Devices
- Tap Link Desktop Device
- Scan the QR code from the terminal
After scanning, a .session file is created locally. This file keeps you logged in.
5. Run
Current server.py contains the login helper and Telegram client setup.
If your MCP server has a main function, call this before starting MCP:
await before_mcp_start()
Example:
async def main():
await before_mcp_start()
await mcp.run_async()
Then run:
python server.py
Project files
server.py # Telegram client and QR login helper
.env.example # Example environment variables
.gitignore # Prevents secrets/session files from being committed
README.md # Documentation
Security notes
Do not commit or share these files:
.env*.session*.session-journal
These files are ignored by .gitignore.
If you accidentally publish your API hash or session file, revoke/regenerate credentials from Telegram and delete the leaked session.
Troubleshooting
Please set TELEGRAM_API_ID and TELEGRAM_API_HASH
Make sure .env exists and contains valid values:
TELEGRAM_API_ID=your_id
TELEGRAM_API_HASH=your_hash
QR code does not appear correctly
Make sure your terminal supports ASCII output and is wide enough. Try zooming out or using a larger terminal window.
Login asks again every time
Make sure the .session file is not being deleted. The session name comes from:
TELEGRAM_SESSION=telegram_mcp
This creates a local file like:
telegram_mcp.session
Arabic quick start
- ثبت المكتبات:
pip install telethon qrcode python-dotenv
- انسخ ملف البيئة:
cp .env.example .env
-
ضع مفاتيحك داخل
.env. -
شغل السكربت:
python server.py
- امسح QR من تطبيق تيليجرام.
Telegram-mcp
Release files for telegram-desktop-mcp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| telegram_desktop_mcp-0.1.0.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| telegram_desktop_mcp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.4 kB
Release files / telegram_desktop_mcp-0.1.0.tar.gz
| Download URL | telegram_desktop_mcp-0.1.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11a55a136ff621f029162a9ba0ec52aa892548b588861d10d33a7e3412a2e962
|
|
BLAKE2b-256 checksum How to use checksums |
76141a380292d9b6054cbb836e673285b999d418b08c40ba99e6c856a4ab5306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / telegram_desktop_mcp-0.1.0-py3-none-any.whl
| Download URL | telegram_desktop_mcp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15e2464df9887f426bdd1112a383194932e1f4957b4e91a2c6e8959bbd338641
|
|
BLAKE2b-256 checksum How to use checksums |
343266ae23fbfefa99767c88490da8e6906dbc576115d229383bdd765db25856
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency log