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
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.