telegram-desktop-mcp 0.1.0__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.
- telegram_desktop_mcp-0.1.0/.env.example +3 -0
- telegram_desktop_mcp-0.1.0/.github/workflows/publish.yml +35 -0
- telegram_desktop_mcp-0.1.0/.github/workflows/python-publish.yml +70 -0
- telegram_desktop_mcp-0.1.0/.gitignore +6 -0
- telegram_desktop_mcp-0.1.0/PKG-INFO +188 -0
- telegram_desktop_mcp-0.1.0/README.md +176 -0
- telegram_desktop_mcp-0.1.0/pyproject.toml +23 -0
- telegram_desktop_mcp-0.1.0/requirements.txt +37 -0
- telegram_desktop_mcp-0.1.0/server.py +75 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
workflow_dispatch: # يتيح لك تشغيل النشر يدوياً بضغطة زر من تبويب Actions
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
pypi-publish:
|
|
11
|
+
name: Upload release to PyPI
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
environment:
|
|
14
|
+
name: pypi
|
|
15
|
+
url: https://pypi.org/p/${{ github.event.repository.name }}
|
|
16
|
+
permissions:
|
|
17
|
+
id-token: write # إلزامي للمصادقة الموثوقة مع PyPI بدون كلمات سر
|
|
18
|
+
|
|
19
|
+
steps:
|
|
20
|
+
- name: Checkout code
|
|
21
|
+
uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Python
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: "3.11"
|
|
27
|
+
|
|
28
|
+
- name: Install build tools
|
|
29
|
+
run: pip install build
|
|
30
|
+
|
|
31
|
+
- name: Build package
|
|
32
|
+
run: python -m build
|
|
33
|
+
|
|
34
|
+
- name: Publish package distributions to PyPI
|
|
35
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# This workflow will upload a Python Package to PyPI when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
+
|
|
4
|
+
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
+
# They are provided by a third-party and are governed by
|
|
6
|
+
# separate terms of service, privacy policy, and support
|
|
7
|
+
# documentation.
|
|
8
|
+
|
|
9
|
+
name: Upload Python Package
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
release:
|
|
13
|
+
types: [published]
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
release-build:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.x"
|
|
28
|
+
|
|
29
|
+
- name: Build release distributions
|
|
30
|
+
run: |
|
|
31
|
+
# NOTE: put your own distribution build steps here.
|
|
32
|
+
python -m pip install build
|
|
33
|
+
python -m build
|
|
34
|
+
|
|
35
|
+
- name: Upload distributions
|
|
36
|
+
uses: actions/upload-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: release-dists
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
pypi-publish:
|
|
42
|
+
runs-on: ubuntu-latest
|
|
43
|
+
needs:
|
|
44
|
+
- release-build
|
|
45
|
+
permissions:
|
|
46
|
+
# IMPORTANT: this permission is mandatory for trusted publishing
|
|
47
|
+
id-token: write
|
|
48
|
+
|
|
49
|
+
# Dedicated environments with protections for publishing are strongly recommended.
|
|
50
|
+
# For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
|
|
51
|
+
environment:
|
|
52
|
+
name: pypi
|
|
53
|
+
# OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
|
|
54
|
+
# url: https://pypi.org/p/YOURPROJECT
|
|
55
|
+
#
|
|
56
|
+
# ALTERNATIVE: if your GitHub Release name is the PyPI project version string
|
|
57
|
+
# ALTERNATIVE: exactly, uncomment the following line instead:
|
|
58
|
+
# url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }}
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- name: Retrieve release distributions
|
|
62
|
+
uses: actions/download-artifact@v4
|
|
63
|
+
with:
|
|
64
|
+
name: release-dists
|
|
65
|
+
path: dist/
|
|
66
|
+
|
|
67
|
+
- name: Publish release distributions to PyPI
|
|
68
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
69
|
+
with:
|
|
70
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: telegram-desktop-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Telegram MCP server to control Telegram and read PDFs
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: mcp>=1.0.0
|
|
7
|
+
Requires-Dist: pypdf>=4.0.0
|
|
8
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
9
|
+
Requires-Dist: qrcode>=7.4.0
|
|
10
|
+
Requires-Dist: telethon>=1.36.0
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Telegram MCP Server
|
|
14
|
+
|
|
15
|
+
Telegram MCP server scaffold that logs in to Telegram using a QR code before starting the MCP server.
|
|
16
|
+
|
|
17
|
+
This project uses:
|
|
18
|
+
|
|
19
|
+
- `telethon` to connect to Telegram
|
|
20
|
+
- `qrcode` to print a login QR code in the terminal
|
|
21
|
+
- `python-dotenv` to load private keys from a local `.env` file
|
|
22
|
+
|
|
23
|
+
> مهم: لا ترفع مفاتيح Telegram الخاصة بك أو ملف `.session` إلى GitHub.
|
|
24
|
+
|
|
25
|
+
## Requirements
|
|
26
|
+
|
|
27
|
+
- Python 3.10+
|
|
28
|
+
- Telegram account
|
|
29
|
+
- Telegram API credentials from <https://my.telegram.org>
|
|
30
|
+
|
|
31
|
+
## 1. Get Telegram API ID and API Hash
|
|
32
|
+
|
|
33
|
+
1. Open <https://my.telegram.org>
|
|
34
|
+
2. Login with your Telegram phone number
|
|
35
|
+
3. Go to **API development tools**
|
|
36
|
+
4. Create an app
|
|
37
|
+
5. Copy:
|
|
38
|
+
- `api_id`
|
|
39
|
+
- `api_hash`
|
|
40
|
+
|
|
41
|
+
## 2. Install dependencies
|
|
42
|
+
|
|
43
|
+
Create and activate a virtual environment:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
python -m venv .venv
|
|
47
|
+
source .venv/bin/activate
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Install packages:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install telethon qrcode python-dotenv
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## 3. Configure environment variables
|
|
57
|
+
|
|
58
|
+
Copy the example file:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cp .env.example .env
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Edit `.env`:
|
|
65
|
+
|
|
66
|
+
```env
|
|
67
|
+
TELEGRAM_API_ID=123456
|
|
68
|
+
TELEGRAM_API_HASH=your_api_hash_here
|
|
69
|
+
TELEGRAM_SESSION=telegram_mcp
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Replace the values with your real Telegram credentials.
|
|
73
|
+
|
|
74
|
+
## 4. How QR login works
|
|
75
|
+
|
|
76
|
+
When the server starts, it checks if your Telegram session is already authorized.
|
|
77
|
+
|
|
78
|
+
- If authorized, it continues normally.
|
|
79
|
+
- If not authorized, it prints a QR code in the terminal.
|
|
80
|
+
|
|
81
|
+
To login:
|
|
82
|
+
|
|
83
|
+
1. Open Telegram on your phone
|
|
84
|
+
2. Go to **Settings**
|
|
85
|
+
3. Go to **Devices**
|
|
86
|
+
4. Tap **Link Desktop Device**
|
|
87
|
+
5. Scan the QR code from the terminal
|
|
88
|
+
|
|
89
|
+
After scanning, a `.session` file is created locally. This file keeps you logged in.
|
|
90
|
+
|
|
91
|
+
## 5. Run
|
|
92
|
+
|
|
93
|
+
Current `server.py` contains the login helper and Telegram client setup.
|
|
94
|
+
|
|
95
|
+
If your MCP server has a main function, call this before starting MCP:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
await before_mcp_start()
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Example:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
async def main():
|
|
105
|
+
await before_mcp_start()
|
|
106
|
+
await mcp.run_async()
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Then run:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python server.py
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Project files
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
server.py # Telegram client and QR login helper
|
|
119
|
+
.env.example # Example environment variables
|
|
120
|
+
.gitignore # Prevents secrets/session files from being committed
|
|
121
|
+
README.md # Documentation
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Security notes
|
|
125
|
+
|
|
126
|
+
Do not commit or share these files:
|
|
127
|
+
|
|
128
|
+
- `.env`
|
|
129
|
+
- `*.session`
|
|
130
|
+
- `*.session-journal`
|
|
131
|
+
|
|
132
|
+
These files are ignored by `.gitignore`.
|
|
133
|
+
|
|
134
|
+
If you accidentally publish your API hash or session file, revoke/regenerate credentials from Telegram and delete the leaked session.
|
|
135
|
+
|
|
136
|
+
## Troubleshooting
|
|
137
|
+
|
|
138
|
+
### `Please set TELEGRAM_API_ID and TELEGRAM_API_HASH`
|
|
139
|
+
|
|
140
|
+
Make sure `.env` exists and contains valid values:
|
|
141
|
+
|
|
142
|
+
```env
|
|
143
|
+
TELEGRAM_API_ID=your_id
|
|
144
|
+
TELEGRAM_API_HASH=your_hash
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### QR code does not appear correctly
|
|
148
|
+
|
|
149
|
+
Make sure your terminal supports ASCII output and is wide enough. Try zooming out or using a larger terminal window.
|
|
150
|
+
|
|
151
|
+
### Login asks again every time
|
|
152
|
+
|
|
153
|
+
Make sure the `.session` file is not being deleted. The session name comes from:
|
|
154
|
+
|
|
155
|
+
```env
|
|
156
|
+
TELEGRAM_SESSION=telegram_mcp
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This creates a local file like:
|
|
160
|
+
|
|
161
|
+
```text
|
|
162
|
+
telegram_mcp.session
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Arabic quick start
|
|
166
|
+
|
|
167
|
+
1. ثبت المكتبات:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
pip install telethon qrcode python-dotenv
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
2. انسخ ملف البيئة:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
cp .env.example .env
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
3. ضع مفاتيحك داخل `.env`.
|
|
180
|
+
|
|
181
|
+
4. شغل السكربت:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
python server.py
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
5. امسح QR من تطبيق تيليجرام.
|
|
188
|
+
# Telegram-mcp
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Telegram MCP Server
|
|
2
|
+
|
|
3
|
+
Telegram MCP server scaffold that logs in to Telegram using a QR code before starting the MCP server.
|
|
4
|
+
|
|
5
|
+
This project uses:
|
|
6
|
+
|
|
7
|
+
- `telethon` to connect to Telegram
|
|
8
|
+
- `qrcode` to print a login QR code in the terminal
|
|
9
|
+
- `python-dotenv` to load private keys from a local `.env` file
|
|
10
|
+
|
|
11
|
+
> مهم: لا ترفع مفاتيح Telegram الخاصة بك أو ملف `.session` إلى GitHub.
|
|
12
|
+
|
|
13
|
+
## Requirements
|
|
14
|
+
|
|
15
|
+
- Python 3.10+
|
|
16
|
+
- Telegram account
|
|
17
|
+
- Telegram API credentials from <https://my.telegram.org>
|
|
18
|
+
|
|
19
|
+
## 1. Get Telegram API ID and API Hash
|
|
20
|
+
|
|
21
|
+
1. Open <https://my.telegram.org>
|
|
22
|
+
2. Login with your Telegram phone number
|
|
23
|
+
3. Go to **API development tools**
|
|
24
|
+
4. Create an app
|
|
25
|
+
5. Copy:
|
|
26
|
+
- `api_id`
|
|
27
|
+
- `api_hash`
|
|
28
|
+
|
|
29
|
+
## 2. Install dependencies
|
|
30
|
+
|
|
31
|
+
Create and activate a virtual environment:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python -m venv .venv
|
|
35
|
+
source .venv/bin/activate
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Install packages:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install telethon qrcode python-dotenv
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 3. Configure environment variables
|
|
45
|
+
|
|
46
|
+
Copy the example file:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp .env.example .env
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Edit `.env`:
|
|
53
|
+
|
|
54
|
+
```env
|
|
55
|
+
TELEGRAM_API_ID=123456
|
|
56
|
+
TELEGRAM_API_HASH=your_api_hash_here
|
|
57
|
+
TELEGRAM_SESSION=telegram_mcp
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Replace the values with your real Telegram credentials.
|
|
61
|
+
|
|
62
|
+
## 4. How QR login works
|
|
63
|
+
|
|
64
|
+
When the server starts, it checks if your Telegram session is already authorized.
|
|
65
|
+
|
|
66
|
+
- If authorized, it continues normally.
|
|
67
|
+
- If not authorized, it prints a QR code in the terminal.
|
|
68
|
+
|
|
69
|
+
To login:
|
|
70
|
+
|
|
71
|
+
1. Open Telegram on your phone
|
|
72
|
+
2. Go to **Settings**
|
|
73
|
+
3. Go to **Devices**
|
|
74
|
+
4. Tap **Link Desktop Device**
|
|
75
|
+
5. Scan the QR code from the terminal
|
|
76
|
+
|
|
77
|
+
After scanning, a `.session` file is created locally. This file keeps you logged in.
|
|
78
|
+
|
|
79
|
+
## 5. Run
|
|
80
|
+
|
|
81
|
+
Current `server.py` contains the login helper and Telegram client setup.
|
|
82
|
+
|
|
83
|
+
If your MCP server has a main function, call this before starting MCP:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
await before_mcp_start()
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Example:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
async def main():
|
|
93
|
+
await before_mcp_start()
|
|
94
|
+
await mcp.run_async()
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Then run:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
python server.py
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Project files
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
server.py # Telegram client and QR login helper
|
|
107
|
+
.env.example # Example environment variables
|
|
108
|
+
.gitignore # Prevents secrets/session files from being committed
|
|
109
|
+
README.md # Documentation
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Security notes
|
|
113
|
+
|
|
114
|
+
Do not commit or share these files:
|
|
115
|
+
|
|
116
|
+
- `.env`
|
|
117
|
+
- `*.session`
|
|
118
|
+
- `*.session-journal`
|
|
119
|
+
|
|
120
|
+
These files are ignored by `.gitignore`.
|
|
121
|
+
|
|
122
|
+
If you accidentally publish your API hash or session file, revoke/regenerate credentials from Telegram and delete the leaked session.
|
|
123
|
+
|
|
124
|
+
## Troubleshooting
|
|
125
|
+
|
|
126
|
+
### `Please set TELEGRAM_API_ID and TELEGRAM_API_HASH`
|
|
127
|
+
|
|
128
|
+
Make sure `.env` exists and contains valid values:
|
|
129
|
+
|
|
130
|
+
```env
|
|
131
|
+
TELEGRAM_API_ID=your_id
|
|
132
|
+
TELEGRAM_API_HASH=your_hash
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### QR code does not appear correctly
|
|
136
|
+
|
|
137
|
+
Make sure your terminal supports ASCII output and is wide enough. Try zooming out or using a larger terminal window.
|
|
138
|
+
|
|
139
|
+
### Login asks again every time
|
|
140
|
+
|
|
141
|
+
Make sure the `.session` file is not being deleted. The session name comes from:
|
|
142
|
+
|
|
143
|
+
```env
|
|
144
|
+
TELEGRAM_SESSION=telegram_mcp
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
This creates a local file like:
|
|
148
|
+
|
|
149
|
+
```text
|
|
150
|
+
telegram_mcp.session
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Arabic quick start
|
|
154
|
+
|
|
155
|
+
1. ثبت المكتبات:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
pip install telethon qrcode python-dotenv
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
2. انسخ ملف البيئة:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
cp .env.example .env
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
3. ضع مفاتيحك داخل `.env`.
|
|
168
|
+
|
|
169
|
+
4. شغل السكربت:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
python server.py
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
5. امسح QR من تطبيق تيليجرام.
|
|
176
|
+
# Telegram-mcp
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "telegram-desktop-mcp" # نفس الاسم الذي وضعته في PyPI
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A Telegram MCP server to control Telegram and read PDFs"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"mcp>=1.0.0",
|
|
13
|
+
"telethon>=1.36.0",
|
|
14
|
+
"pypdf>=4.0.0",
|
|
15
|
+
"qrcode>=7.4.0",
|
|
16
|
+
"python-dotenv>=1.0.0",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.scripts]
|
|
20
|
+
telegram-mcp = "server:main"
|
|
21
|
+
|
|
22
|
+
[tool.hatch.build.targets.wheel]
|
|
23
|
+
only-include = ["server.py"]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
annotated-types==0.8.0
|
|
2
|
+
anyio==4.15.1
|
|
3
|
+
arabic-reshaper==3.0.1
|
|
4
|
+
attrs==26.1.0
|
|
5
|
+
cffi==2.1.1
|
|
6
|
+
click==8.5.0
|
|
7
|
+
cryptography==50.0.1
|
|
8
|
+
h11==0.16.0
|
|
9
|
+
httpcore2==2.13.1
|
|
10
|
+
httpx2==2.13.1
|
|
11
|
+
idna==3.20
|
|
12
|
+
jsonschema==4.26.0
|
|
13
|
+
jsonschema-specifications==2025.9.1
|
|
14
|
+
mcp==2.2.0
|
|
15
|
+
mcp-types==2.2.0
|
|
16
|
+
opentelemetry-api==1.45.0
|
|
17
|
+
pyaes==1.6.1
|
|
18
|
+
pyasn1==0.6.4
|
|
19
|
+
pycparser==3.0
|
|
20
|
+
pydantic==2.13.5
|
|
21
|
+
pydantic_core==2.46.5
|
|
22
|
+
PyJWT==2.15.0
|
|
23
|
+
pypdf==6.19.0
|
|
24
|
+
python-bidi==0.6.11
|
|
25
|
+
python-dotenv==1.2.3
|
|
26
|
+
python-multipart==0.0.32
|
|
27
|
+
qrcode==8.2
|
|
28
|
+
referencing==0.37.0
|
|
29
|
+
rpds-py==2026.6.3
|
|
30
|
+
rsa==4.9.1
|
|
31
|
+
sse-starlette==3.4.11
|
|
32
|
+
starlette==1.7.0
|
|
33
|
+
Telethon==1.45.0
|
|
34
|
+
truststore==0.10.4
|
|
35
|
+
typing_extensions==4.16.0
|
|
36
|
+
typing-inspection==0.4.4
|
|
37
|
+
uvicorn==0.54.0
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
import qrcode
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
from telethon import TelegramClient
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import arabic_reshaper
|
|
10
|
+
from bidi.algorithm import get_display
|
|
11
|
+
except ImportError: # Optional terminal-only display helpers.
|
|
12
|
+
arabic_reshaper = None
|
|
13
|
+
get_display = None
|
|
14
|
+
|
|
15
|
+
load_dotenv()
|
|
16
|
+
|
|
17
|
+
API_ID = int(os.getenv("TELEGRAM_API_ID", "0"))
|
|
18
|
+
API_HASH = os.getenv("TELEGRAM_API_HASH", "")
|
|
19
|
+
SESSION_NAME = os.getenv("TELEGRAM_SESSION", "telegram_mcp")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if not API_ID or not API_HASH:
|
|
23
|
+
raise RuntimeError(
|
|
24
|
+
"Please set TELEGRAM_API_ID and TELEGRAM_API_HASH in environment variables or a .env file."
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
client = TelegramClient(SESSION_NAME, API_ID, API_HASH)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
32
|
+
sys.stdout.reconfigure(encoding="utf-8")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def terminal_arabic(text: str) -> str:
|
|
36
|
+
"""Shape Arabic so it displays correctly in LTR terminals and agent output."""
|
|
37
|
+
if arabic_reshaper and get_display:
|
|
38
|
+
return get_display(arabic_reshaper.reshape(text))
|
|
39
|
+
return text
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def print_arabic(text: str = "") -> None:
|
|
43
|
+
print(terminal_arabic(text))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
async def login_with_qr(client: TelegramClient):
|
|
47
|
+
"""Log in to Telegram using a QR code before starting the MCP server."""
|
|
48
|
+
if not client.is_connected():
|
|
49
|
+
await client.connect()
|
|
50
|
+
|
|
51
|
+
if await client.is_user_authorized():
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
qr_login = await client.qr_login()
|
|
55
|
+
print()
|
|
56
|
+
print_arabic("--- امسح رمز QR التالي من تطبيق تيليجرام على هاتفك: ---")
|
|
57
|
+
|
|
58
|
+
qr = qrcode.QRCode()
|
|
59
|
+
qr.add_data(qr_login.url)
|
|
60
|
+
qr.print_ascii(invert=True)
|
|
61
|
+
|
|
62
|
+
await qr_login.wait()
|
|
63
|
+
print_arabic("تم تسجيل الدخول بنجاح!")
|
|
64
|
+
print()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
async def before_mcp_start():
|
|
68
|
+
"""Call this before running the MCP server."""
|
|
69
|
+
await login_with_qr(client)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# Example usage when you add/run your MCP server:
|
|
73
|
+
# async def main():
|
|
74
|
+
# await before_mcp_start()
|
|
75
|
+
# await mcp.run_async()
|