mcp-server-telegram-pager 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.
- mcp_server_telegram_pager-0.1.0/.gitignore +35 -0
- mcp_server_telegram_pager-0.1.0/PKG-INFO +62 -0
- mcp_server_telegram_pager-0.1.0/README.md +53 -0
- mcp_server_telegram_pager-0.1.0/pyproject.toml +18 -0
- mcp_server_telegram_pager-0.1.0/src/mcp_server_telegram_pager/__init__.py +4 -0
- mcp_server_telegram_pager-0.1.0/src/mcp_server_telegram_pager/generate_session.py +28 -0
- mcp_server_telegram_pager-0.1.0/src/mcp_server_telegram_pager/server.py +47 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
env/
|
|
8
|
+
build/
|
|
9
|
+
develop-eggs/
|
|
10
|
+
dist/
|
|
11
|
+
downloads/
|
|
12
|
+
eggs/
|
|
13
|
+
.eggs/
|
|
14
|
+
lib/
|
|
15
|
+
lib64/
|
|
16
|
+
parts/
|
|
17
|
+
sdist/
|
|
18
|
+
var/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual Environment
|
|
24
|
+
.env
|
|
25
|
+
.venv
|
|
26
|
+
venv/
|
|
27
|
+
ENV/
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
|
32
|
+
|
|
33
|
+
# Session Data
|
|
34
|
+
*.session
|
|
35
|
+
*.session-journal
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcp-server-telegram-pager
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A send-only Telegram Pager MCP server for personal AI notifications
|
|
5
|
+
Requires-Python: >=3.10
|
|
6
|
+
Requires-Dist: mcp>=1.0.0
|
|
7
|
+
Requires-Dist: telethon>=1.36.0
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# Telegram Pager MCP Server
|
|
11
|
+
|
|
12
|
+
A specialized [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that allows AI coding assistants (like Cursor, Cline, or Claude Desktop) to send direct messages via your personal Telegram account.
|
|
13
|
+
|
|
14
|
+
**Security First:** This server exposes exactly *one* tool (`send_telegram_message`). It is intentionally designed as a "Telegram Pager", meaning the AI cannot read your chat history, delete messages, or view your contacts.
|
|
15
|
+
|
|
16
|
+
## Prerequisites
|
|
17
|
+
|
|
18
|
+
To use this, you need a Telegram API ID and Hash.
|
|
19
|
+
1. Log in to [my.telegram.org/apps](https://my.telegram.org/apps).
|
|
20
|
+
2. Create an application (if you haven't already).
|
|
21
|
+
3. Copy your `App api_id` and `App api_hash`.
|
|
22
|
+
|
|
23
|
+
## Installation & Setup
|
|
24
|
+
|
|
25
|
+
1. **Clone the repository and install dependencies:**
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/ashizam/mcp-server-telegram-pager.git
|
|
28
|
+
cd mcp-server-telegram-pager
|
|
29
|
+
pipx install .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
2. **Generate your Session String:**
|
|
33
|
+
Because Telegram requires 2FA (a login code sent to your app), you must generate an authentication session string locally first.
|
|
34
|
+
```bash
|
|
35
|
+
mcp-server-telegram-pager-auth
|
|
36
|
+
```
|
|
37
|
+
*Follow the prompts to enter your API ID, Hash, and Login Code. Copy the long session string it outputs!*
|
|
38
|
+
|
|
39
|
+
## Configuring your MCP Client
|
|
40
|
+
|
|
41
|
+
Add the following to your IDE's MCP configuration file (e.g., in Cursor or Claude Desktop):
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"mcpServers": {
|
|
46
|
+
"telegram-pager": {
|
|
47
|
+
"command": "mcp-server-telegram-pager",
|
|
48
|
+
"env": {
|
|
49
|
+
"TELEGRAM_API_ID": "YOUR_API_ID_HERE",
|
|
50
|
+
"TELEGRAM_API_HASH": "YOUR_API_HASH_HERE",
|
|
51
|
+
"TELEGRAM_SESSION": "YOUR_LONG_SESSION_STRING_HERE"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## How to Test
|
|
59
|
+
Once configured, you can ask your AI assistant:
|
|
60
|
+
> "Send a Telegram message to username 'coolperson123' saying 'The build finished successfully!'"
|
|
61
|
+
|
|
62
|
+
*(Note: Do not include the `@` symbol in the username).*
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Telegram Pager MCP Server
|
|
2
|
+
|
|
3
|
+
A specialized [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that allows AI coding assistants (like Cursor, Cline, or Claude Desktop) to send direct messages via your personal Telegram account.
|
|
4
|
+
|
|
5
|
+
**Security First:** This server exposes exactly *one* tool (`send_telegram_message`). It is intentionally designed as a "Telegram Pager", meaning the AI cannot read your chat history, delete messages, or view your contacts.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
To use this, you need a Telegram API ID and Hash.
|
|
10
|
+
1. Log in to [my.telegram.org/apps](https://my.telegram.org/apps).
|
|
11
|
+
2. Create an application (if you haven't already).
|
|
12
|
+
3. Copy your `App api_id` and `App api_hash`.
|
|
13
|
+
|
|
14
|
+
## Installation & Setup
|
|
15
|
+
|
|
16
|
+
1. **Clone the repository and install dependencies:**
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/ashizam/mcp-server-telegram-pager.git
|
|
19
|
+
cd mcp-server-telegram-pager
|
|
20
|
+
pipx install .
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. **Generate your Session String:**
|
|
24
|
+
Because Telegram requires 2FA (a login code sent to your app), you must generate an authentication session string locally first.
|
|
25
|
+
```bash
|
|
26
|
+
mcp-server-telegram-pager-auth
|
|
27
|
+
```
|
|
28
|
+
*Follow the prompts to enter your API ID, Hash, and Login Code. Copy the long session string it outputs!*
|
|
29
|
+
|
|
30
|
+
## Configuring your MCP Client
|
|
31
|
+
|
|
32
|
+
Add the following to your IDE's MCP configuration file (e.g., in Cursor or Claude Desktop):
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"telegram-pager": {
|
|
38
|
+
"command": "mcp-server-telegram-pager",
|
|
39
|
+
"env": {
|
|
40
|
+
"TELEGRAM_API_ID": "YOUR_API_ID_HERE",
|
|
41
|
+
"TELEGRAM_API_HASH": "YOUR_API_HASH_HERE",
|
|
42
|
+
"TELEGRAM_SESSION": "YOUR_LONG_SESSION_STRING_HERE"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## How to Test
|
|
50
|
+
Once configured, you can ask your AI assistant:
|
|
51
|
+
> "Send a Telegram message to username 'coolperson123' saying 'The build finished successfully!'"
|
|
52
|
+
|
|
53
|
+
*(Note: Do not include the `@` symbol in the username).*
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcp-server-telegram-pager"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A send-only Telegram Pager MCP server for personal AI notifications"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"mcp>=1.0.0",
|
|
13
|
+
"telethon>=1.36.0"
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.scripts]
|
|
17
|
+
mcp-server-telegram-pager = "mcp_server_telegram_pager.server:main"
|
|
18
|
+
mcp-server-telegram-pager-auth = "mcp_server_telegram_pager.generate_session:main"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
from telethon.sync import TelegramClient
|
|
3
|
+
from telethon.sessions import StringSession
|
|
4
|
+
|
|
5
|
+
def main():
|
|
6
|
+
print("=======================================")
|
|
7
|
+
print(" Telegram Session Generator")
|
|
8
|
+
print("=======================================\n")
|
|
9
|
+
print("1. Go to https://my.telegram.org/apps and log in.")
|
|
10
|
+
print("2. Copy your App api_id and App api_hash.\n")
|
|
11
|
+
|
|
12
|
+
api_id = input("Enter your API_ID: ").strip()
|
|
13
|
+
api_hash = input("Enter your API_HASH: ").strip()
|
|
14
|
+
|
|
15
|
+
print("\nConnecting to Telegram... (You will receive a login code on your Telegram app)")
|
|
16
|
+
|
|
17
|
+
# Create an in-memory string session
|
|
18
|
+
with TelegramClient(StringSession(), int(api_id), api_hash) as client:
|
|
19
|
+
print("\n✅ Authentication Successful!")
|
|
20
|
+
print("\n=======================================")
|
|
21
|
+
print(" YOUR SESSION STRING (KEEP THIS SECRET)")
|
|
22
|
+
print("=======================================\n")
|
|
23
|
+
print(client.session.save())
|
|
24
|
+
print("\n=======================================")
|
|
25
|
+
print("Copy the long string above. You will need it for your MCP config.")
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
main()
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import asyncio
|
|
3
|
+
from mcp.server.fastmcp import FastMCP
|
|
4
|
+
from telethon import TelegramClient
|
|
5
|
+
from telethon.sessions import StringSession
|
|
6
|
+
|
|
7
|
+
# Initialize the MCP server
|
|
8
|
+
# This creates a server that exposes ONLY the tools defined below.
|
|
9
|
+
mcp = FastMCP("Telegram Pager")
|
|
10
|
+
|
|
11
|
+
@mcp.tool()
|
|
12
|
+
async def send_telegram_message(username: str, message: str) -> str:
|
|
13
|
+
"""
|
|
14
|
+
Send a direct message to a Telegram user.
|
|
15
|
+
Do not use the @ symbol in the username (e.g. use 'jakethesnake', not '@jakethesnake').
|
|
16
|
+
"""
|
|
17
|
+
api_id = os.environ.get("TELEGRAM_API_ID")
|
|
18
|
+
api_hash = os.environ.get("TELEGRAM_API_HASH")
|
|
19
|
+
session_str = os.environ.get("TELEGRAM_SESSION")
|
|
20
|
+
|
|
21
|
+
if not all([api_id, api_hash, session_str]):
|
|
22
|
+
return "Error: TELEGRAM_API_ID, TELEGRAM_API_HASH, and TELEGRAM_SESSION environment variables must be set."
|
|
23
|
+
|
|
24
|
+
try:
|
|
25
|
+
# Connect using the pre-authenticated session string
|
|
26
|
+
client = TelegramClient(StringSession(session_str), int(api_id), api_hash)
|
|
27
|
+
await client.connect()
|
|
28
|
+
|
|
29
|
+
if not await client.is_user_authorized():
|
|
30
|
+
await client.disconnect()
|
|
31
|
+
return "Error: Session is invalid or expired. Please generate a new session string."
|
|
32
|
+
|
|
33
|
+
# Send the message (this is the ONLY capability the AI has access to)
|
|
34
|
+
await client.send_message(username, message)
|
|
35
|
+
await client.disconnect()
|
|
36
|
+
|
|
37
|
+
return f"Successfully sent message to {username}."
|
|
38
|
+
|
|
39
|
+
except Exception as e:
|
|
40
|
+
return f"Failed to send message: {str(e)}"
|
|
41
|
+
|
|
42
|
+
def main():
|
|
43
|
+
"""Entry point for the package console script."""
|
|
44
|
+
mcp.run(transport="stdio")
|
|
45
|
+
|
|
46
|
+
if __name__ == "__main__":
|
|
47
|
+
main()
|