Telegram MCP Server & CLI
A free, open source Telegram MCP server and CLI that lets Claude Code, Codex, Cursor and other AI agents read, search and answer your real Telegram chats.
This free Telegram MCP server and CLI gives your AI real access to your real Telegram account: your chats, their history, search, contacts and media. It catches you up on your chats, searches years of history for the thing you half remember, and sends and forwards messages as you.
It's one install with 2 ways in. Claude, Codex, Cursor or any other MCP app calls its 13 tools for you, and the same tools work as a CLI that agents like Claude Code, Codex and OpenCode run, or that you type yourself.
Here's what the Telegram MCP server and CLI is, how to set it up in each app, and every tool it has.
What is the Telegram MCP server & CLI?
The Telegram MCP server & CLI is a free, open source program that lets AI agents read, search and answer your Telegram chats for you, in 2 ways. The MCP server is what an AI app like Claude, Codex or Cursor connects to, through MCP (Model Context Protocol), the open standard AI apps use to call outside tools.
You ask in plain language. Your AI picks the right tool, and the server makes the call to Telegram's own servers, logged in as you.
The CLI is the same program as commands. telegram-cli search --query "wifi password" runs the same code your AI runs when you ask for something someone sent you, whether an agent like Claude Code runs it or you do.
What can you ask it?
Once it's set up, you ask the way you'd ask an assistant. These are real prompts it handles:
Try askingWhat did I miss in the group chats while I was asleep?
Search every chat for the wifi password someone sent me last year.
Find the last thing Sarah sent me about the invoice and reply that I'll look tonight.
Which conversations have unread messages, and which actually need an answer?
Save the PDF that Tom sent me this morning to my desktop.
Send myself a note in Saved Messages with these three links.
The second one shows why this is useful. Searching a decade of chats for something you half remember is what this does better than scrolling.
How to install the Telegram MCP server
Pick your app in the box at the top of this page. You log in once to get your session string, then paste 3 values into your app's config.
Watch out: Use one session string per computer. If 2 computers or 2 servers use the same one at once, Telegram cancels it everywhere, and you log in again on each.
Set up Telegram
There are 3 values. The first 2 identify the app, and the third is you.
TELEGRAM_API_ID and TELEGRAM_API_HASH in your terminal.npx -y @thenavidm/telegram-mcp-cli login.TELEGRAM_SESSION in your app's config.The session string is your login, not a limited token. Anyone holding it can read every chat and send as you, so keep it in your app's config and out of anything you share. To revoke it, end the session in Telegram under Settings, then Devices.
Check that it works
Run the doctor. It checks the 3 values, connects, and says which account it's signed in as.
npx -y @thenavidm/telegram-mcp-cli doctorIf the server starts and then exits, the session string is usually wrong or was revoked. Run login again.
Use the Telegram CLI
The CLI is the same 13 tools as commands. AI agents that run commands, like Claude Code, Codex and OpenCode, use it on their own, and you can type the same commands in a terminal or a script.
Every tool name becomes a command with dashes, so list_chats runs as telegram-cli list-chats.
npm install -g @thenavidm/telegram-mcp-cli
telegram-cli
telegram-cli list-chats --limit 10
telegram-cli search --query "invoice"
telegram-cli history --peer me --limit 5The bare telegram-cli lists every command, and telegram-cli <command> --help shows what a command takes. Deleting messages asks for --confirm first, and it's off entirely until you set TELEGRAM_ALLOW_DESTRUCTIVE=1.
These flags work on every command:
| Flag | What it does |
|---|---|
--json | Prints JSON |
--compact | Prints the JSON on one line |
--agent | Machine mode: JSON, compact, no prompts and no color |
--select a,b.c | Keeps only those fields, and a dotted path goes deeper |
--confirm | Lets a write that asks first go ahead |
A script can branch on the exit code:
| Exit code | What it means |
|---|---|
| 0 | It worked |
| 2 | The command was typed wrong, or a write needed --confirm |
| 3 | It wasn't found |
| 4 | Telegram rejected the credentials |
| 5 | Telegram's API failed |
| 7 | You hit a rate limit, so wait and try again |
| 10 | Nothing is set up yet |
MCP server or CLI: which one?
Both are the same program with the same 13 tools. The difference is when your AI pays for them, in the tokens it reads.
- MCP server
- 2,800 tokens
- CLI
- Nothing
- MCP server
- 130 tokens
- CLI
- Nothing
- MCP server
- Nothing more, or in Claude Code the tools it picks
- CLI
- 2,600 tokens, once
- MCP server
- 56,000 tokens
- CLI
- 2,600 tokens
- MCP server
- Yes
- CLI
- No, there's no terminal there
- MCP server
- No
- CLI
- Yes
An app that loads every tool up front sends the full list with every message, whether you mention Telegram or not. Claude Code doesn't by default: its tool search sends only the tool names and the server's instructions, and loads a tool's full definition when your AI reaches for it.
The CLI costs nothing until Telegram comes up. Then your agent reads its skill file once and runs the commands it needs. With the skill added, Claude Code also lists its one-line description with every message, about 130 tokens.
When the whole conversation is about Telegram, the gap closes. Then the MCP server is the better experience, because you ask in plain language and your AI never has to look up a command.
How to spend less
In Claude Code, leave tool search on, which it is unless you've set ENABLE_TOOL_SEARCH=false.
Keep the default profile. TELEGRAM_TOOLS=full adds the other 61 tools to your AI's list and costs about 14,400 tokens a message in an app that loads every tool. The CLI reaches all 74 either way. TELEGRAM_READ_ONLY=1 cuts the list to the 7 reading tools.
Or install the CLI and connect the server later, on the days it earns its place. Every tool stays in reach, and the standing cost drops to nothing.
Every number here was measured on September 27, 2026 in Claude Code 2.1.257 with Claude Opus 5. It's the same one-line prompt with and without the server connected, once with tool search off so every tool loads, and once with Claude Code's default. The skill was measured the same way, and other apps and models count tokens a little differently.
13 tools by default, 74 in reach
The server shows your AI 13 tools: the ones that get used, for reading, searching, sending and media. A model picks the right tool far more reliably from 13 than from 74, and the list costs much less.
The other 61, for contacts, groups, admin, folders, polls, reactions and privacy, are always there as CLI commands, where an unused one costs nothing. Set TELEGRAM_TOOLS=full to show them all to your AI too, or read for the reading tools only.
Every Telegram tool
The 13 tools of the default profile, grouped the way the repo groups them. 7 only read, and 6 send, edit, forward or mark as read.
Chats
list_chats- What it does
- Recent conversations, newest first.
- Kind
- Reads
get_chat- What it does
- Details of a single chat: name, kind, username, member count and description where the chat has them.
- Kind
- Reads
Messages
history- What it does
- Messages from one chat, newest first.
- Kind
- Reads
search- What it does
- Search message text, either inside one chat or across the whole account when no peer is given.
- Kind
- Reads
send- What it does
- Send a message to a chat.
- Kind
- Writes
edit- What it does
- Change the text of a message you sent.
- Kind
- Writes
delete- What it does
- Delete one or more messages.
- Kind
- Asks first
mark_read- What it does
- Clear the unread count on a chat.
- Kind
- Writes
forward- What it does
- Forward messages from one chat into another.
- Kind
- Writes
Media
download_media- What it does
- Save the photo, video, document or voice note attached to a message, and return the local path.
- Kind
- Reads
send_file- What it does
- Send a local file to a chat, with an optional caption.
- Kind
- Writes
Your account
whoami- What it does
- The Telegram account this session is signed in as.
- Kind
- Reads
resolve- What it does
- Turn a @username, phone number or numeric id into a chat you can act on.
- Kind
- Reads
Is the Telegram MCP server safe?
Writes work from the start, because answering your chats is the point. A message goes to a real person as you, so read what your AI is about to send.
delete can remove a message for everyone in the chat, so it's off until you set TELEGRAM_ALLOW_DESTRUCTIVE=1, and then it asks for a confirm check, marked Asks first in the tool tables above.
Make it read-only
Set TELEGRAM_READ_ONLY=1 and the write tools are never registered, so your AI can't see them, leaving 7.
Keep a log of every write
Set TELEGRAM_AUDIT_LOG to a file path. The server writes one line per attempted write, allowed or blocked.
Watch out: Message text is written by other people and reaches your AI as input. The server strips hidden characters used to smuggle instructions, but treat what's in a chat as data, and give an agent you don't fully trust TELEGRAM_READ_ONLY=1.
Your data
There's no server of ours in between. The only calls go to Telegram's own servers, and there's no account to create and no tracking.
The session string lives wherever you put it, and the server never writes it to disk. Message text is held in memory for one call. Media goes where you ask, and the audit log is written only when you set TELEGRAM_AUDIT_LOG.
Several accounts
Add a second account as TELEGRAM_SESSION_WORK, or any label you like, with its own session string from its own login. Every tool then takes account to pick one.
Telegram MCP server settings
The first 3 are required. The rest are optional, as environment variables in your app's config.
TELEGRAM_API_ID- Default
- none
- What it does
- Holds the api_id from my.telegram.org
TELEGRAM_API_HASH- Default
- none
- What it does
- Holds the api_hash from the same page
TELEGRAM_SESSION- Default
- none
- What it does
- Holds the session string
loginprints
TELEGRAM_TOOLS- Default
core- What it does
- Picks the profile:
core,fullorread
TELEGRAM_READ_ONLY- Default
- off
- What it does
1never registers a write tool
TELEGRAM_ALLOW_DESTRUCTIVE- Default
- off
- What it does
1allowsdeleteat all
TELEGRAM_AUDIT_LOG- Default
- none
- What it does
- Names a file that gets one line per attempted write
TELEGRAM_SESSION_<LABEL>- Default
- none
- What it does
- Adds another account, like
TELEGRAM_SESSION_WORK
Troubleshooting
Run the doctor first. It names the step that failed and the fix.
| What you see | What to do |
|---|---|
| Exit code 10, not configured | One of the 3 values is missing. The doctor names it |
| Exit code 4, auth | The session was revoked or cancelled. Run login again |
| Exit code 7, a flood wait | Telegram is rate limiting you. Wait the seconds it says, and don't retry in a loop |
| The session was cancelled on every computer | Two places used the same session string at once. Log in separately on each |
delete refuses | That's by design. Set TELEGRAM_ALLOW_DESTRUCTIVE=1 and pass --confirm |
If the server doesn't show up in your app at all, run the command your app runs, in a terminal, and read the error.
More free tools for staying in touch
Make a QR code that opens a chat, or tag the links you send so you can see which ones people open.
Telegram MCP Server FAQs
Here are the questions people ask most about the Telegram MCP server and CLI.
The Telegram MCP server & CLI is a free, open source program that lets an AI app like Claude, Codex or Cursor read, search and answer your Telegram chats.
It has 13 tools for your chats, their history, search, sending and media, and the same tools run as a CLI that agents like Claude Code and Codex use, or that you type yourself.
An MCP server is a standard way to give an AI app real access to a tool, so it can act instead of guessing.
MCP stands for Model Context Protocol, and Claude, Codex, Cursor and many other AI apps speak it.
The Telegram CLI is the same program as the Telegram MCP server, run as commands.
AI agents like Claude Code, Codex and OpenCode run them for you, and you can type them in a terminal or a script.
Use the Telegram MCP server in an AI app with no terminal, like Claude Desktop's chat, and the CLI in a terminal, a script or a cron job.
In an AI app that can run commands, like Claude Code, Codex or Cursor, the CLI is the lighter choice, because it costs nothing until it runs.
Yes, the Telegram MCP server is free and open source under the MIT license, and Telegram's API is free.
The only thing you pay for is your own AI app.
No, it logs in as you, like a Telegram app on a new device, so it reads your real chats.
A bot only sees chats it was added to.
Telegram's terms allow user apps, and reading and answering your own chats is what this is built for.
Bulk or spammy sending through a user account is what gets accounts limited.
The same session string is running in 2 places at once, and Telegram cancels it everywhere.
Log in separately on each computer.
A model picks the right tool far more reliably from 13 than from 74, and the list costs less.
The other 61 are always there as CLI commands, and TELEGRAM_TOOLS=full shows them to your AI too.
The Telegram MCP server works with any app that speaks MCP.
That includes Claude Code, Claude Desktop, Codex, Cursor, VS Code, GitHub Copilot CLI, Gemini CLI, OpenCode, OpenClaw, Antigravity and Hermes.
Navid.me is reader-supported. When you buy through links on this site, I may earn an affiliate commission. Learn more.
More MCP servers & CLIs
The most actionable AI newsletter for founders
Every week, get proven AI strategies, curated tools, and step-by-step systems to grow your audience, create better content, and build a profitable creator business.
No fluff, no filler, no BS. Just five minutes each week that might level up your online business and life.
P.S. Sign up now to get free access to my ultimate AI tools guide for creators.


