telegram-mcp
Enables AI agents to interact with a user's Telegram account: list chats, read history, search, and send messages through Telegram's MTProto API.
README
Telegram MCP Server
A local Model Context Protocol server that gives an AI agent — Claude Code, Claude Desktop, or any MCP client — controlled access to your own Telegram account: list chats, read history, search, and send messages, through Telegram's MTProto API.
Built with Python + Telethon. Runs entirely on your machine; your login session never leaves it.
Why
Telegram's Bot API can't see your existing chats — a bot is a separate identity and only receives messages explicitly sent to it. To let an agent work with your real conversations you need the MTProto client API, authenticated as your user account. This project wraps that in a small, focused MCP server so any MCP-capable agent can read and act on your Telegram — without you writing glue code each time.
Features
- 6 tools covering the common read/write actions (see below)
- Local-only — credentials and session live in a git-ignored
.env; nothing is sent anywhere except Telegram - Standard MCP stdio server — works with Claude Code, Claude Desktop, or any MCP client
- One-time login — interactive script stores a reusable session string; no re-auth on every run
- Small and readable — ~150 lines of Python, easy to audit and extend
Tools
| Tool | Description |
|---|---|
get_me() |
Return the connected account (sanity check) |
list_chats(limit=20) |
Your most recent conversations |
get_history(chat, limit=30) |
Recent messages from one chat |
search_messages(chat, query, limit=30) |
Search within one chat |
search_all(query, limit=30) |
Search across all your chats at once |
send_message(chat, text) |
Send a message as you |
chat accepts a username (@name), numeric id, phone number, t.me link, or the chat's display name.
Quickstart
1. Install
git clone https://github.com/<you>/telegram-mcp.git
cd telegram-mcp
python -m venv .venv
# Windows
.venv\Scripts\pip install -r requirements.txt
# macOS / Linux
.venv/bin/pip install -r requirements.txt
2. Get API credentials
Go to my.telegram.org → API development tools → create an app → copy the api_id and api_hash.
3. Log in (one time)
# Windows
.venv\Scripts\python login.py
# macOS / Linux
.venv/bin/python login.py
Enter your api_id/api_hash, phone number (with country code), and the login code Telegram sends you (plus your 2FA password if set). This writes a reusable session to .env.
4. Register with your MCP client
Claude Code:
claude mcp add telegram --scope user -- "/abs/path/.venv/bin/python" "/abs/path/server.py"
Claude Desktop — add to claude_desktop_config.json:
{
"mcpServers": {
"telegram": {
"command": "/abs/path/.venv/bin/python",
"args": ["/abs/path/server.py"]
}
}
}
Restart your client and the telegram tools are available.
Example
You: Search all my Telegram chats for "invoice" and summarize what's outstanding.
The agent calls search_all("invoice"), which returns:
[
{
"id": 84213,
"date": "2026-07-02T09:14:00+00:00",
"chat": "Acme Billing",
"from": "Acme Billing",
"text": "Invoice #204 is due on the 10th."
}
]
…and the agent summarizes from there.
How it works
login.py authenticates once via Telethon and saves a StringSession to .env. server.py builds a FastMCP stdio server, connects lazily on the first tool call, verifies the session is authorized, and maps each tool to a Telethon call (iter_dialogs, iter_messages, SearchGlobalRequest, send_message). Results are returned as plain JSON-serializable dicts.
Security
- Keep
.envprivate. TheSESSION_STRINGis equivalent to being logged in as you. It is git-ignored — never commit it. - Everything runs locally; the server talks only to Telegram's servers.
- Automating a user account is a Telegram ToS gray area. Reading your own account is generally fine; keep sending human-paced and avoid bulk/spam activity to stay clear of account limits.
Limitations
- No automated test suite yet — verified manually against a live account.
search_messagessearches a single chat; usesearch_allfor a global search.- Display-name resolution falls back to scanning your dialog list, so exact usernames/ids are faster and more reliable.
License
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.