fast-mcp-telegram 0.0.1__tar.gz

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.
Files changed (30) hide show
  1. fast_mcp_telegram-0.0.1/LICENSE +21 -0
  2. fast_mcp_telegram-0.0.1/PKG-INFO +650 -0
  3. fast_mcp_telegram-0.0.1/README.md +624 -0
  4. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/PKG-INFO +650 -0
  5. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/SOURCES.txt +28 -0
  6. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/dependency_links.txt +1 -0
  7. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/entry_points.txt +3 -0
  8. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/requires.txt +5 -0
  9. fast_mcp_telegram-0.0.1/fast_mcp_telegram.egg-info/top_level.txt +1 -0
  10. fast_mcp_telegram-0.0.1/pyproject.toml +84 -0
  11. fast_mcp_telegram-0.0.1/setup.cfg +4 -0
  12. fast_mcp_telegram-0.0.1/src/__init__.py +5 -0
  13. fast_mcp_telegram-0.0.1/src/client/__init__.py +1 -0
  14. fast_mcp_telegram-0.0.1/src/client/connection.py +99 -0
  15. fast_mcp_telegram-0.0.1/src/config/__init__.py +1 -0
  16. fast_mcp_telegram-0.0.1/src/config/logging.py +141 -0
  17. fast_mcp_telegram-0.0.1/src/config/settings.py +57 -0
  18. fast_mcp_telegram-0.0.1/src/server.py +512 -0
  19. fast_mcp_telegram-0.0.1/src/setup_telegram.py +139 -0
  20. fast_mcp_telegram-0.0.1/src/tools/__init__.py +5 -0
  21. fast_mcp_telegram-0.0.1/src/tools/contacts.py +139 -0
  22. fast_mcp_telegram-0.0.1/src/tools/links.py +170 -0
  23. fast_mcp_telegram-0.0.1/src/tools/messages.py +363 -0
  24. fast_mcp_telegram-0.0.1/src/tools/mtproto.py +160 -0
  25. fast_mcp_telegram-0.0.1/src/tools/search.py +377 -0
  26. fast_mcp_telegram-0.0.1/src/utils/__init__.py +3 -0
  27. fast_mcp_telegram-0.0.1/src/utils/entity.py +259 -0
  28. fast_mcp_telegram-0.0.1/src/utils/error_handling.py +258 -0
  29. fast_mcp_telegram-0.0.1/src/utils/helpers.py +21 -0
  30. fast_mcp_telegram-0.0.1/src/utils/message_format.py +146 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 MCP Telegram Search Server
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.
@@ -0,0 +1,650 @@
1
+ Metadata-Version: 2.4
2
+ Name: fast-mcp-telegram
3
+ Version: 0.0.1
4
+ Summary: MCP server with Telegram search and messaging capabilities
5
+ Author-email: Alexey Leshchenko <leshchenko@gmail.com>
6
+ License-Expression: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Topic :: Communications :: Chat
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: loguru
21
+ Requires-Dist: aiohttp
22
+ Requires-Dist: fastmcp
23
+ Requires-Dist: telethon
24
+ Requires-Dist: python-dotenv
25
+ Dynamic: license-file
26
+
27
+ # 🚀 fast-mcp-telegram
28
+
29
+ [![Python Version](https://img.shields.io/badge/python-3.10+-blue.svg)](https://python.org)
30
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
31
+ [![Docker Ready](https://img.shields.io/badge/Docker-Ready-blue?logo=docker)](https://github.com/leshchenko1979/fast-mcp-telegram)
32
+
33
+ <div align="center">
34
+
35
+ # 🤖 AI-Powered Telegram Automation
36
+
37
+ **Transform your AI assistant into a Telegram power user with full API access**
38
+
39
+ *Search messages, send automated replies, manage contacts, and control Telegram through any MCP-compatible AI client*
40
+
41
+ [![Quick Start](https://img.shields.io/badge/🚀_Quick_Start-2_min_setup-brightgreen?style=for-the-badge&logo=lightning)](#-uvx-path-recommended)
42
+ [![Docker](https://img.shields.io/badge/🐳_Docker-Production_ready-blue?style=for-the-badge&logo=docker)](#-docker-deployment-production)
43
+ [![Community](https://img.shields.io/badge/💬_Community-Join_us-blue?style=for-the-badge&logo=telegram)](https://t.me/mcp_telegram)
44
+
45
+ **⚡ Lightning-fast setup • 🔍 Smart search • 💬 Auto-messaging • 📱 Phone integration • 🐳 Production-ready**
46
+
47
+ </div>
48
+
49
+ ---
50
+
51
+ ## 📖 Table of Contents
52
+
53
+ - [✨ Features](#-features)
54
+ - [📋 Prerequisites](#-prerequisites)
55
+ - [🚀 Choose Your Installation Path](#-choose-your-installation-path)
56
+ - [🚀 uvx Path (Recommended)](#-uvx-path-recommended)
57
+ - [💻 Local Installation Path](#-local-installation-path)
58
+ - [🐳 Docker Deployment (Production)](#-docker-deployment-production)
59
+ - [🔧 Available Tools](#-available-tools)
60
+ - [📁 Project Structure](#-project-structure)
61
+ - [📦 Dependencies](#-dependencies)
62
+ - [🔒 Security Considerations](#-security-considerations)
63
+ - [🤝 Contributing](#-contributing)
64
+ - [📄 License](#-license)
65
+ - [🙏 Acknowledgments](#-acknowledgments)
66
+
67
+ ---
68
+
69
+ ## ✨ Features
70
+
71
+ | Feature | Description |
72
+ |---------|-------------|
73
+ | 🔍 **Smart Search** | Global & per-chat message search with filters |
74
+ | 💬 **Messaging** | Send, edit, reply with formatting support |
75
+ | 👥 **Contacts** | Search users, get profiles, manage contacts |
76
+ | 📱 **Phone Integration** | Message by phone number, auto-contact management |
77
+ | 🔧 **Low-level API** | Direct MTProto access for advanced operations |
78
+ | ⚡ **Performance** | Async operations, connection pooling, caching |
79
+ | 🛡️ **Reliability** | Auto-reconnect, structured logging, error handling |
80
+
81
+ ## 📋 Prerequisites
82
+
83
+ - **Python 3.10+**
84
+ - **Telegram API credentials** ([get them here](https://my.telegram.org/auth))
85
+ - **MCP-compatible client** (Cursor, Claude Desktop, etc.)
86
+
87
+ ## 🚀 Choose Your Installation Path
88
+
89
+ | Path | Best For | Complexity | Maintenance |
90
+ |------|----------|------------|-------------|
91
+ | **🚀 uvx (Recommended)** | Most users, quick setup | ⭐⭐⭐⭐⭐ Easy | ✅ Auto-updates |
92
+ | **🐳 Docker (Production)** | Production deployment | ⭐⭐⭐⭐ Easy | 🐳 Container updates |
93
+ | **💻 Local Installation** | Developers, contributors | ⭐⭐⭐ Medium | 🔧 Manual updates |
94
+
95
+ **Choose your path below:**
96
+ - [uvx Path (2-minute setup)](#-uvx-path-recommended)
97
+ - [Local Installation Path](#-local-installation-path)
98
+ - [🐳 Docker Deployment (Production)](#-docker-deployment-production)
99
+
100
+ ---
101
+
102
+ ## 🚀 uvx Path (Recommended)
103
+
104
+ ### 1. One-Time Telegram Authentication
105
+ ```bash
106
+ API_ID="your_api_id" API_HASH="your_api_hash" PHONE_NUMBER="+123456789" \
107
+ uvx --from git+https://github.com/leshchenko1979/fast-mcp-telegram.git@master fast-mcp-telegram-setup
108
+ ```
109
+
110
+ ### 2. Configure Your MCP Client
111
+ ```json
112
+ {
113
+ "mcpServers": {
114
+ "telegram": {
115
+ "command": "uvx",
116
+ "args": ["--from", "git+https://github.com/leshchenko1979/fast-mcp-telegram.git@master", "fast-mcp-telegram"],
117
+ "env": {
118
+ "API_ID": "your_api_id",
119
+ "API_HASH": "your_api_hash",
120
+ "PHONE_NUMBER": "+123456789"
121
+ }
122
+ }
123
+ }
124
+ }
125
+ ```
126
+
127
+ ### 3. Start Using!
128
+ ```json
129
+ {"tool": "search_messages", "params": {"query": "hello", "limit": 5}}
130
+ {"tool": "send_message", "params": {"chat_id": "me", "message": "Hello from AI!"}}
131
+ ```
132
+
133
+ **ℹ️ Session Info:** Your Telegram session is saved to `~/.config/fast-mcp-telegram/mcp_telegram.session` (one-time setup)
134
+
135
+ **✅ You're all set!** Jump to [Available Tools](#-available-tools) to explore features.
136
+
137
+ ---
138
+
139
+ ## 💻 Local Installation Path
140
+
141
+ ### 1. Install Locally
142
+ ```bash
143
+ git clone https://github.com/leshchenko1979/fast-mcp-telegram.git
144
+ cd fast-mcp-telegram
145
+ uv sync # Install dependencies
146
+ ```
147
+
148
+ ### 2. Authenticate with Telegram
149
+ ```bash
150
+ API_ID="your_api_id" API_HASH="your_api_hash" PHONE_NUMBER="+123456789" \
151
+ python src/setup_telegram.py
152
+ ```
153
+
154
+ ### 3. Configure Your MCP Client
155
+ ```json
156
+ {
157
+ "mcpServers": {
158
+ "telegram": {
159
+ "command": "python3",
160
+ "args": ["/path/to/fast-mcp-telegram/src/server.py"],
161
+ "cwd": "/path/to/fast-mcp-telegram"
162
+ }
163
+ }
164
+ }
165
+ ```
166
+
167
+ ### 4. Start Using!
168
+ ```json
169
+ {"tool": "search_messages", "params": {"query": "hello", "limit": 5}}
170
+ {"tool": "send_message", "params": {"chat_id": "me", "message": "Hello from AI!"}}
171
+ ```
172
+
173
+ **ℹ️ Session Info:** Your Telegram session is saved to `mcp_telegram.session` in the project directory (one-time setup)
174
+
175
+ **✅ You're all set!** Continue below for development tools.
176
+
177
+ ---
178
+
179
+ ## 🐳 Docker Deployment (Production)
180
+
181
+ ### Prerequisites
182
+
183
+ - **Docker & Docker Compose** installed
184
+ - **Telegram API credentials** ([get them here](https://my.telegram.org/auth))
185
+ - **Domain name** (for Traefik reverse proxy setup)
186
+
187
+ ### 1. Environment Setup
188
+
189
+ Create a `.env` file in your project directory:
190
+
191
+ ```bash
192
+ # Telegram API Credentials
193
+ API_ID=your_api_id
194
+ API_HASH=your_api_hash
195
+ PHONE_NUMBER=+1234567890
196
+
197
+ # MCP Server Configuration
198
+ MCP_TRANSPORT=http
199
+ MCP_HOST=0.0.0.0
200
+ MCP_PORT=8000
201
+ SESSION_NAME=mcp_telegram
202
+
203
+ # Domain Configuration (optional - defaults to your-domain.com)
204
+ DOMAIN=your-domain.com
205
+
206
+ # Optional: Logging
207
+ LOG_LEVEL=INFO
208
+ ```
209
+
210
+ ### 2. Telegram Authentication (One-Time Setup)
211
+
212
+ **Important:** The setup process creates an authenticated Telegram session file at `./mcp_telegram.session` in your project directory.
213
+
214
+ ```bash
215
+ # 1. Run authentication setup
216
+ docker compose --profile setup run --rm setup
217
+
218
+ # 2. Start the main MCP server
219
+ docker compose up -d
220
+ ```
221
+
222
+ **Creates authenticated session file at `./mcp_telegram.session`**
223
+
224
+ ### 3. Domain Configuration (Optional)
225
+
226
+ The default domain is `your-domain.com`. To use your own domain:
227
+
228
+ 1. **Set up DNS**: Point your domain to your server
229
+ 2. **Configure environment**: Add `DOMAIN=your-domain.com` to your `.env` file
230
+ 3. **Traefik network**: Ensure `traefik-public` network exists on your host
231
+
232
+ **Example:**
233
+ ```bash
234
+ # In your .env file
235
+ DOMAIN=my-telegram-bot.example.com
236
+ ```
237
+
238
+ ### 4. Local Docker Deployment
239
+
240
+ ```bash
241
+ # Build and start the service
242
+ docker compose up --build -d
243
+
244
+ # Check logs
245
+ docker compose logs -f fast-mcp-telegram
246
+
247
+ # Check health
248
+ docker compose ps
249
+ ```
250
+
251
+ The service will be available at `http://localhost:8000` (internal) and through Traefik if configured.
252
+
253
+ ### 5. Remote Server Deployment
254
+
255
+ For production deployment on a remote server:
256
+
257
+ ```bash
258
+ # Set up environment variables for remote deployment
259
+ export VDS_USER=your_server_user
260
+ export VDS_HOST=your.server.com
261
+ export VDS_PROJECT_PATH=/path/to/deployment
262
+
263
+ # Run the deployment script
264
+ ./scripts/deploy-mcp.sh
265
+ ```
266
+
267
+ The script will:
268
+ - Transfer project files to your server
269
+ - Copy environment file
270
+ - Build and start the Docker containers
271
+
272
+ ### 6. Configure Your MCP Client
273
+
274
+ For HTTP-based MCP clients:
275
+
276
+ ```json
277
+ {
278
+ "mcpServers": {
279
+ "telegram": {
280
+ "command": "curl",
281
+ "args": ["-X", "POST", "https://your-domain.com/mcp"],
282
+ "env": {}
283
+ }
284
+ }
285
+ }
286
+ ```
287
+
288
+ Or for direct HTTP connection:
289
+
290
+ ```json
291
+ {
292
+ "mcpServers": {
293
+ "telegram": {
294
+ "url": "https://your-domain.com"
295
+ }
296
+ }
297
+ }
298
+ ```
299
+
300
+ ### 7. Verify Deployment
301
+
302
+ ```bash
303
+ # Check container status
304
+ docker compose ps
305
+
306
+ # View logs
307
+ docker compose logs fast-mcp-telegram
308
+
309
+ # Test health endpoint
310
+ curl -s https://your-domain.com/health
311
+ ```
312
+
313
+ **Environment Variables:**
314
+ - `MCP_TRANSPORT=http` - HTTP transport mode
315
+ - `MCP_HOST=0.0.0.0` - Bind to all interfaces
316
+ - `MCP_PORT=8000` - Service port
317
+ - `SESSION_NAME=mcp_telegram` - Telegram session name
318
+
319
+ ---
320
+
321
+ ## 🛠️ Development
322
+
323
+ ```bash
324
+ uv sync --all-extras # Install dev dependencies
325
+ uv run ruff format . # Format code
326
+ uv run ruff check . # Lint code
327
+ python src/server.py # Test server
328
+ ```
329
+
330
+ ---
331
+
332
+ ## 🔧 Available Tools
333
+
334
+ | Tool | Purpose | Key Features |
335
+ |------|---------|--------------|
336
+ | `search_messages` | Search messages globally or in specific chats | Filters by date, chat type, multiple queries |
337
+ | `send_or_edit_message` | Send new messages or edit existing ones | Markdown/HTML formatting, replies |
338
+ | `read_messages` | Read specific messages by ID | Bulk reading, full metadata |
339
+ | `search_contacts` | Find users and contacts | By name, username, or phone |
340
+ | `get_contact_details` | Get user/chat profile information | Bio, status, online state |
341
+ | `send_message_to_phone` | Message by phone number | Auto-contact management |
342
+ | `invoke_mtproto` | Direct Telegram API access | Advanced operations |
343
+
344
+ ### 📍 search_messages
345
+ **Search messages with advanced filtering**
346
+
347
+ ```typescript
348
+ search_messages(
349
+ query: str, // Search terms (comma-separated)
350
+ chat_id?: str, // Specific chat ID ('me' for Saved Messages)
351
+ limit?: number = 50, // Max results
352
+ chat_type?: 'private'|'group'|'channel', // Filter by chat type
353
+ min_date?: string, // ISO date format
354
+ max_date?: string // ISO date format
355
+ )
356
+ ```
357
+
358
+ **Examples:**
359
+ ```json
360
+ // Global search
361
+ {"tool": "search_messages", "params": {"query": "deadline", "limit": 20}}
362
+
363
+ // Chat-specific search
364
+ {"tool": "search_messages", "params": {"chat_id": "-1001234567890", "query": "launch"}}
365
+
366
+ // Filtered by date and type
367
+ {"tool": "search_messages", "params": {
368
+ "query": "project",
369
+ "chat_type": "private",
370
+ "min_date": "2024-01-01"
371
+ }}
372
+ ```
373
+
374
+ ### 💬 send_or_edit_message
375
+ **Send or edit messages with formatting**
376
+
377
+ ```typescript
378
+ send_or_edit_message(
379
+ chat_id: str, // Target chat ID ('me', username, or numeric ID)
380
+ message: str, // Message content
381
+ reply_to_msg_id?: number, // Reply to specific message
382
+ parse_mode?: 'markdown'|'html', // Text formatting
383
+ message_id?: number // Edit existing message (omit for new)
384
+ )
385
+ ```
386
+
387
+ **Examples:**
388
+ ```json
389
+ // Send new message
390
+ {"tool": "send_or_edit_message", "params": {
391
+ "chat_id": "me",
392
+ "message": "Hello from AI! 🚀"
393
+ }}
394
+
395
+ // Edit existing message
396
+ {"tool": "send_or_edit_message", "params": {
397
+ "chat_id": "-1001234567890",
398
+ "message": "Updated: Project deadline extended",
399
+ "message_id": 12345
400
+ }}
401
+
402
+ // Reply with formatting
403
+ {"tool": "send_or_edit_message", "params": {
404
+ "chat_id": "@username",
405
+ "message": "*Important:* Meeting at 3 PM",
406
+ "parse_mode": "markdown",
407
+ "reply_to_msg_id": 67890
408
+ }}
409
+ ```
410
+
411
+ ### 📖 read_messages
412
+ **Read specific messages by ID**
413
+
414
+ ```typescript
415
+ read_messages(
416
+ chat_id: str, // Chat identifier ('me', username, or numeric ID)
417
+ message_ids: number[] // Array of message IDs to retrieve
418
+ )
419
+ ```
420
+
421
+ **Supported chat formats:**
422
+ - `'me'` - Saved Messages
423
+ - `@username` - Username
424
+ - `123456789` - User ID
425
+ - `-1001234567890` - Channel ID
426
+
427
+ **Examples:**
428
+ ```json
429
+ // Read multiple messages from Saved Messages
430
+ {"tool": "read_messages", "params": {
431
+ "chat_id": "me",
432
+ "message_ids": [680204, 680205, 680206]
433
+ }}
434
+
435
+ // Read from a channel
436
+ {"tool": "read_messages", "params": {
437
+ "chat_id": "-1001234567890",
438
+ "message_ids": [123, 124, 125]
439
+ }}
440
+ ```
441
+
442
+ ### 👥 search_contacts
443
+ **Find users and contacts**
444
+
445
+ ```typescript
446
+ search_contacts(
447
+ query: str, // Search term (name, username, or phone)
448
+ limit?: number = 20 // Max results to return
449
+ )
450
+ ```
451
+
452
+ **Search capabilities:**
453
+ - **Saved contacts** - Your Telegram contacts
454
+ - **Global users** - Public Telegram users
455
+ - **Channels & groups** - Public channels and groups
456
+
457
+ **Query formats:**
458
+ - Name: `"John Doe"`
459
+ - Username: `"telegram"` (without @)
460
+ - Phone: `"+1234567890"`
461
+
462
+ **Examples:**
463
+ ```json
464
+ // Find by username
465
+ {"tool": "search_contacts", "params": {"query": "telegram"}}
466
+
467
+ // Find by name
468
+ {"tool": "search_contacts", "params": {"query": "John Smith"}}
469
+
470
+ // Find by phone
471
+ {"tool": "search_contacts", "params": {"query": "+1234567890"}}
472
+ ```
473
+
474
+ ### ℹ️ get_contact_details
475
+ **Get user/chat profile information**
476
+
477
+ ```typescript
478
+ get_contact_details(
479
+ chat_id: str // User/channel identifier
480
+ )
481
+ ```
482
+
483
+ **Returns:** Bio, status, online state, profile photos, and more
484
+
485
+ **Examples:**
486
+ ```json
487
+ // Get user details by ID
488
+ {"tool": "get_contact_details", "params": {"chat_id": "133526395"}}
489
+
490
+ // Get details by username
491
+ {"tool": "get_contact_details", "params": {"chat_id": "telegram"}}
492
+
493
+ // Get channel information
494
+ {"tool": "get_contact_details", "params": {"chat_id": "-1001234567890"}}
495
+ ```
496
+
497
+ ### 📱 send_message_to_phone
498
+ **Message by phone number (auto-contact management)**
499
+
500
+ ```typescript
501
+ send_message_to_phone(
502
+ phone_number: str, // Phone with country code (+1234567890)
503
+ message: str, // Message content
504
+ first_name?: str = "Contact", // For new contacts
505
+ last_name?: str = "Name", // For new contacts
506
+ remove_if_new?: boolean = false, // Remove temp contact after send
507
+ parse_mode?: 'markdown'|'html' // Text formatting
508
+ )
509
+ ```
510
+
511
+ **Features:**
512
+ - Auto-creates contact if phone not in contacts
513
+ - Optional contact cleanup after sending
514
+ - Full formatting support
515
+
516
+ **Examples:**
517
+ ```json
518
+ // Basic message to new contact
519
+ {"tool": "send_message_to_phone", "params": {
520
+ "phone_number": "+1234567890",
521
+ "message": "Hello from AI! 🤖"
522
+ }}
523
+
524
+ // Message with formatting and cleanup
525
+ {"tool": "send_message_to_phone", "params": {
526
+ "phone_number": "+1234567890",
527
+ "message": "*Urgent:* Meeting rescheduled to 4 PM",
528
+ "parse_mode": "markdown",
529
+ "remove_if_new": true
530
+ }}
531
+ ```
532
+
533
+ ### 🔧 invoke_mtproto
534
+ **Direct Telegram API access**
535
+
536
+ ```typescript
537
+ invoke_mtproto(
538
+ method_full_name: str, // Full API method name (e.g., "messages.GetHistory")
539
+ params_json: str // JSON string of method parameters
540
+ )
541
+ ```
542
+
543
+ **Use cases:** Advanced operations not covered by standard tools
544
+
545
+ **Examples:**
546
+ ```json
547
+ // Get your own user information
548
+ {"tool": "invoke_mtproto", "params": {
549
+ "method_full_name": "users.GetFullUser",
550
+ "params_json": "{\"id\": {\"_\": \"inputUserSelf\"}}"
551
+ }}
552
+
553
+ // Get chat message history
554
+ {"tool": "invoke_mtproto", "params": {
555
+ "method_full_name": "messages.GetHistory",
556
+ "params_json": "{\"peer\": {\"_\": \"inputPeerChannel\", \"channel_id\": 123456, \"access_hash\": 0}, \"limit\": 10}"
557
+ }}
558
+ ```
559
+
560
+ ## 📁 Project Structure
561
+
562
+ ```
563
+ fast-mcp-telegram/
564
+ ├── sessions/ # 🆕 Dedicated session storage
565
+ │ ├── mcp_telegram.session # Authenticated Telegram session
566
+ │ └── .gitkeep # Maintains directory structure
567
+ ├── src/ # Source code directory
568
+ │ ├── client/ # Telegram client management
569
+ │ ├── config/ # Configuration settings
570
+ │ ├── tools/ # MCP tool implementations
571
+ │ ├── utils/ # Utility functions
572
+ │ ├── __init__.py # Package initialization
573
+ │ ├── server.py # Main server implementation
574
+ │ └── setup_telegram.py # Telegram setup script
575
+ ├── scripts/ # Deployment and utility scripts
576
+ │ └── deploy-mcp.sh # Enhanced deployment script
577
+ ├── logs/ # Log files directory
578
+ ├── pyproject.toml # Package setup configuration
579
+ ├── uv.lock # Dependency lock file
580
+ ├── docker-compose.yml # Production Docker configuration
581
+ ├── Dockerfile # Multi-stage UV build
582
+ ├── .env # Environment variables (create this)
583
+ ├── .gitignore # Git ignore patterns (includes sessions/)
584
+ └── LICENSE # MIT License
585
+
586
+ Note: After authentication, `mcp_telegram.session` will be created in your project root directory. This file contains your authenticated Telegram session and should be kept secure.
587
+
588
+ **Important:** When deploying remotely, you must authenticate with Telegram on the remote server after deployment. Session files are not transferred during deployment for security reasons.
589
+ ```
590
+
591
+ ## 📦 Dependencies
592
+
593
+ | Package | Purpose |
594
+ |---------|---------|
595
+ | **fastmcp** | MCP server framework |
596
+ | **telethon** | Telegram API client |
597
+ | **loguru** | Structured logging |
598
+ | **aiohttp** | Async HTTP client |
599
+ | **python-dotenv** | Environment management |
600
+
601
+ **Installation:** `uv sync` (dependencies managed via `pyproject.toml`)
602
+
603
+ ---
604
+
605
+ ## 🔒 Security
606
+
607
+ **🚨 CRITICAL SECURITY WARNING:** Once authenticated, anyone with access to this MCP server can perform **ANY action** on your Telegram account. Implement proper access controls before deployment.
608
+
609
+ **Session files contain your complete Telegram access - keep them secure and never commit to version control.**
610
+
611
+ ---
612
+
613
+ ## 🤝 Contributing
614
+
615
+ 1. Fork the repository
616
+ 2. Create a feature branch: `git checkout -b feature/amazing-feature`
617
+ 3. Commit changes: `git commit -m 'Add amazing feature'`
618
+ 4. Push to branch: `git push origin feature/amazing-feature`
619
+ 5. Open a Pull Request
620
+
621
+ **Development setup:**
622
+ ```bash
623
+ uv sync --all-extras # Install dev dependencies
624
+ uv run ruff format . # Format code
625
+ uv run ruff check . # Lint code
626
+ ```
627
+
628
+ ---
629
+
630
+ ## 📄 License
631
+
632
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
633
+
634
+ ---
635
+
636
+ ## 🙏 Acknowledgments
637
+
638
+ - [FastMCP](https://github.com/jlowin/fastmcp) - MCP server framework
639
+ - [Telethon](https://github.com/LonamiWebs/Telethon) - Telegram API library
640
+ - [Model Context Protocol](https://modelcontextprotocol.io) - Protocol specification
641
+
642
+ ---
643
+
644
+ <div align="center">
645
+
646
+ **Made with ❤️ for the AI automation community**
647
+
648
+ [⭐ Star us on GitHub](https://github.com/leshchenko1979/fast-mcp-telegram) • [💬 Join our community](https://t.me/mcp_telegram)
649
+
650
+ </div>