Secure Telegram
io.github.antonorlov由 GitHub 账号 antonorlov 发布v0.3.3更新于 Nov 4, 2026
Telegram MCP server: each AI client gets its own key, scoped to chosen chats. Read-only by default.
概览
本地运行的 Telegram MCP 服务器,为每个 AI 客户端分配独立且默认只读的端点密钥,无需交出完整账号会话。
- 可以做什么
- 读取聊天:列出对话、话题、成员和聊天信息,获取置顶消息,获取与搜索消息,查看媒体信息
- 在严格大小上限内下载媒体到服务器指定的位置
- 发送与编辑消息,并通过会过期的句柄分两步准备和发送本地媒体
- 获得授权后可执行其他写入:保存草稿、删除消息、标记已读、添加表情回应、转发消息
- 每次调用都会按封存策略重新校验端点的权限动词,未授权即失败关闭
- 适用场景
- 当你希望助手读取或操作 Telegram 聊天,但不想把完整账号会话交给客户端时使用。适合不同代理需要不同权限范围的场景,例如仅限某个文件夹的只读工作代理,以及具备写权限的个人代理。
- 运行要求
- 需要 Node.js 20.10 或更高版本,以及来自 my.telegram.org/apps 的 Telegram api_id 和 api_hash。先在终端运行一次 setup 命令完成登录(二维码或手机号加验证码,如启用两步验证还需密码)并创建端点,密钥只打印一次。客户端随后通过 stdio 运行该包,并设置 TELEGRAM_MCP_ENDPOINT_TOKEN 环境变量。使用 PIN 模式时每次重启后需交互解锁。
安装
在 SourceWeft 中
- 打开 控制台中的 Secure Telegram,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
Connect Claude, Cursor, or any MCP client to Telegram — without handing any of them your whole account.
[MCP Server] [Node] [License: MIT] [npm] [CI]
The demo runs against synthetic data — no real Telegram connection, no usable credential.
❌ The usual Telegram MCP setup
- The AI client holds your full account session — every chat, every contact, every write.
- Access is all-or-nothing: your work agent can read your family group.
- The session credential sits in plaintext in a config file or
.env.
✅ With secure-telegram-mcp
- Each AI client gets an endpoint: its own API key, scoped to the chats and folders you pick.
- Read/write verbs are re-checked on every call and fail closed — the tool menu is discovery, not authority.
- The Telegram session is encrypted at rest (AES-256-GCM, scrypt-wrapped keys), machine-bound by default or PIN-protected.
For example:
Every MCP connection authenticates with one endpoint key and receives a scope-bound Telegram adapter for that endpoint's account; without a key, a client can only list the tools. Endpoints can ride different logged-in accounts; endpoints on the same account share one background Telegram connection. Out-of-scope chats are not addressable at all.
Features
- 🔑 Per-endpoint API keys — each AI client gets its own key and scope, pinned to one of your logged-in accounts (one or many); only salted key hashes are stored.
- 📁 Folder-scoped access — bind an endpoint to Telegram folders, chats, or channels; write access is opt-in per endpoint.
- 🔒 Encrypted session at rest — AES-256-GCM envelopes for sessions and policy; PIN, recovery-keyfile, and machine-bound unlock slots.
- 🚦 Anti-ban pacing — per-account token buckets on messages, forwards, and search, plus a circuit breaker that backs the whole account off at the first sign of saturation. Pacing lowers the risk of flood limits; nothing can guarantee against a ban.
- 👤 Human-in-the-loop writes — optional per-endpoint confirmation; requires a client that supports MCP elicitation. On clients that don't, a confirm-writes endpoint fails closed: writes are blocked, never silent.
- ⛔ No raw MTProto surface — no
invokeescape hatch, no model-accessible scope mutation; a CI architecture guard keeps it that way.
Quickstart
Prerequisites: Node.js ≥ 20.10 and Telegram api_id/api_hash from my.telegram.org/apps.
1. Run setup
Setup walks you through, in order:
- Telegram app credentials — the
api_id/api_hashfrom the prerequisite link. - Login method — QR code (scan from a phone that's already logged in) or phone number + code. If your account has two-step verification, setup also asks for that password.
- Session name — press Enter to accept the suggestion (your Telegram username, or
mainif you have none). - PIN or no PIN — default is no PIN (encryption keyed to this machine, nothing to unlock). With a PIN you re-enter it after each reboot; a forgotten PIN is unrecoverable.
- Endpoint — name it, then pick chats/folders in the picker:
ror Space grants read,wwrite,ssaves,?shows the full keymap.
At exit the endpoint's API key is printed once, inside a ready-to-paste client config — copy it before closing the terminal. Hit a snag? See Troubleshooting.
2. Add the endpoint to one MCP client
The token alone selects and authorizes the endpoint — no api_id, api_hash, or PIN material ever goes into client config. Setup prints one block per endpoint; each goes only into its own client — combining entries in one client intentionally grants it the union of the scopes.
Claude Code
Claude Desktop
Add the JSON block above to claude_desktop_config.json (Settings → Developer → Edit Config).
Cursor
Run setup first, then click and replace the placeholder token — or add the JSON block above to ~/.cursor/mcp.json yourself.
VS Code
VS Code prompts for the endpoint token as a masked secret — it never lands in a settings file in plain sight of other extensions' recommendations.
Docker
See Usage and operations → Docker for the setup and stdio-connect containers.
3. Unlock (PIN posture only)
If you kept the default machine-bound protection, skip this — the service starts automatically when a client connects. With a PIN:
Enter the PIN interactively; clients never need it. Multi-client examples, unattended unlock, environment variables, and manual policy editing live in Usage and operations.
Tools
18 tools, gated by 8 permission verbs that are checked at execution time.
Forwarding is two-sided: read on the source chat and forward on the destination. Sending local media is a deliberate two-phase flow — prepare_media returns an opaque, expiring handle for a file inside the confined media root; send_media consumes it. The full catalogue and verb semantics are in Usage and operations.
Security model
- One local service owns the encrypted Telegram session and the sealed policy; MCP shims never open a second Telegram session.
- Every call re-verifies the endpoint token against the current sealed policy, so rotating a key revokes live connections.
- There is no raw MTProto tool and no way for the model to widen its own scope.
- Writes pass ACL → optional human confirmation → quota → audit, in that order, and fail closed at each gate.
- Telegram prose is Unicode-sanitized (control/format characters stripped, length-capped) before it reaches the model; writes, denials, and media egress land in an append-only NDJSON audit log.
- Known limits: the enforcement boundary is your local OS user; endpoint ACLs cannot shrink what the underlying full-account session could do if the process itself were compromised; sanitization cannot neutralize semantic prompt injection.
A read-only endpoint attempting send_message is stopped at the ACL gate and audited — one NDJSON line, no message content:
The client sees only an ACL_DENIED error. An out-of-scope peer denies the same way, with PEER_OUT_OF_SCOPE.
Read the complete threat model — including non-objectives and residual risks — before pointing this at a Telegram account you care about. Component boundaries are in Architecture.
Documentation
- Usage and operations — clients, endpoints, commands, environment variables, Docker, media, tool catalogue.
- Security — threat model, guarantees, residual risks, hardened deployment.
- Architecture — process ownership, trust boundaries, policy lifecycle.
- Example configuration — schema-valid, deliberately unusable placeholders.
Development
The architecture guard rejects forbidden MCP surfaces and unreviewed MTProto request constructors; ESLint enforces dependency boundaries and confines GramJS to the infrastructure layer. See CONTRIBUTING.md before opening a PR.
License
Unofficial project: not affiliated with, endorsed by, or sponsored by Telegram FZ-LLC. "Telegram" is a trademark of Telegram FZ-LLC. This software connects to the Telegram API; each user supplies their own API credentials.
来源:README.md,提交 b6a696a
工具
0版本历史
1- v0.3.3最新Nov 4, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分