telegram-mcp-server

telegram-mcp-server

Enables reading chats, messages, and media and sending messages/files via a Telegram user account (MTProto/Telethon), supporting group history and media that bots cannot access.

Category
Visit Server

README

telegram-mcp-server

MCP-Server für Telegram über einen User-Account (MTProto/Telethon). Liest Chats/Nachrichten/Medien und sendet Nachrichten/Dateien. Läuft lokal über stdio.

Warum User-Account statt Bot?

Ein Bot kann keine Gruppen-Historie und keine vor seinem Beitritt geposteten Medien lesen (und hat ein 20-MB-Download-Limit). Für „hol mir die Bilder aus der Gruppe" braucht es einen User-Client. Session-Datei = voller Account-Zugriff → lokal halten, chmod 600, nie committen.

Setup

  1. API-Credentials auf https://my.telegram.org (API development tools) erzeugen.
  2. Repo installieren (venv + editierbar; Python ≥3.10):
    python3 -m venv .venv
    .venv/bin/pip install -e .
    
  3. Environment setzen:
    export TELEGRAM_API_ID=...
    export TELEGRAM_API_HASH=...
    export TELEGRAM_PHONE=+49...        # nur für den Login nötig
    # optional:
    export TELEGRAM_SESSION="$HOME/.telegram-mcp/telegram.session"
    export TELEGRAM_DOWNLOAD_DIR="$HOME/Downloads/telegram-mcp"
    
  4. Einmalig einloggen (erzeugt die Session-Datei, fragt Code + ggf. 2FA):
    .venv/bin/python -m telegram_mcp_server.login
    

In Claude Code registrieren

claude mcp add telegram \
  -e TELEGRAM_API_ID=... \
  -e TELEGRAM_API_HASH=... \
  -e TELEGRAM_SESSION="$HOME/.telegram-mcp/telegram.session" \
  -- /ABSOLUTER/PFAD/telegram-mcp-server/.venv/bin/telegram-mcp-server

Die -e-Flags sind nötig, weil ein von Claude Code gestarteter MCP-Server die Shell-exports aus dem Setup NICHT erbt. Alternativ die env-Sektion in der MCP-Konfiguration nutzen. TELEGRAM_DOWNLOAD_DIR optional per weiterem -e setzen. Nach dem Registrieren eine neue Claude-Code-Session starten, damit der Server erscheint.

Tools

Tool Zweck
get_me Whoami / Session-Check
list_chats(query?, limit) Chats auflisten (Gruppe/Kanal/DM)
get_messages(chat, limit, before_id?, search?) Nachrichten eines Chats lesen
search_messages(query, chat?, limit) Nachrichten suchen (global oder im Chat)
download_media(chat, message_ids[], dest_dir?) Medien gezielter Nachrichten laden
get_recent_media(chat, limit, kind?, dest_dir?) Letzte N Medien eines Chats laden
send_message(chat, text) Textnachricht senden
send_file(chat, file_path, caption?) Datei/Bild senden

chat akzeptiert Chat-id, @username oder (Teil-)Titel; bei mehrdeutigem Titel kommt ein Fehler mit den Treffern statt einer Rate-Auflösung.

get_messages/search_messages liefern pro Nachricht auch chat_id mit — Treffer aus der globalen Suche sind damit direkt in weiteren Tool-Aufrufen (z.B. download_media) verwendbar.

Entwicklung / Tests

python3 -m venv .venv && .venv/bin/pip install -e ".[test]"
.venv/bin/python -m pytest tests/ -v

Tests laufen ohne Live-Account (Client wird gemockt).

Smoke-Test (einmalig nach Login, mit echtem Account)

.venv/bin/python -m telegram_mcp_server.login        # 1) Session erzeugen
# 2) get_me / list_chats / get_messages / download_media manuell über den
#    MCP-Client (Claude Code) prüfen:
#    - get_me                         -> zeigt deinen Account
#    - list_chats query="<gruppe>"    -> findet eine deiner Gruppen
#    - get_messages chat=<id> limit=5 -> liefert Nachrichten
#    - search_messages query="..."    -> globale Suche (übt _search_global live aus;
#                                         Treffer müssen chat_id tragen)
#    - get_recent_media chat=<id> kind="photo" -> lädt Fotos nach $TELEGRAM_DOWNLOAD_DIR

Erster echter Integrationstest = ein Medienabruf aus einer deiner Gruppen. Die globale search_messages (ohne chat) ist der einzige Pfad, der _search_global/SearchGlobalRequest real ausführt — im Smoke-Test nicht überspringen.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured