A Model Context Protocol (MCP) server that provides structured access to Telegram data. This MCP acts as a data bridge, allowing AI assistants to efficiently access and analyze Telegram messages, media, and chat information through the Model Context Protocol.
-
Get your Telegram API credentials:
# 1. Go to https://my.telegram.org/auth # 2. Log in with your phone number # 3. Go to 'API development tools' # 4. Create a new application # 5. Note down your api_id and api_hash
-
Clone this repository and create a
.envfile:git clone https://github.com/TeaGuild/mcp-telegram.git cd mcp-telegram cp .env.example .env # Edit .env to add your API credentials
-
Install dependencies:
pip install -e . # Or if you use uv: uv pip install -e .
-
Generate a session string:
python scripts/get_session.py
This will prompt for your phone number and verification code, then generate a session string to add to your
.envfile. -
Run the MCP server:
mcp dev mcp_telegram/server.py
The server logs are stored in
logs/telegram_server.log.
This MCP provides these tools for interacting with Telegram:
Get messages from a chat with optional filtering.
result = await mcp.call_tool("get_messages", {
"chat": "@username",
"limit": 10,
"offset_id": "12345", # Get messages before this ID
"from_date": "2024-02-01T00:00:00",
"has_media": True
})Returns structured message data including:
- Message text and timestamps
- Sender information
- Chat context
- Media details
- Forward information
- View counts
Search for messages across chats.
result = await mcp.call_tool("search_messages", {
"query": "project meeting",
"chats": ["@team", "@project"],
"limit": 10
})Get comprehensive information about a chat or user.
result = await mcp.call_tool("get_full_chat_info", {
"chat": "@username" # Defaults to "me" for your own account
})Get a list of chats (conversations) with basic information.
result = await mcp.call_tool("get_chat_list", {
"limit": 100, # Maximum number of chats to return
"offset_id": "12345", # Get chats before this message ID
"offset_date": "2024-02-01T00:00:00" # Get chats before this date
})Get contacts from your Telegram address book.
result = await mcp.call_tool("get_contacts")Send a message to a chat (with appropriate disclaimer).
result = await mcp.call_tool("send_message", {
"chat": "@username",
"text": "Hello from the Telegram MCP! This message was sent by an AI assistant.",
"parse_mode": "markdown", # Can be "markdown", "html", or "disabled"
"disable_web_page_preview": True
})Get media content (images) using a file_id.
result = await mcp.call_tool("get_media_content", {
"file_id": "ABCDEFG..." # File ID obtained from message media
})- Important: The session string provides full access to your Telegram account. Treat it like a password.
- Store credentials securely in environment variables and never commit them to version control.
- The MCP operates with your user account permissions - it can access any chat you have joined.
- Review the messages being sent with the
send_messagetool to ensure they comply with Telegram's terms of service.
Run the server with debug logging:
mcp dev mcp_telegram/server.pyLogs are written to logs/telegram_server.log.
To use this MCP with compatible AI assistants:
-
Start the MCP server
-
In a separate terminal, run:
mcp client
For specific assistants, you can use flags like:
mcp client --claude # For Claude mcp client --anthropic # For Anthropic's API directly
-
Connect to the MCP in the assistant conversation:
/connect telegram
This project is licensed under the MIT License - see the LICENSE file for details.