home / mcp / telegram mcp server
Telegram MCP server powered by Telethon to let MCP clients read chats, manage groups, and send/modify messages, media, contacts, and settings.
Configuration
View docs{
"mcpServers": {
"chigwell-telegram-mcp": {
"command": "uv",
"args": [
"--directory",
"/full/path/to/telegram-mcp",
"run",
"main.py"
],
"env": {
"TELEGRAM_API_ID": "your_api_id_here",
"TELEGRAM_API_HASH": "your_api_hash_here",
"TELEGRAM_SESSION_NAME": "anon",
"TELEGRAM_SESSION_STRING": "your_session_string_here"
}
}
}
}You can control and automate your Telegram account programmatically using the Telegram MCP Server, enabling rich chat, group, and message management through MCP-compatible clients. This server exposes a wide range of Telethon-based capabilities that you can drive from Claude, Cursor, or any MCP client to perform operations like reading chat histories, sending messages, managing participants, and subscribing to channels, all with robust input validation and fallbacks.
You interact with the Telegram MCP Server through an MCP client by configuring the MCP connection as either a local (stdio) server or a remote HTTP server. The server is designed to understand a broad set of Telegram actions, mapped to tools you call from your client. Begin by starting the server locally or in a container, then connect your MCP client using the recommended configuration. Use the provided tools to read chats, send messages, manage groups, and handle invitations or inline button callbacks. The design includes input validation for chat and user IDs and multiple fallbacks for critical tasks to improve reliability in real-world use.
Prerequisites: Python 3.10+, Telethon, MCP Python SDK, and an MCP client such as Claude Desktop or Cursor.
# 1. Clone the project
git clone https://github.com/chigwell/telegram-mcp.git
cd telegram-mcp
# 2. Install dependencies with uv
uv sync
# 3. Generate a session string
uv run session_string_generator.py
# 4. Configure environment variables
# Copy .env.example to .env and fill in your credentials
# TELEGRAM_API_ID=your_api_id_here
# TELEGRAM_API_HASH=your_api_hash_here
# TELEGRAM_SESSION_NAME=anon
# TELEGRAM_SESSION_STRING=your_session_string_hereYou can configure the MCP connection directly in your Claude or Cursor configuration to point to the Telegram MCP Server. The example shows a complete stdio configuration that uses uv to run the server from a specified directory.
{
"mcpServers": {
"telegram-mcp": {
"command": "uv",
"args": [
"--directory",
"/full/path/to/telegram-mcp",
"run",
"main.py"
]
}
}
}If you prefer containerized deployment, you can build and run the server with Docker. The process includes building the image and choosing either Docker Compose or a direct docker run invocation.
# 1. Build the image
docker build -t telegram-mcp:latest .
# Option A: Docker Compose (recommended for local use)
# 2A. Create a .env file in the project root with TELeGRAM_API_ID, TELEGRAM_API_HASH, and TELEGRAM_SESSION_STRING
# 3A. Run
docker compose up --build
# To run in the background
# docker compose up -d
# Stop with Ctrl+C
```
```bash
# Option B: Direct docker run
helmThe server requires Telegram API credentials and a session string. You typically provide these through a .env file or environment variables when running in Docker. The common variables include TELEGRAM_API_ID, TELEGRAM_API_HASH, and TELEGRAM_SESSION_STRING or TELEGRAM_SESSION_NAME. The session string grants access to your Telegram account, so protect it accordingly.
Never expose your session string or API credentials. Treat the session string as a sensitive credential that grants full account access. All processing happens locally in the MCP client context; no data leaves your environment except requests to Telegram.
If you encounter issues, check the mcp_errors.log for detailed error messages, verify that your .env or environment variables are correctly set, and ensure the Telethon-based client has the necessary permissions for the requested actions. If a function requires a bot account, you will receive a clear notification.
Fetch a paginated list of chats with optional paging parameters.
List chats with metadata and optional filters.
Retrieve detailed information about a specific chat.
Create a new group with a list of user IDs.
Invite users to a group or channel.
Create a channel or supergroup with a title and description.
Change the title of a chat, group, or channel.
Remove the chat photo.
Leave a chat or channel.
List all participants of a chat.
List all admins of a chat.
List all banned users in a chat.
Promote a user to admin in a chat.
Demote an admin to a regular member.
Ban a user from a chat.
Unban a user from a chat.
Get an invite link for a chat.
Export an invite link for a chat.
Join a chat using an invite hash.
Join a chat by invite link.
Subscribe to a public channel or supergroup.
Fetch messages from a chat with paging.
Filter messages by date or search terms.
List forum topics in a supergroup.
Send a message to a chat.
Reply to a specific message in a chat.
Edit an existing message.
Delete a message.
Forward a message to another chat.
Pin a message in a chat.
Unpin a message.
Mark messages as read in a chat.
Get surrounding context for a message.
Retrieve full chat history.
List pinned messages in a chat.
Get the most recent message with a contact.
Create a poll with options.
Inspect inline keyboard buttons and their indices.
Trigger an inline keyboard callback by label or index.
Add a reaction to a message.
Remove a reaction from a message.
Get all reactions on a message.
List all contacts.
Search contacts by query.
Add a new contact.
Delete a contact.
Block a user.
Unblock a user.
Bulk import contacts.
Export all contacts as JSON.
List blocked users.
List all contact IDs.
Find direct chats with a specific contact.
List all chats with a contact.
Get your user information.
Update your profile details.
Remove your profile photo.
Fetch a user's profile photos.
Get a user's online status.
Get information about media attached to a message.
Search public chats, channels, or bots.
Search messages within a chat.
Resolve a username to an ID.