TeleMCP
by Adarshukumar
README.md
<div align="center">
<h1>✦ TeleMCP</h1>
<p><strong>Telegram Model Context Protocol</strong></p>
<p>Connect Telegram workflows to AI assistants through the Model Context Protocol.</p>
<p>
<a href="https://github.com/Adarshukumar/telemcp">
<img src="https://img.shields.io/badge/PROJECT-TeleMCP-18181B?style=for-the-badge" alt="TeleMCP project">
</a>
<a href="https://github.com/Adarshukumar/">
<img src="https://img.shields.io/badge/MAINTAINER-Adarsh%20Kumar-18181B?style=for-the-badge" alt="Maintainer: Adarsh Kumar">
</a>
<a href="https://modelcontextprotocol.io/">
<img src="https://img.shields.io/badge/PROTOCOL-MCP-7657D6?style=for-the-badge" alt="Model Context Protocol">
</a>
<a href="LICENSE">
<img src="https://img.shields.io/badge/LICENSE-MIT-0F766E?style=for-the-badge" alt="MIT License">
</a>
</p>
<p>
<a href="https://github.com/Adarshukumar/telemcp">Repository</a>
·
<a href="https://github.com/Adarshukumar/telemcp/issues">Issues</a>
·
<a href="https://modelcontextprotocol.io/">MCP documentation</a>
·
<a href="https://core.telegram.org/api">Telegram API</a>
</p>
</div>
---
## ✨ What is TeleMCP?
**TeleMCP** is a Python-based integration that exposes Telegram account operations as tools for applications that support the **Model Context Protocol (MCP)**. It lets an MCP-compatible AI client work with Telegram chats, messages, contacts, groups, channels, media, and supported profile operations through a configured Telegram account.
TeleMCP runs as a local MCP process and communicates with Telegram over the network. Local execution does **not** mean that Telegram API requests or account data never leave your device.
## At a glance
| Area | Capabilities |
|---|---|
| **Chats** | Discover conversations, inspect chats, send messages, archive and mute chats |
| **Messages** | Read history, search, reply, forward, edit, delete, and pin messages |
| **Contacts** | Search, add, remove, import, export, block, and unblock contacts |
| **Groups & channels** | Create and manage groups and channels, members, invitations, and permissions |
| **Media** | Send files, voice messages, stickers, and GIFs; inspect and download media |
| **Profile** | Read account information and manage supported profile and privacy settings |
## How it works
```mermaid
flowchart LR
A[AI assistant / MCP host] <-->|MCP requests and results| B[TeleMCP server]
B <-->|Telegram API requests| C[Telegram]
```
The MCP host launches TeleMCP as a local process. The assistant discovers the tools exposed by the server, calls the relevant tool, and receives the result from TeleMCP.
## 🧰 Tool showcase
The following tool names are documented for this project. The tools available at runtime depend on the installed code version and its configuration.
<details open>
<summary><strong>Chats</strong></summary>
- `get_chats` — List chats with pagination
- `list_chats` — List detailed metadata for users, groups, and channels
- `get_chat` — Get information about a specific chat
- `get_direct_chat_by_contact` — Find a direct chat for a contact
- `send_message` — Send a text message
- `archive_chat` / `unarchive_chat` — Archive or restore a chat
- `mute_chat` / `unmute_chat` — Manage chat notifications
- `get_invite_link` / `export_chat_invite` — Retrieve or export an invite link
- `join_chat_by_link` / `import_chat_invite` — Join using an invite link
</details>
<details>
<summary><strong>Messages</strong></summary>
- `get_messages` / `list_messages` — Retrieve messages
- `get_message_context` — Get context around a message
- `get_history` — Retrieve chat history with filters
- `search_messages` — Search messages in a chat
- `reply_to_message` — Reply to a message
- `forward_message` — Forward a message
- `edit_message` — Edit a sent message
- `delete_message` — Delete messages
- `pin_message` / `unpin_message` — Manage pinned messages
- `mark_as_read` — Mark messages as read
- `get_pinned_messages` — List pinned messages
</details>
<details>
<summary><strong>Contacts</strong></summary>
- `list_contacts` — List account contacts
- `search_contacts` — Search by name, username, or phone
- `get_contact_ids` — Resolve contact IDs
- `get_contact_chats` — Find chats for contacts
- `get_last_interaction` — Get the most recent interaction with a contact
- `add_contact` / `delete_contact` — Manage contacts
- `import_contacts` / `export_contacts` — Import or export contacts
- `block_user` / `unblock_user` — Manage blocked users
- `get_blocked_users` — List blocked users
- `resolve_username` — Resolve a Telegram username
- `search_public_chats` — Search public chats
</details>
<details>
<summary><strong>Groups and channels</strong></summary>
- `create_group` / `create_channel` — Create a group or channel
- `invite_to_group` — Invite members
- `leave_chat` — Leave a group or channel
- `get_participants` — List participants
- `edit_chat_title` — Change a chat title
- `edit_chat_photo` / `delete_chat_photo` — Manage a chat photo
- `promote_admin` / `demote_admin` — Manage administrator roles
- `ban_user` / `unban_user` — Manage membership restrictions
- `get_admins` — List administrators
- `get_banned_users` — List banned users
- `get_recent_actions` — View recent administrative actions
</details>
<details>
<summary><strong>Media</strong></summary>
- `send_file` — Send a document, photo, or video
- `download_media` — Download media from a message
- `get_media_info` — Inspect media metadata
- `send_voice` — Send a voice message
- `send_sticker` — Send a sticker
- `get_sticker_sets` — List available sticker sets
- `get_gif_search` — Search for GIFs
- `send_gif` — Send a GIF
</details>
<details>
<summary><strong>Profile</strong></summary>
- `get_me` — Get information about the authenticated account
- `update_profile` — Update supported profile fields
- `set_profile_photo` / `delete_profile_photo` — Manage profile photos
- `get_privacy_settings` / `set_privacy_settings` — Read or update privacy settings
- `get_user_photos` — Retrieve a user's profile photos
- `get_user_status` — Check a user's online status
- `get_bot_info` — Get bot information
- `set_bot_commands` — Configure bot commands
</details>
## 🚀 Installation
### Clone the repository
```bash
git clone https://github.com/Adarshukumar/telemcp.git
cd telemcp
```
### Install from source
Run this from the project root, where `pyproject.toml` is located:
```bash
python -m pip install -e .
```
Using an editable install means changes made in this checkout are available to the installed Python environment.
## 🔐 Telegram credentials
TeleMCP requires Telegram API credentials. Create a private `.env` file in your project directory, or provide the same values through your MCP client's environment configuration:
```dotenv
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
TELEGRAM_SESSION_NAME=telemcp
# Optional alternative to a session file:
# TELEGRAM_SESSION_STRING=your_session_string
```
Get your API ID and API hash from [Telegram's official API development page](https://my.telegram.org/apps). Never commit your API hash, session string, `.env` file, or `.session` file.
### First-time authentication
Choose one authentication method.
**Session string:**
```bash
python -m telemcp.session_string_generator
```
Add the generated value to `TELEGRAM_SESSION_STRING` in your private environment. Treat it like a password: anyone who obtains it may be able to access the authenticated Telegram session.
**Session file:**
```bash
python -m telemcp.authenticate
```
This creates a local session file. Keep it private and out of version control.
## 🔌 Connect to an MCP client
### Visual Studio Code
Add a server entry to `.vscode/mcp.json`. This example uses Python to launch the TeleMCP module and prompts for credentials instead of storing real secrets in the repository:
```json
{
"servers": {
"telegram": {
"type": "stdio",
"command": "python",
"args": ["-m", "telemcp"],
"env": {
"TELEGRAM_API_ID": "${input:telegram-api-id}",
"TELEGRAM_API_HASH": "${input:telegram-api-hash}",
"TELEGRAM_SESSION_STRING": "${input:telegram-session-string}",
"MCP_NONINTERACTIVE": "true"
}
}
},
"inputs": [
{
"id": "telegram-api-id",
"type": "promptString",
"description": "Telegram API ID"
},
{
"id": "telegram-api-hash",
"type": "promptString",
"description": "Telegram API hash",
"password": true
},
{
"id": "telegram-session-string",
"type": "promptString",
"description": "Telegram session string",
"password": true
}
]
}
```
The example uses the session-string method. For file-based authentication, replace `TELEGRAM_SESSION_STRING` with `TELEGRAM_SESSION_NAME` and use the session name configured on your machine. Keep the session file local.
The Python executable used by the MCP client must be the environment where TeleMCP is installed. MCP client configuration formats differ; adapt the example to the client you use.
## ▶️ Run locally
From the project root, start the module with:
```bash
python -m telemcp
```
## 🐍 Use from Python
```python
import asyncio
from telemcp import client
async def main() -> None:
await client.start()
try:
me = await client.get_me()
print(f"Connected account: {me.first_name}")
await client.send_message("username", "Hello from TeleMCP!")
finally:
await client.disconnect()
if __name__ == "__main__":
asyncio.run(main())
```
Replace `username` with the intended Telegram username or chat reference. Use this example only with an account and conversations you are authorized to access.
## ⚙️ Tool configuration
TeleMCP's tool groups are controlled by environment settings in the project configuration. The exact variable names should match the implementation in [`telemcp/tool_config.py`](telemcp/tool_config.py). Check that file in your checkout before adding optional switches to an MCP client configuration; renaming a variable in documentation alone does not change the runtime behavior.
## 🛡️ Security notes
- Keep `TELEGRAM_API_HASH`, `TELEGRAM_SESSION_STRING`, and session files private.
- Add `.env`, `*.session`, and local credential files to `.gitignore` before committing.
- Prefer environment variables or your MCP client's secret/input mechanism over hard-coded credentials.
- Enable only the tool groups required for the task, especially administrative tools.
- Review Telegram actions before allowing an AI client to send, edit, delete, forward, or administer content.
- TeleMCP needs network access to Telegram. Review the account permissions and trust boundary of every MCP client you connect.
## 🧪 Verification checklist
Before treating a checkout as ready for use, verify it in the environment where you intend to run it:
- [ ] Install the project in a clean virtual environment.
- [ ] Generate a session using the chosen authentication method.
- [ ] Start the MCP server and confirm that the client can discover its tools.
- [ ] Test read-only operations before enabling message-sending or administrative actions.
- [ ] Confirm that optional tool-group settings behave as expected.
- [ ] Confirm that `.env` and session files are excluded from Git.
This README describes the documented project interface; the checklist is included so that runtime behavior can be verified against the exact checkout. It is not a claim that these tests have already been run.
## 🤝 Contributing
Contributions, bug reports, and documentation improvements are welcome. When reporting an issue, include the Python version, MCP client, relevant tool name, and a sanitized error message. Never include API hashes, session strings, phone numbers, or private chat content in an issue.
## 📄 License and maintenance
This repository retains its existing MIT license. Keep the original copyright and license notice in [`LICENSE`](LICENSE) intact when redistributing or modifying the code.
Documentation and ongoing maintenance for this repository are presented under **Adarsh Kumar**. This maintainer credit does not transfer authorship or ownership of previously published material.
<div align="center">
<sub>Maintained by <a href="https://github.com/Adarshukumar/">Adarsh Kumar</a> · Built for AI-assisted Telegram workflows</sub>
</div>