A powerful Telegram integration for Claude via the Model Context Protocol (MCP), allowing you to interact with your Telegram account directly from Claude Desktop.
This MCP server provides a comprehensive suite of tools for seamless Telegram interaction:
- get_chats - Get a paginated list of your chats
- list_chats - List all chats with detailed metadata and filtering options
- get_chat - Get detailed information about a specific chat
- get_messages - Get messages from a specific chat with pagination
- list_messages - Retrieve messages with powerful filtering (text search, date ranges)
- send_message - Send messages to any chat
- get_message_context - View the context around a specific message
- search_contacts - Find contacts by name, username or phone number
- get_direct_chat_by_contact - Find personal chats with specific contacts
- get_contact_chats - List all chats (including groups) involving a contact
- get_last_interaction - View your most recent exchanges with a contact
- Python 3.10+
- Telethon for Telegram API access
- MCP Python SDK
- UV package manager
- Claude Desktop app
git clone https://github.com/l1v0n1/telegram-mcp-server
cd telegram-mcp-server
For better security and portability, this project uses Telethon's StringSession. Generate your session string:
python session_string_generator.py
This will:
- Ask for your phone number
- Send a verification code to your Telegram app
- Generate a session string and add it to your
.env
file
The session string allows authentication without storing SQLite session files, which helps avoid database lock issues and improves portability.
Create a .env
file with your Telegram 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_here
You can obtain API credentials at my.telegram.org/apps.
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv add "mcp[cli]" telethon python-dotenv nest_asyncio
Edit ~/Library/Application Support/Claude/claude_desktop_config.json
:
{
"mcpServers": {
"telegram-mcp": {
"command": "/full/path/to/uv",
"args": [
"--directory",
"/full/path/to/telegram-mcp-server",
"run",
"main.py"
]
}
}
}
Edit %APPDATA%\Claude\claude_desktop_config.json
with similar configuration.
Here are some ways to interact with Telegram through Claude:
- "Show me my most recent chats"
- "List my group chats with unread messages"
- "Show detailed information about chat 123456789"
- "Show me the last 10 messages from chat 123456789"
- "Send 'I'll be there in 10 minutes' to chat 123456789"
- "Find messages containing 'meeting' in chat 123456789"
- "Show messages from March 1-15, 2023 in chat 123456789"
- "Search for contacts named 'Alex'"
- "Find my direct chat with John"
- "Show all chats where I interact with contact 987654321"
- "Show my last conversation with Lisa"
- "Show the context around message 42 in chat 123456789"
- "List all channels I'm subscribed to"
- Private API Keys: Never commit your
.env
file or session files to Git repositories - Session String: The session string in your
.env
file provides full access to your Telegram account. Keep it secure. - Local Processing: All Telegram data is processed locally on your machine - no data is sent to external servers beyond Telegram's own API.
- Permissions: The MCP server has the same access to Telegram as you would have with the official app, including reading and sending messages.
If you encounter issues:
- Check Claude Desktop logs for error messages
- Ensure your Telegram API credentials are correct
- Verify that the paths in your Claude Desktop config are absolute and correct
- If you see database lock errors, use the session string authentication method
- If you need to regenerate your session string, run
python session_string_generator.py
again
This project is licensed under the Apache 2.0 License.
- Telethon for the Telegram client library
- Model Context Protocol for the integration framework
- Anthropic for Claude and the Claude Desktop app