@teletele/tg-mcp
by PunkSlerf
README.md
<p align="right">
<strong>English</strong> | <a href="./README.zh-CN.md">简体中文</a>
</p>
<div align="center">
<a href="https://bot.teletele.lol/open-source">
<img src="./docs/assets/logo-bot.svg" alt="Teletele MCP Logo" width="88" height="88" />
</a>
<h1>Teletele MCP & Plugin SDK</h1>
<p>
<strong>Zero-trust, local-first Telegram MCP server & plugin SDK for Claude Desktop, Cursor, Codex CLI, and custom AI agents.</strong><br />
Keep your Telegram MTProto session locked in a local <strong>AES-256-GCM</strong> vault — zero cloud relays, zero session uploads.
</p>
<p>
<a href="https://github.com/PunkSlerf/teletele-mcp/releases/latest"><img src="https://img.shields.io/github/v/release/PunkSlerf/teletele-mcp?style=flat-square&label=release&color=10b981" alt="Latest Release" /></a>
<a href="https://github.com/PunkSlerf/teletele-mcp/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/PunkSlerf/teletele-mcp/ci.yml?branch=main&style=flat-square&label=CI" alt="CI Status" /></a>
<a href="./LICENSE"><img src="https://img.shields.io/badge/License-MIT-31cf76?style=flat-square" alt="MIT License" /></a>
<img src="https://img.shields.io/badge/MCP-JSON--RPC%202.0-38bdf8?style=flat-square" alt="MCP JSON-RPC 2.0" />
<img src="https://img.shields.io/badge/Node.js-%3E%3D22-5B4BE7?style=flat-square&logo=node.js&logoColor=white" alt="Node >= 22" />
<img src="https://img.shields.io/badge/Python-%3E%3D3.11-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python >= 3.11" />
<img src="https://img.shields.io/badge/Vault-AES--256--GCM-a855f7?style=flat-square" alt="AES-256-GCM Vault" />
</p>
<p>
<a href="#5-minute-quickstart">Quickstart</a> ·
<a href="#9-mcp-tools-reference">9 MCP Tools</a> ·
<a href="#teleteleplugin-sdk-developer-guide">Plugin SDK</a> ·
<a href="#zero-trust-local-security-architecture">Security Model</a> ·
<a href="#open-source-vs-teletele-bot-desktop">Teletele Bot Desktop</a>
</p>
</div>
<br />
<p align="center">
<img src="./docs/assets/mcp-claude-demo.png" alt="Claude Desktop invoking tg_search_messages and tg_save_draft via @teletele/tg-mcp with local AES-256-GCM Vault" width="100%" />
</p>
---
## Why Teletele MCP?
Most Telegram agent integrations ask you to upload raw `.session` files to a hosted proxy or paste credentials directly into an LLM process. **Teletele MCP** separates untrusted AI clients from your Telegram identity with a strict local loopback boundary:
- **Zero-dependency stdio MCP server (`@teletele/tg-mcp`)** — Pure Node.js (`>= 22`) implementing MCP JSON-RPC 2.0 (`2024-11-05`) with 9 allowlisted Telegram tools and zero third-party runtime dependencies.
- **Local AES-256-GCM encrypted sidecar (`tg-gateway-oss`)** — Single-account FastAPI + Telethon gateway bound to `127.0.0.1:18421` that encrypts both your Telegram `StringSession` and `api_hash` at rest with `0600` key permissions.
- **Human-in-the-loop draft staging** — `tg_save_draft` writes pending replies to `~/.teletele-oss/drafts.json` instead of auto-sending, so agents can triage conversations safely without sending unreviewed outbound messages.
- **Rich media awareness** — `tg_read_messages` and `tg_read_dm` classify photos, voice notes, videos, GIFs, stickers, polls, contacts, locations, and files into structured fallback text so LLMs never lose context on non-text threads.
- **Typed Plugin SDK (`@teletele/plugin-sdk`)** — Author and validate hot-swappable full-stack Feature Plugins (`teletele-feature-v1`) and Business Rule Packs (`teletele-plugin-v1`) for Teletele Bot Desktop Studio.
---
## Packages Included
| Package / Directory | Name | Runtime | Responsibility |
| --- | --- | --- | --- |
| [`packages/tg-mcp-server`](./packages/tg-mcp-server) | `@teletele/tg-mcp` | Node.js `>= 22` | Zero-dependency stdio JSON-RPC 2.0 MCP server (`teletele-tg-mcp` bin) forwarding 9 scoped tools over loopback HTTP. |
| [`packages/plugin-sdk`](./packages/plugin-sdk) | `@teletele/plugin-sdk` | TypeScript / ESM | Strongly typed manifest builders (`defineFeaturePlugin`, `validateFeaturePluginManifest`) for full-stack Feature & Business plugins. |
| [`sidecar/tg-gateway-oss`](./sidecar/tg-gateway-oss) | `teletele-tg-gateway-oss` | Python `>= 3.11` | Single-account FastAPI + Telethon gateway with `SessionVault` (AES-256-GCM), `hmac.compare_digest` token auth, and local draft staging. |
---
## 5-Minute Quickstart
### Pre-Built Release Download (Zero Build)
Prefer not to install `pnpm` or Python build tooling? Download the pre-compiled release artifacts directly from **[GitHub Releases (latest)](https://github.com/PunkSlerf/teletele-mcp/releases/latest)**:
- **Pre-compiled Quickstart Bundle**: `teletele-mcp-v0.1.0-quickstart.tar.gz` (macOS / Linux) or `teletele-mcp-v0.1.0-quickstart.zip` (Windows) — includes built `packages/tg-mcp-server/dist/index.js` ready to register in Claude Desktop / Cursor.
- **Standalone Encrypted Sidecar Binaries** (zero Python install required):
- `tg-gateway-oss-macos-arm64.tar.gz` (macOS Apple Silicon)
- `tg-gateway-oss-linux-x64.tar.gz` (Linux x86_64)
- `tg-gateway-oss-windows-x64.zip` (Windows x64 `.exe`)
- **Offline npm Tarballs & Checksums**: `teletele-tg-mcp-0.1.0.tgz`, `teletele-plugin-sdk-0.1.0.tgz`, and `SHA256SUMS.txt`.
```bash
# Example (macOS Apple Silicon): run the standalone gateway binary without Python
tar -xzf tg-gateway-oss-macos-arm64.tar.gz
export TELETELE_GATEWAY_TOKEN="$(openssl rand -hex 32)"
./tg-gateway-oss-macos-arm64 # binds to 127.0.0.1:18421
```
### Build from Source — Prerequisites
- **Node.js `>= 22`** and **`pnpm`** (`pnpm@10.x`)
- **Python `>= 3.11`** and **`uv`** (or `pip` + `venv`)
- A Telegram account (and optional Telegram API credentials from [my.telegram.org](https://my.telegram.org))
### Step 1 — Clone & Build TypeScript Packages
```bash
git clone https://github.com/PunkSlerf/teletele-mcp.git
cd teletele-mcp
pnpm install && pnpm build
```
This compiles both `@teletele/tg-mcp` (`packages/tg-mcp-server/dist/index.js`) and `@teletele/plugin-sdk` (`packages/plugin-sdk/dist/index.js`).
### Step 2 — Start the Local Encrypted Sidecar (`tg-gateway-oss`)
Generate a high-entropy local gateway token and bind the sidecar strictly to loopback (`127.0.0.1`):
```bash
cd sidecar/tg-gateway-oss
uv venv && uv sync
export TELETELE_GATEWAY_TOKEN="$(openssl rand -hex 32)"
echo "Save this token for your MCP client: $TELETELE_GATEWAY_TOKEN"
uv run uvicorn tg_gateway_oss.server:app --host 127.0.0.1 --port 18421
```
> [!TIP]
> You can optionally set `TELETELE_OSS_DATA_DIR` (defaults to `~/.teletele-oss`) and `TELETELE_VAULT_KEY` (32-byte URL-safe base64 key; otherwise auto-generated into `~/.teletele-oss/vault/.vault.key` with `0600` permissions).
### Step 3 — Onboard Your Local Telegram Session (QR / Login Code)
Generate a Telethon `StringSession` locally (one-time interactive login) and import it directly into the AES-256-GCM encrypted vault:
```bash
# 1) Generate a Telethon StringSession locally (supports phone code or QR)
uv run python -c '
import asyncio, os
from telethon import TelegramClient
from telethon.sessions import StringSession
async def main():
api_id = int(os.getenv("TG_API_ID", "2040"))
api_hash = os.getenv("TG_API_HASH", "b18441a1ff607e10a989891a5462e627")
async with TelegramClient(StringSession(), api_id, api_hash) as client:
print("\nSESSION_STRING=" + client.session.save())
asyncio.run(main())
'
```
Import the generated `SESSION_STRING` into `tg-gateway-oss` (it is immediately encrypted with AES-256-GCM before touching disk):
```bash
curl -sS -X POST http://127.0.0.1:18421/admin/v1/import-session \
-H "Content-Type: application/json" \
-H "X-Agent-Token: $TELETELE_GATEWAY_TOKEN" \
-d '{
"account_id": "primary",
"phone": "+15550100000",
"session_string": "<paste-telethon-string-session>"
}'
```
Verify the gateway is healthy and your local account is sealed in the vault:
```bash
curl -sS http://127.0.0.1:18421/health
# {"ok":true,"edition":"oss","max_accounts":1,"account_configured":true}
```
### Step 4 — Connect Your AI Client
Replace `/path/to/teletele-mcp` with your local clone path and paste the `TELETELE_GATEWAY_TOKEN` from Step 2.
<details open>
<summary><strong>Claude Desktop</strong> — <code>~/Library/Application Support/Claude/claude_desktop_config.json</code> (macOS) / <code>%APPDATA%\Claude\claude_desktop_config.json</code> (Windows)</summary>
```json
{
"mcpServers": {
"teletele-tg": {
"command": "node",
"args": ["/path/to/teletele-mcp/packages/tg-mcp-server/dist/index.js"],
"env": {
"TELETELE_SIDECAR_URL": "http://127.0.0.1:18421",
"TELETELE_GATEWAY_TOKEN": "<your-local-gateway-token>"
}
}
}
}
```
</details>
<details>
<summary><strong>Cursor IDE</strong> — <code>.cursor/mcp.json</code> (project or <code>~/.cursor/mcp.json</code> global)</summary>
```json
{
"mcpServers": {
"teletele-tg": {
"command": "node",
"args": ["/path/to/teletele-mcp/packages/tg-mcp-server/dist/index.js"],
"env": {
"TELETELE_SIDECAR_URL": "http://127.0.0.1:18421",
"TELETELE_GATEWAY_TOKEN": "<your-local-gateway-token>"
}
}
}
}
```
</details>
<details>
<summary><strong>OpenAI Codex CLI</strong> — <code>~/.codex/config.toml</code></summary>
```toml
[mcp_servers.teletele-tg]
command = "node"
args = ["/path/to/teletele-mcp/packages/tg-mcp-server/dist/index.js"]
[mcp_servers.teletele-tg.env]
TELETELE_SIDECAR_URL = "http://127.0.0.1:18421"
TELETELE_GATEWAY_TOKEN = "<your-local-gateway-token>"
```
</details>
---
## 9 MCP Tools Reference
`@teletele/tg-mcp` exposes 9 strongly-typed tools over MCP JSON-RPC 2.0 (`protocolVersion: "2024-11-05"`). Every call is mapped to `POST /agent/v1/tools/<gateway_tool>` on `tg-gateway-oss`.
| MCP Tool Name | Gateway Route | Parameters (`*` = required) | Mode & Safety Notes |
| --- | --- | --- | --- |
| `tg_list_accounts` | `list_accounts` | *(none)* | **Read-only.** Returns the configured local Telegram account metadata (`account_id`, `phone`, `edition: "oss"`). Never returns session or API secrets. |
| `tg_list_groups` | `list_groups` | `account_id?: string`, `limit?: number` *(default `30`)* | **Read-only.** Lists recent Telegram dialogs (groups, supergroups, channels, and DMs) with `chat_id`, `title`, and `is_group`. |
| `tg_read_messages` | `read_messages` | `chat_id*: number \| string`, `account_id?: string`, `limit?: number` *(default `20`)* | **Read-only.** Reads recent messages from a group or channel. Automatically replaces non-text media (photos, voice notes, polls, files) with structured fallback labels. |
| `tg_read_dm` | `read_dm` | `chat_id*: number \| string`, `account_id?: string`, `limit?: number` *(default `20`)* | **Read-only.** Reads recent direct messages exchanged with a Telegram user or peer ID. |
| `tg_search_messages` | `search_messages` | `query*: string`, `chat_id?: number \| string`, `account_id?: string`, `limit?: number` *(default `20`)* | **Read-only.** Searches Telegram messages globally (when `chat_id` is omitted) or scoped inside a single chat. |
| `tg_save_draft` | `save_draft` | `chat_id*: number \| string`, `text*: string`, `account_id?: string` | **Safe Draft (Recommended).** Appends a `pending` draft entry (`draft_1`, `draft_2`, ...) into `~/.teletele-oss/drafts.json` without sending anything to Telegram. |
| `tg_send_group_msg` | `send_group_msg` | `chat_id*: number \| string`, `text*: string`, `account_id?: string`, `reply_to?: number` | **Live Write.** Immediately sends a message to a Telegram group or channel (supports threading via `reply_to`). Prefer `tg_save_draft` for sensitive announcements. |
| `tg_reply_dm` | `reply_dm` | `chat_id*: number \| string`, `text*: string`, `account_id?: string` | **Live Write.** Immediately sends a direct message reply to a Telegram user. |
| `tg_react_emoji` | `react_emoji` | `chat_id*: number \| string`, `message_id*: number`, `emoji*: string`, `account_id?: string` | **Live Reaction.** Sends a Telegram emoji reaction (`SendReactionRequest`) to the specified `message_id`. |
> [!NOTE]
> Looking for `tg_join_group`, `tg_delete_messages`, `tg_download_media`, multi-account auto-rotation, anti-ban jitter/cooldown guardrails, or mobile-synced Draft Approval Inbox? Those ship inside [Teletele Bot Desktop (Pro / Studio)](https://bot.teletele.lol/pricing).
---
## `@teletele/plugin-sdk` Developer Guide
`@teletele/plugin-sdk` provides the open-source TypeScript schema and builder utilities for extending **Teletele Bot Desktop Studio** with hot-swappable full-stack **Feature Plugins** (`teletele-feature-v1`) and **Business Rule Packs** (`teletele-plugin-v1`).
When you define a `table_crud` plugin using `defineFeaturePlugin`, the SDK automatically declares both the AI agent tools and REST CRUD routes:
- **Auto-contributed Agent Tools**: `feature_<id>_list_records`, `feature_<id>_upsert_record`, `feature_<id>_delete_record`
- **Auto-contributed Runtime Routes**: `GET /api/feature-plugins/<id>/records`, `POST /api/feature-plugins/<id>/records`, `DELETE /api/feature-plugins/<id>/records/:id`
- **Supported `uiKind` modes**: `"table_crud"` (auto-generated SQLite CRUD view), `"custom_html"` (sandboxed interactive panel), `"builtin_view"`, and `"right_pane"`.
### Example: Partner License Inventory Feature Plugin
```ts
import {
defineFeaturePlugin,
validateFeaturePluginManifest,
type FeaturePluginManifest,
} from "@teletele/plugin-sdk";
export const partnerLicensesPlugin: FeaturePluginManifest = defineFeaturePlugin({
id: "partner-licenses",
name: "Partner License Vault",
version: "1.0.0",
category: "Operations",
iconEmoji: "🔑",
accentColor: "#38bdf8",
description:
"Track partner activation keys, seat counts, and fulfillment status directly inside Teletele Bot Studio.",
uiKind: "table_crud",
navSlot: {
section: "operations",
label: "License Vault",
iconName: "Package",
order: 20,
},
statusColumnKey: "status",
tableColumns: [
{ key: "partner", label: "Partner", type: "text", required: true, placeholder: "Acme Cloud" },
{ key: "seats", label: "Seats", type: "number", required: true, placeholder: "10" },
{
key: "status",
label: "Status",
type: "select",
options: ["available", "reserved", "issued", "revoked"],
required: true,
},
{ key: "license_key", label: "Activation Key", type: "secret", required: true },
],
agentPromptGuide:
"Before issuing a key to a Telegram VIP contact, query feature_partner-licenses_list_records for an 'available' row and stage the delivery message with tg_save_draft.",
});
const check = validateFeaturePluginManifest(partnerLicensesPlugin);
if (!check.valid) {
throw new Error(`Invalid plugin manifest: ${check.errors.join("; ")}`);
}
// Ready to export as JSON and hot-install in Teletele Bot Desktop Studio
console.log(JSON.stringify(partnerLicensesPlugin, null, 2));
```
---
## Zero-Trust Local Security Architecture
<p align="center">
<img src="./docs/assets/architecture-security.png" alt="Zero-Trust Local Security Architecture diagram showing AI Client, @teletele/tg-mcp, Loopback HTTP X-Agent-Token Trust Wall, tg-gateway-oss, and AES-256-GCM Encrypted Session Vault" width="100%" />
</p>
### Security Guarantees
1. **Zero LLM Credential Exposure** — The AI client (Claude, Cursor, Codex, or your agent) only communicates with `@teletele/tg-mcp` over `stdin`/`stdout`. It never receives the filesystem path to your vault, `.vault.key`, `StringSession`, or `api_hash`.
2. **Loopback-Only Transport & Constant-Time Token Verification** — `tg-gateway-oss` listens exclusively on `127.0.0.1:18421` and validates `X-Agent-Token`, `X-Teletele-Admin-Token`, or `Authorization: Bearer <token>` using Python's constant-time `hmac.compare_digest`.
3. **Authenticated AES-256-GCM Storage** — `SessionVault` encrypts both `session_string` and `api_hash` before writing `~/.teletele-oss/account.json` using `cryptography`'s `AESGCM` with a 256-bit key and a fresh 12-byte CSPRNG nonce (`os.urandom(12)`) per secret. The vault directory is locked to `0700` and `.vault.key` is locked to `0600` (or injected via `TELETELE_VAULT_KEY` / Electron `safeStorage`).
4. **Human-in-the-Loop Draft Staging** — `tg_save_draft` persists outbound candidates locally in `~/.teletele-oss/drafts.json` (`status: "pending"`) without touching Telegram's send API.
### Environment Variables
| Variable | Component | Default | Purpose |
| --- | --- | --- | --- |
| `TELETELE_SIDECAR_URL` | `@teletele/tg-mcp` | `http://127.0.0.1:18421` | Loopback base URL of `tg-gateway-oss`. |
| `TELETELE_GATEWAY_TOKEN` | Both | *(empty)* | Shared secret required on `/agent/v1/tools/*` and `/admin/v1/*`. Always set in production use. |
| `TELETELE_ADMIN_TOKEN` | `tg-gateway-oss` | Falls back to `TELETELE_GATEWAY_TOKEN` | Optional dedicated admin token for session import. |
| `TELETELE_OSS_DATA_DIR` | `tg-gateway-oss` | `~/.teletele-oss` | Directory holding `account.json`, `drafts.json`, and `vault/`. |
| `TELETELE_VAULT_KEY` | `tg-gateway-oss` | Auto-generated `.vault.key` (`0600`) | Optional 32-byte URL-safe base64 master key (or passphrase hashed via SHA-256). |
| `TG_API_ID` / `TG_API_HASH` | `tg-gateway-oss` | Built-in defaults | Optional custom Telegram API credentials from `my.telegram.org`. |
---
## Open-Source vs Teletele Bot Desktop
The open-source core in this repository (`PunkSlerf/teletele-mcp`, MIT) is designed for solo developers integrating 1 local Telegram account into MCP clients. When you need a turnkey visual workstation for multi-account growth, team CRM, anti-ban guardrails, and mobile draft sign-off, upgrade seamlessly to **[Teletele Bot Desktop](https://bot.teletele.lol)**.
<p align="center">
<img src="./docs/assets/desktop-workspace-preview.png" alt="Teletele Bot Desktop Studio showing Multi-Agent Workspace, 3 AI Digital Employees, and Inline OPSEC Draft Approval Inbox cards" width="100%" />
</p>
| Capability | Open-Source (`teletele-mcp`, MIT) | Desktop Free Trial | Desktop Pro | Desktop Studio |
| --- | :---: | :---: | :---: | :---: |
| **License / Pricing** | Free (MIT) | Free Local Trial | [See Pro Pricing](https://bot.teletele.lol/pricing) | [See Studio Pricing](https://bot.teletele.lol/pricing) |
| **Telegram Accounts** | 1 local account | 1 local account | Up to 5 accounts | Up to 30+ accounts |
| **Stdio MCP Server (9 Tools) & Plugin SDK** | ✅ | ✅ | ✅ | ✅ |
| **AES-256-GCM Local Session Vault** | ✅ (`.vault.key` `0600`) | ✅ (+ OS `safeStorage`) | ✅ (+ OS `safeStorage`) | ✅ (+ OS `safeStorage`) |
| **AI Digital Employees & Visual Workstation** | Headless MCP only | 1 AI employee | Up to 3 AI employees | Unlimited (`999+`) |
| **Draft Approval Inbox (Mobile TG Draft Sync)** | Local `drafts.json` | ✅ | ✅ | ✅ |
| **5-Stage CRM Sales Funnel & Task Kanban** | — | — | ✅ | ✅ |
| **Multi-Account Auto-Rotation & Anti-Ban Guardrails** | — | — | ✅ | ✅ |
| **Auto Routines, Risk Radar & Built-in Browser** | — | — | ✅ | ✅ |
| **Official Teletele Cloud Compute Credits** | BYO MCP Host | — | 500 credits included | 2,000 credits included |
| **BYOK Providers & Hot-Swappable Custom Plugins** | SDK Authoring | — | — | ✅ |
| **Multi-Bot Channels & Mobile / LAN Co-Pilot** | — | — | — | ✅ |
<p align="center">
<a href="https://bot.teletele.lol/open-source">
<img src="./docs/assets/bot-site-opensource.png" alt="Teletele Bot Open Source portal at bot.teletele.lol/open-source" width="100%" />
</a>
</p>
<p align="center">
<a href="https://bot.teletele.lol"><strong>Explore Teletele Bot Desktop →</strong></a> ·
<a href="https://bot.teletele.lol/open-source"><strong>Open-Source Portal →</strong></a> ·
<a href="https://bot.teletele.lol/pricing"><strong>Compare Pro & Studio Plans →</strong></a>
</p>
---
## Development & Verification
```bash
# Install workspace dependencies
pnpm install
# Build @teletele/tg-mcp and @teletele/plugin-sdk
pnpm build
# Run strict TypeScript typechecking across all packages
pnpm typecheck
```
### Quick Smoke Test (Stdio JSON-RPC 2.0)
```bash
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | node ./packages/tg-mcp-server/dist/index.js
```
---
## License
Released under the [MIT License](./LICENSE). Built with ❤️ by the Teletele team — [bot.teletele.lol](https://bot.teletele.lol).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues