@overpod/mcp-telegram 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +335 -0
- package/dist/cli.js +9 -0
- package/dist/index.js +424 -0
- package/dist/qr-login-cli.js +58 -0
- package/dist/telegram-client.js +508 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 overpod
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
# MCP Telegram
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@overpod/mcp-telegram)
|
|
4
|
+
[](https://www.typescriptlang.org/)
|
|
5
|
+
[](https://modelcontextprotocol.io/)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
An MCP (Model Context Protocol) server that connects AI assistants like Claude to Telegram via the MTProto protocol. Unlike bots, this runs as a **userbot** -- it operates under your personal Telegram account using [GramJS](https://github.com/nicedoc/gramjs), giving full access to your chats, contacts, and message history.
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **MTProto protocol** -- direct Telegram API access, not the limited Bot API
|
|
13
|
+
- **Userbot** -- operates as your personal account, not a bot
|
|
14
|
+
- **20 tools** -- messaging, chat management, media, contacts, and more
|
|
15
|
+
- **QR code login** -- authenticate by scanning a QR code in the Telegram app
|
|
16
|
+
- **Session persistence** -- login once, stay connected across restarts
|
|
17
|
+
- **Human-readable output** -- sender names are resolved, not just numeric IDs
|
|
18
|
+
- **Works with any MCP client** -- Claude Code, Claude Desktop, Cursor, VS Code, Mastra, etc.
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
- **Node.js** 18 or later
|
|
23
|
+
- **Telegram API credentials** -- `API_ID` and `API_HASH` from [my.telegram.org](https://my.telegram.org)
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
### 1. Get Telegram API credentials
|
|
28
|
+
|
|
29
|
+
1. Go to [my.telegram.org](https://my.telegram.org) and log in with your phone number.
|
|
30
|
+
2. Navigate to **API development tools**.
|
|
31
|
+
3. Create a new application (any name and platform).
|
|
32
|
+
4. Copy the **App api_id** and **App api_hash**.
|
|
33
|
+
|
|
34
|
+
### 2. Login
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
TELEGRAM_API_ID=YOUR_ID TELEGRAM_API_HASH=YOUR_HASH npx @overpod/mcp-telegram login
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
A QR code will appear in the terminal. Open Telegram on your phone, go to **Settings > Devices > Link Desktop Device**, and scan the code. The session is saved to `~/.telegram-session` and reused automatically.
|
|
41
|
+
|
|
42
|
+
### 3. Add to Claude
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
claude mcp add telegram -s user \
|
|
46
|
+
-e TELEGRAM_API_ID=YOUR_ID \
|
|
47
|
+
-e TELEGRAM_API_HASH=YOUR_HASH \
|
|
48
|
+
-- npx @overpod/mcp-telegram
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
That's it! Ask Claude to run `telegram-status` to verify.
|
|
52
|
+
|
|
53
|
+
## Installation Options
|
|
54
|
+
|
|
55
|
+
### npx (recommended, zero install)
|
|
56
|
+
|
|
57
|
+
No need to clone or install anything. Just use `npx @overpod/mcp-telegram`.
|
|
58
|
+
|
|
59
|
+
### Global install
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install -g @overpod/mcp-telegram
|
|
63
|
+
mcp-telegram # run server
|
|
64
|
+
mcp-telegram login # QR login
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### From source
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git clone https://github.com/overpod/mcp-telegram.git
|
|
71
|
+
cd mcp-telegram
|
|
72
|
+
npm install && npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Usage with MCP Clients
|
|
76
|
+
|
|
77
|
+
### Claude Code (CLI)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
claude mcp add telegram -s user \
|
|
81
|
+
-e TELEGRAM_API_ID=YOUR_ID \
|
|
82
|
+
-e TELEGRAM_API_HASH=YOUR_HASH \
|
|
83
|
+
-- npx @overpod/mcp-telegram
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Claude Desktop / Cursor / VS Code
|
|
87
|
+
|
|
88
|
+
Add to your MCP configuration file:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"mcpServers": {
|
|
93
|
+
"telegram": {
|
|
94
|
+
"command": "npx",
|
|
95
|
+
"args": ["@overpod/mcp-telegram"],
|
|
96
|
+
"env": {
|
|
97
|
+
"TELEGRAM_API_ID": "YOUR_ID",
|
|
98
|
+
"TELEGRAM_API_HASH": "YOUR_HASH"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Mastra
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import { MCPClient } from "@mastra/mcp";
|
|
109
|
+
|
|
110
|
+
const telegramMcp = new MCPClient({
|
|
111
|
+
id: "telegram-mcp",
|
|
112
|
+
servers: {
|
|
113
|
+
telegram: {
|
|
114
|
+
command: "npx",
|
|
115
|
+
args: ["@overpod/mcp-telegram"],
|
|
116
|
+
env: {
|
|
117
|
+
TELEGRAM_API_ID: process.env.TELEGRAM_API_ID!,
|
|
118
|
+
TELEGRAM_API_HASH: process.env.TELEGRAM_API_HASH!,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Available Tools
|
|
126
|
+
|
|
127
|
+
### Connection
|
|
128
|
+
|
|
129
|
+
| Tool | Description |
|
|
130
|
+
|------|-------------|
|
|
131
|
+
| `telegram-status` | Check connection status and current account info |
|
|
132
|
+
| `telegram-login` | Authenticate via QR code |
|
|
133
|
+
|
|
134
|
+
### Messaging
|
|
135
|
+
|
|
136
|
+
| Tool | Description |
|
|
137
|
+
|------|-------------|
|
|
138
|
+
| `telegram-send-message` | Send a text message to a chat |
|
|
139
|
+
| `telegram-send-file` | Send a file (photo, document, video, etc.) to a chat |
|
|
140
|
+
| `telegram-edit-message` | Edit a previously sent message |
|
|
141
|
+
| `telegram-delete-message` | Delete messages in a chat |
|
|
142
|
+
| `telegram-forward-message` | Forward messages between chats |
|
|
143
|
+
|
|
144
|
+
### Reading
|
|
145
|
+
|
|
146
|
+
| Tool | Description |
|
|
147
|
+
|------|-------------|
|
|
148
|
+
| `telegram-list-chats` | List recent dialogs with unread counts |
|
|
149
|
+
| `telegram-read-messages` | Read recent messages from a chat |
|
|
150
|
+
| `telegram-search-chats` | Search for chats, users, or channels by name |
|
|
151
|
+
| `telegram-search-messages` | Search messages in a chat by text |
|
|
152
|
+
| `telegram-get-unread` | Get chats with unread messages |
|
|
153
|
+
|
|
154
|
+
### Chat Management
|
|
155
|
+
|
|
156
|
+
| Tool | Description |
|
|
157
|
+
|------|-------------|
|
|
158
|
+
| `telegram-mark-as-read` | Mark a chat as read |
|
|
159
|
+
| `telegram-get-chat-info` | Get detailed info about a chat (name, type, members count, description) |
|
|
160
|
+
| `telegram-get-chat-members` | List members of a group or channel |
|
|
161
|
+
| `telegram-pin-message` | Pin a message in a chat |
|
|
162
|
+
| `telegram-unpin-message` | Unpin a message in a chat |
|
|
163
|
+
|
|
164
|
+
### User Info
|
|
165
|
+
|
|
166
|
+
| Tool | Description |
|
|
167
|
+
|------|-------------|
|
|
168
|
+
| `telegram-get-contacts` | Get your contacts list with phone numbers |
|
|
169
|
+
| `telegram-get-profile` | Get detailed profile info for a user (bio, photo, last seen) |
|
|
170
|
+
|
|
171
|
+
### Media
|
|
172
|
+
|
|
173
|
+
| Tool | Description |
|
|
174
|
+
|------|-------------|
|
|
175
|
+
| `telegram-download-media` | Download media from a message to a local file |
|
|
176
|
+
|
|
177
|
+
## Tool Parameters
|
|
178
|
+
|
|
179
|
+
### Common patterns
|
|
180
|
+
|
|
181
|
+
Most tools accept `chatId` as a string -- either a numeric ID (e.g., `"-1001234567890"`) or a username (e.g., `"@username"`).
|
|
182
|
+
|
|
183
|
+
### telegram-send-message
|
|
184
|
+
|
|
185
|
+
| Parameter | Type | Required | Description |
|
|
186
|
+
|-----------|------|----------|-------------|
|
|
187
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
188
|
+
| `text` | string | yes | Message text |
|
|
189
|
+
| `replyTo` | number | no | Message ID to reply to |
|
|
190
|
+
| `parseMode` | `"md"` / `"html"` | no | Message formatting mode |
|
|
191
|
+
|
|
192
|
+
### telegram-list-chats
|
|
193
|
+
|
|
194
|
+
| Parameter | Type | Required | Description |
|
|
195
|
+
|-----------|------|----------|-------------|
|
|
196
|
+
| `limit` | number | no | Number of chats to return (default: 20) |
|
|
197
|
+
| `offsetDate` | number | no | Unix timestamp for pagination |
|
|
198
|
+
| `filterType` | `"private"` / `"group"` / `"channel"` | no | Filter by chat type |
|
|
199
|
+
|
|
200
|
+
### telegram-read-messages
|
|
201
|
+
|
|
202
|
+
| Parameter | Type | Required | Description |
|
|
203
|
+
|-----------|------|----------|-------------|
|
|
204
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
205
|
+
| `limit` | number | no | Number of messages (default: 10) |
|
|
206
|
+
| `offsetId` | number | no | Message ID for pagination |
|
|
207
|
+
|
|
208
|
+
### telegram-send-file
|
|
209
|
+
|
|
210
|
+
| Parameter | Type | Required | Description |
|
|
211
|
+
|-----------|------|----------|-------------|
|
|
212
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
213
|
+
| `filePath` | string | yes | Absolute path to the file |
|
|
214
|
+
| `caption` | string | no | File caption |
|
|
215
|
+
|
|
216
|
+
### telegram-download-media
|
|
217
|
+
|
|
218
|
+
| Parameter | Type | Required | Description |
|
|
219
|
+
|-----------|------|----------|-------------|
|
|
220
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
221
|
+
| `messageId` | number | yes | Message ID containing media |
|
|
222
|
+
| `downloadPath` | string | yes | Absolute path to save the file |
|
|
223
|
+
|
|
224
|
+
### telegram-forward-message
|
|
225
|
+
|
|
226
|
+
| Parameter | Type | Required | Description |
|
|
227
|
+
|-----------|------|----------|-------------|
|
|
228
|
+
| `fromChatId` | string | yes | Source chat ID or @username |
|
|
229
|
+
| `toChatId` | string | yes | Destination chat ID or @username |
|
|
230
|
+
| `messageIds` | number[] | yes | Array of message IDs to forward |
|
|
231
|
+
|
|
232
|
+
### telegram-edit-message
|
|
233
|
+
|
|
234
|
+
| Parameter | Type | Required | Description |
|
|
235
|
+
|-----------|------|----------|-------------|
|
|
236
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
237
|
+
| `messageId` | number | yes | ID of the message to edit |
|
|
238
|
+
| `text` | string | yes | New message text |
|
|
239
|
+
|
|
240
|
+
### telegram-delete-message
|
|
241
|
+
|
|
242
|
+
| Parameter | Type | Required | Description |
|
|
243
|
+
|-----------|------|----------|-------------|
|
|
244
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
245
|
+
| `messageIds` | number[] | yes | Array of message IDs to delete |
|
|
246
|
+
|
|
247
|
+
### telegram-pin-message
|
|
248
|
+
|
|
249
|
+
| Parameter | Type | Required | Description |
|
|
250
|
+
|-----------|------|----------|-------------|
|
|
251
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
252
|
+
| `messageId` | number | yes | Message ID to pin |
|
|
253
|
+
| `silent` | boolean | no | Pin without notification (default: false) |
|
|
254
|
+
|
|
255
|
+
### telegram-search-messages
|
|
256
|
+
|
|
257
|
+
| Parameter | Type | Required | Description |
|
|
258
|
+
|-----------|------|----------|-------------|
|
|
259
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
260
|
+
| `query` | string | yes | Search text |
|
|
261
|
+
| `limit` | number | no | Max results (default: 20) |
|
|
262
|
+
|
|
263
|
+
### telegram-search-chats
|
|
264
|
+
|
|
265
|
+
| Parameter | Type | Required | Description |
|
|
266
|
+
|-----------|------|----------|-------------|
|
|
267
|
+
| `query` | string | yes | Search query (name or username) |
|
|
268
|
+
| `limit` | number | no | Max results (default: 10) |
|
|
269
|
+
|
|
270
|
+
### telegram-get-chat-members
|
|
271
|
+
|
|
272
|
+
| Parameter | Type | Required | Description |
|
|
273
|
+
|-----------|------|----------|-------------|
|
|
274
|
+
| `chatId` | string | yes | Chat ID or @username |
|
|
275
|
+
| `limit` | number | no | Number of members (default: 50) |
|
|
276
|
+
|
|
277
|
+
### telegram-get-contacts
|
|
278
|
+
|
|
279
|
+
| Parameter | Type | Required | Description |
|
|
280
|
+
|-----------|------|----------|-------------|
|
|
281
|
+
| `limit` | number | no | Number of contacts (default: 50) |
|
|
282
|
+
|
|
283
|
+
### telegram-get-profile
|
|
284
|
+
|
|
285
|
+
| Parameter | Type | Required | Description |
|
|
286
|
+
|-----------|------|----------|-------------|
|
|
287
|
+
| `userId` | string | yes | User ID or @username |
|
|
288
|
+
|
|
289
|
+
### telegram-get-unread
|
|
290
|
+
|
|
291
|
+
| Parameter | Type | Required | Description |
|
|
292
|
+
|-----------|------|----------|-------------|
|
|
293
|
+
| `limit` | number | no | Number of unread chats (default: 20) |
|
|
294
|
+
|
|
295
|
+
## Development
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
npm run dev # Start with file watching (tsx)
|
|
299
|
+
npm start # Start the MCP server
|
|
300
|
+
npm run login # QR code login in terminal
|
|
301
|
+
npm run build # Compile TypeScript
|
|
302
|
+
npm run lint # Check code with Biome
|
|
303
|
+
npm run lint:fix # Auto-fix lint issues
|
|
304
|
+
npm run format # Format code with Biome
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Project Structure
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
src/
|
|
311
|
+
index.ts -- MCP server entry point, 20 tool definitions
|
|
312
|
+
telegram-client.ts -- TelegramService class (GramJS wrapper)
|
|
313
|
+
qr-login-cli.ts -- CLI utility for QR code login
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## Tech Stack
|
|
317
|
+
|
|
318
|
+
- **[TypeScript](https://www.typescriptlang.org/)** -- ES2022, ESM modules
|
|
319
|
+
- **[GramJS](https://github.com/nicedoc/gramjs)** (`telegram`) -- Telegram MTProto client
|
|
320
|
+
- **[@modelcontextprotocol/sdk](https://modelcontextprotocol.io/)** -- MCP server framework
|
|
321
|
+
- **[Zod](https://zod.dev/)** -- Runtime schema validation for tool parameters
|
|
322
|
+
- **[Biome](https://biomejs.dev/)** -- Linter and formatter
|
|
323
|
+
- **[tsx](https://tsx.is/)** -- TypeScript execution without a build step
|
|
324
|
+
- **[dotenv](https://github.com/motdotla/dotenv)** -- Environment variable management
|
|
325
|
+
|
|
326
|
+
## Security
|
|
327
|
+
|
|
328
|
+
- API credentials are stored in `.env` (gitignored)
|
|
329
|
+
- Session is stored in `.telegram-session` (gitignored)
|
|
330
|
+
- Phone number is **not required** -- QR-only authentication
|
|
331
|
+
- This is a **userbot** (personal account), not a bot -- respect the [Telegram Terms of Service](https://core.telegram.org/api/terms)
|
|
332
|
+
|
|
333
|
+
## License
|
|
334
|
+
|
|
335
|
+
MIT
|