tgmcp
An MCP server that automates a single Telegram user account via the Telegram user API, enabling chat listing, reading/sending messages, searching, and additional actions through natural language.
README
tgmcp
MCP server that automates one Telegram user account through the Telegram user API (mtcute). It is not a bot.
The public tool list is an inbox: list chats, read, send, and search. Everything else lives in an action catalog behind telegram search / describe / invoke. Empty catalog search shows inbox and lookup actions only. Join, leave, and profile edits stay hidden until you search for them.
tgmcp runs on Node.js 20 or newer. npx and bunx both work.
Install
One-shot (no global install):
npx @watzon/tgmcp login
bunx @watzon/tgmcp login
Global install:
npm install -g @watzon/tgmcp
# or
bun add -g @watzon/tgmcp
That puts tgmcp on your PATH.
From a clone:
git clone https://github.com/watzon/tgmcp.git
cd tgmcp
bun install
bun run login
Sign in
- Create an application at my.telegram.org and copy
api_id/api_hash. - Run
tgmcp login(orbun run loginin a clone). - Finish the page that opens on
127.0.0.1. The hash, login code, and 2FA stay in the browser. They never enter the model.
Both login paths write storage/credentials.json (api id, hash, owner id) and the mtcute session under the data home.
[!TIP] Local browser login is the one you want. On a remote host, start the MCP server unsigned and use the
authtool:set_credentials, thensend_code/sign_in, orstart_qr. You can also callauthwithbrowserand open that URL on the machine that runs tgmcp (SSH port-forward if you are not on that host).
Optional: put TELEGRAM_API_ID and TELEGRAM_API_HASH in .env in the data home. Env values override the credentials file.
Check the session with tgmcp status.
Run the MCP server
tgmcp
# same thing:
tgmcp serve
The process speaks MCP on stdio. Point your host at that command. Host snippets for Claude Code, Cursor, OpenClaw, and Hermes are in agent instructions.
Agent instructions
<details> <summary>Read this if you are an agent installing tgmcp</summary>
You are installing tgmcp. It is an MCP server that automates one Telegram user account through the Telegram user API. It is not a bot. Do not ask for a bot token.
Requirements
- Node.js 20 or newer on the machine that will run the server. Prefer
npx -y @watzon/tgmcp.bunx @watzon/tgmcpalso works. - An
api_idandapi_hashfrom my.telegram.org. The user already has these, or they get them there.
Do not clone the repo unless the user asked for a development checkout.
Wire the host
Generic stdio, Claude Code, Cursor, and OpenClaw:
{
"mcpServers": {
"telegram": {
"command": "npx",
"args": ["-y", "@watzon/tgmcp"]
}
}
}
bunx @watzon/tgmcp is the same command if you prefer Bun.
Hermes:
mcp_servers:
telegram:
command: "npx"
args: ["-y", "@watzon/tgmcp"]
Default data home is ~/.tgmcp. Set TGMCP_HOME in the host env only if the user wants a different directory. From a clone, bun src/index.ts with cwd set to the repo still works.
Sign in
- On the same machine as the server, run
npx @watzon/tgmcp login(ortgmcp loginif it is installed). A page binds to127.0.0.1. The user finishes it in a browser. Do not ask them to pasteapiHash, the login code, or a 2FA password into chat. - On a remote host, start the server unsigned. Call
authwithcommand: "status"first. Thenset_credentials, thensend_code/sign_in, orstart_qr. Preferauthcommand: "browser"if they can open or port-forward that URL. - Never echo
apiHash, login codes, or 2FA passwords in tool results, logs, or later messages.
After it is connected
- Call
authwithcommand: "status"once per session before other tools. The tool list does not change with auth state. - Use
list_chatsto get a numericchatId. Pass thatchatIdon every chat-scoped call. Groups and channels are negative. - Inbox tools:
list_chats,read_messages,send_message,search_messages. - Longer tail goes through
telegramwithcommandsearch,describe, orinvoke. Empty search lists inbox and lookup actions only. Searchjoin,leave,folder, orprofilefor account-admin actions.
Example:
telegram { command: "search", query: "pin topic" }
telegram { command: "describe", name: "pin" }
telegram { command: "invoke", name: "pin", params: { chatId: "-100123", messageId: 42 } }
</details>
Tools
| Tool | Role |
|---|---|
list_chats |
Resolve a title to a numeric chatId |
read_messages |
Recent history. Does not mark read |
send_message |
Send or reply in a chat |
search_messages |
Find messages inside one chat |
telegram |
Catalog knife: search, describe, invoke |
auth |
Sign-in. Prefer browser locally. Use set_credentials + phone/QR on a remote host. |
Chat-scoped work needs an explicit numeric chatId. Use list_chats first.
Example catalog flow:
telegram { command: "search", query: "pin topic" }
telegram { command: "describe", name: "pin" }
telegram { command: "invoke", name: "pin", params: { chatId: "-100123", messageId: 42 } }
Empty telegram search lists inbox and lookup actions (react, edit, pin, media, user info, topics). Search for join, leave, folder, or profile when you need those.
Data home
Published runs store state in ~/.tgmcp unless you say otherwise:
| Path | What |
|---|---|
tgmcp.config.json |
Denylist, rate limits, relative paths |
storage/credentials.json |
api id, hash, owner id (mode 0600) |
storage/session |
mtcute SQLite session |
data/tgmcp.db |
Append-only action ledger |
data/downloads/ |
Saved media |
Resolution order:
TGMCP_HOMEif set- The current directory, if it already has
tgmcp.config.json(this is how a clone works) ~/.tgmcp, created on first run
Copy .env.example to .env in that directory if you want env overrides.
Config
tgmcp.config.json looks like this:
{
"ownerId": "",
"telegram": {
"sessionPath": "storage/session",
"credentialsPath": "storage/credentials.json"
},
"ledgerPath": "data/tgmcp.db",
"downloadsDir": "data/downloads",
"denylist": [],
"rateLimits": {
"perChatMs": 2000,
"globalPerHour": 120
}
}
ownerId is filled in after the first login. If you set it yourself, tgmcp refuses to start as a different account.
Safety
- Mutations go through a denylist, per-chat spacing, a global hourly cap, one flood-wait retry, and an append-only ledger.
- Secrets stay on disk or in
.env. The MCP transport is stdio, so logs go to stderr only. - This process does not run an agent loop and does not ingest incoming chats on its own.
- Treat
storage/sessionlike a logged-in browser profile. Do not commit it.
Development
bun install
bun test
bun run typecheck
bun run build
node dist/cli.js help
bun run login
bun src/index.ts
CONTEXT.md has the project vocabulary and boundaries.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。