Skip to main content

Telegram MCP Server

Telegram MCP server scaffold that logs in to Telegram using a QR code before starting the MCP server.

This project uses:

  • telethon to connect to Telegram
  • qrcode to print a login QR code in the terminal
  • python-dotenv to load private keys from a local .env file

مهم: لا ترفع مفاتيح Telegram الخاصة بك أو ملف .session إلى GitHub.

Requirements

1. Get Telegram API ID and API Hash

  1. Open https://my.telegram.org
  2. Login with your Telegram phone number
  3. Go to API development tools
  4. Create an app
  5. Copy:
    • api_id
    • api_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:

  1. Open Telegram on your phone
  2. Go to Settings
  3. Go to Devices
  4. Tap Link Desktop Device
  5. 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

  1. ثبت المكتبات:
pip install telethon qrcode python-dotenv
  1. انسخ ملف البيئة:
cp .env.example .env
  1. ضع مفاتيحك داخل .env.

  2. شغل السكربت:

python server.py
  1. امسح 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)

Source distribution for telegram-desktop-mcp 0.1.0
File Size Uploaded
telegram_desktop_mcp-0.1.0.tar.gz 4.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for telegram-desktop-mcp 0.1.0
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page