telegram-mcp-server
A read-only MCP server that lets AI agents read personal Telegram chats from an allowlist of folders, with no send/edit/delete capability.
README
telegram-mcp-server
A local, read-only, folder-scoped MCP server that lets an AI agent (Claude Code, etc.) read your personal Telegram chats — but only the chats inside an allowlist of Telegram folders. No send/edit/delete capability exists.
Built for a common use case: let an agent read your client/lead conversations and pull out tasks, without giving it the keys to your whole Telegram.
⚠️ This logs in as your personal Telegram account via the official MTProto API (GramJS). Automating a user account is a grey area under Telegram's ToS; the risk is low for read-only use but not zero. Use on your own account.
How it stays safe
- Read-only. The server registers four tools, all read-only. There is no tool that can send, edit, or delete anything.
- Folder-scoped. Only chats inside the folders listed in
config.json(allowedFolders) are reachable. Every tool resolves the requested chat against that allowlist and refuses anything outside it. Chats in your other folders (family, personal, etc.) are physically unreachable. - Secrets stay local.
api_id/api_hashlive inconfig.json(gitignored). The session string — which grants full account access — is stored in the macOS Keychain, never on disk, never in git.
Requirements
- Bun (runs the TypeScript directly)
- macOS (uses the Keychain via the
securityCLI for session storage) - A Telegram account, and an
api_id/api_hashfrom https://my.telegram.org
Setup
# 1. install
bun install
# 2. configure
cp config.example.json config.json
# edit config.json: apiId, apiHash, allowedFolders (exact Telegram folder names)
# 3. log in (QR — the reliable method; see note below)
bun run qr
# On your phone: Telegram -> Settings -> Devices -> Link Desktop Device -> scan the QR
# 4. verify which folders/chats resolved
bun run folders
# 5. register with your MCP client (Claude Code example, user scope):
claude mcp add telegram -s user -- bun run "$(pwd)/src/server.ts"
Why QR login, not the SMS/app code
bun run login (phone + code) often fails: Telegram frequently accepts the
SendCode request and reports "code sent to app", but never actually delivers
the code (and offers no SMS fallback) for third-party API logins — especially
with a freshly created api_id. bun run qr sidesteps this entirely: the
login is approved from your already-authorized phone, so no code delivery is
needed. Use QR first.
Tools
| Tool | What it does |
|---|---|
tg_list_folders |
List allowed folders + resolved chat counts |
tg_list_chats |
List chats in allowed folders (optionally one folder) |
tg_read_chat |
Recent messages from one allowed chat |
tg_search |
Search messages across allowed chats / one folder / one chat |
Troubleshooting
- A folder shows 0 chats → its name in
config.jsondoesn't match Telegram exactly. Runbun run folders; if needed, temporarily inspect all folder titles (the diagnose output lists matched ones). Names are case-insensitive but must otherwise match (watch for typos / emoji / extra words). FLOOD_WAIT_N→ too many login attempts; wait N seconds. Don't spam retries — each one extends the window.CHANNEL_PRIVATEskipped → a private channel you've left/been removed from can't be resolved; it's skipped, harmless.- Login code never arrives → use
bun run qr(see above).
Files
src/
server.ts MCP server (4 read-only tools)
client.ts GramJS client + folder allowlist (the privacy boundary)
qr-login.ts QR-code login (recommended)
login.ts phone+code login (fallback, with 'sms' resend)
config.ts loads config.json
keychain.ts session string <-> macOS Keychain
diagnose.ts 'bun run folders' — show allowed folders + counts
probe.ts 'bun run probe +NUMBER' — dump raw SendCode response
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。