q0t-telegram-mcp
A production-quality Telegram MCP server that sends messages via Telegram API, fixing bugs in the reference implementation. Provides tools to list dialogs, read messages, send messages, and mark chats as read.
README
q0t-telegram-mcp
A production-quality Telegram MCP server in Python that actually sends messages.
Why This Exists
The reference Go implementation (@chaindead/telegram-mcp) ships with two bugs that make it silently broken:
tg_sendsaves a draft instead of sending. The implementation callsMessagesSaveDraftinstead ofSendMessage. Messages are stored as unsent drafts — they never arrive at the recipient.- Parameter naming inconsistency. The MCP tool advertises a parameter named
to, but the Go struct uses the JSON tagname. The value passed by the caller is silently ignored and the dialog name is never set.
This project fixes both and builds a reliable, well-tested replacement.
MCP Tools
| Tool | Parameters | Returns | Description |
|---|---|---|---|
tg_me |
— | UserInfo |
Get current Telegram account info |
tg_dialogs |
unread_only (bool, default false), limit (int, default 20), offset (int, default 0) |
List of dialogs — each has id, name, username (or null), unread_count, type flags, last_message, date |
List dialogs (chats, groups, channels) |
tg_dialog |
dialog_id (int), username (str), or name (str) — at least one required; limit (int, default 20), offset (int, default 0) |
List of messages | Get messages from a dialog |
tg_send |
dialog_id (int), username (str), or name (str) — at least one required; text (str) |
{"ok": true} |
Send a message — calls SendMessage, never SaveDraft |
tg_read |
dialog_id (int), username (str), or name (str) — at least one required |
{"ok": true} |
Mark all messages in a dialog as read |
Identifying a dialog
Three selectors are available for tg_dialog, tg_send, and tg_read. Supply at least one:
| Selector | Type | Notes |
|---|---|---|
dialog_id |
int | Numeric ID from tg_dialogs. Most reliable — always refers to exactly one entity. |
username |
str | Telegram @handle. Leading @ is accepted but not required. |
name |
str | Display name (e.g. "Alice"). Least reliable — may match the wrong contact when names are not unique. |
When more than one selector is supplied, priority is: dialog_id > username > name.
Disambiguation: when to use dialog_id vs name
Use name only as a fallback. Two real problems arise when you rely on it:
- Duplicate names. If two contacts are both named "Adilet", name-based resolution scans your dialog list and picks whichever comes first — it may be the wrong person.
- Display names are not Telegram handles. Telethon's
get_entity()cannot resolve a human display name like"Алёна 😍"directly. Under the hood this server scans your cached dialog list for an exact match, which is slower and can fail if the dialog is not yet cached.
Recommended workflow:
- Call
tg_dialogsto get the list. Each entry includes bothidandusername(when the contact has a public handle). - Pass
dialog_id(preferred) orusernametotg_send,tg_dialog, andtg_read. - Fall back to
nameonly when neitheridnorusernameis available (e.g. phone-only contacts without a handle).
Prerequisites
Obtain API credentials from https://my.telegram.org/apps:
| Variable | Where to get it |
|---|---|
TG_APP_ID |
https://my.telegram.org/apps |
TG_API_HASH |
https://my.telegram.org/apps |
Installation & Authentication
No repository clone is needed. Use uvx to run directly from PyPI.
API credentials (TG_APP_ID and TG_API_HASH) can be supplied either as environment variables
or as CLI flags — flags take priority.
First-time authentication
# Via environment variables
TG_APP_ID=your_app_id TG_API_HASH=your_api_hash uvx q0t-telegram-mcp auth --phone +1234567890
# Via CLI flags (no env vars needed)
uvx q0t-telegram-mcp auth --phone +1234567890 --app-id your_app_id --api-hash your_api_hash
With 2FA enabled
# Via environment variables
TG_APP_ID=your_app_id TG_API_HASH=your_api_hash uvx q0t-telegram-mcp auth --phone +1234567890 --password your_2fa_password
# Via CLI flags
uvx q0t-telegram-mcp auth --phone +1234567890 --app-id your_app_id --api-hash your_api_hash --password your_2fa_password
You will be prompted to enter the OTP sent to your Telegram app (or SMS). After successful authentication, a session file is saved locally and subsequent connections reuse it automatically.
Session File Location
The session is stored at .telegram-mcp/session.session relative to whichever directory auth was run from. The MCP server must be started from the same directory so it can find the session.
For Claude Code users, add .telegram-mcp/ to .gitignore to avoid committing credentials:
.telegram-mcp/
Claude Code Configuration
Add the following to your project's .mcp.json:
{
"mcpServers": {
"telegram": {
"command": "uvx",
"args": ["q0t-telegram-mcp"],
"env": {
"TG_APP_ID": "your_app_id",
"TG_API_HASH": "your_api_hash"
}
}
}
}
Claude Code starts the server from your project root, so run auth from the same directory before using the tools.
Publishing to PyPI (Maintainers)
uv build
uv publish
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。