Telegram MCP Server
Enables full access to your personal Telegram account via MCP, allowing reading, sending, and searching messages, managing chats, and retrieving user information through natural language commands.
README
Telegram MCP Server
A Model Context Protocol (MCP) server that provides full access to your personal Telegram account. This allows you to interact with your Telegram messages, chats, and contacts through MCP clients like Claude Desktop.
Features
- Full Account Access: Access all your personal messages, chats, and channels
- Message Management: Read, send, and search messages across all conversations
- Chat Operations: List, search, and get information about chats, groups, and channels
- User Information: Get details about users and contacts
- Real-time Operations: Mark messages as read and perform live actions
Prerequisites
- Telegram API Credentials: You need to obtain API credentials from Telegram
- Node.js: Version 18 or higher
- Your Phone Number: The phone number associated with your Telegram account
Setup Instructions
1. Get Telegram API Credentials
- Go to https://my.telegram.org/apps
- Log in with your phone number
- Create a new application:
- App title: Choose any name (e.g., "My MCP Server")
- Short name: Choose a short name (e.g., "mcp-server")
- Platform: Choose "Desktop"
- Note down your
api_idandapi_hash
2. Install Dependencies
npm install
3. Configure Environment
- Copy the example environment file:
cp .env.example .env
- Edit
.envand fill in your credentials:
TELEGRAM_API_ID=your_api_id_here
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_PHONE=+1234567890
NODE_ENV=production
SESSION_DIR=./session
4. Build the Project
npm run build
5. Authentication
Before using the MCP server, you need to authenticate with Telegram. Run the standalone authentication script:
npm run auth
You'll be prompted to:
- Enter the verification code sent to your Telegram app
- If you have 2FA enabled, enter your password
The session will be saved in the session/ directory and reused automatically by the MCP server.
MCP Client Configuration
Q CLI
For Amazon Q CLI, create or edit your MCP configuration file:
macOS/Linux: ~/.config/mcp/mcp.json
Windows: %APPDATA%\mcp\mcp.json
{
"mcpServers": {
"telegram": {
"command": "node",
"args": ["/Users/orrb/personal/workspace/telegram-mcp/dist/index.js"],
"env": {
"TELEGRAM_API_ID": "your_api_id",
"TELEGRAM_API_HASH": "your_api_hash",
"TELEGRAM_PHONE": "+1234567890"
}
}
}
}
Claude Desktop
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"telegram": {
"command": "node",
"args": ["/path/to/telegram-mcp-server/dist/index.js"],
"env": {
"TELEGRAM_API_ID": "your_api_id",
"TELEGRAM_API_HASH": "your_api_hash",
"TELEGRAM_PHONE": "+1234567890"
}
}
}
}
Cline (VS Code Extension)
For Cline, add the MCP server to your VS Code settings or Cline configuration:
{
"cline.mcpServers": {
"telegram": {
"command": "node",
"args": ["/path/to/telegram-mcp-server/dist/index.js"],
"env": {
"TELEGRAM_API_ID": "your_api_id",
"TELEGRAM_API_HASH": "your_api_hash",
"TELEGRAM_PHONE": "+1234567890"
}
}
}
}
Other MCP Clients
For other MCP clients, use:
- Command:
node - Args:
["/path/to/telegram-mcp-server/dist/index.js"] - Environment Variables: Set the Telegram credentials as shown above
Available Tools
Chat Management
list_chats
List all chats, groups, and channels you have access to.
Parameters:
limit(optional): Number of chats to return (default: 50, max: 200)
get_chat_info
Get detailed information about a specific chat.
Parameters:
chatId: The chat ID to get information for
search_chats
Search for chats by title or username.
Parameters:
query: Search query to find chats by titlelimit(optional): Number of results to return (default: 20, max: 100)
Message Operations
get_messages
Get recent messages from a specific chat.
Parameters:
chatId: The chat ID to get messages fromlimit(optional): Number of messages to return (default: 20, max: 100)fromMessageId(optional): Get messages starting from this message ID
send_message
Send a text message to a chat.
Parameters:
chatId: The chat ID to send the message totext: The message text to sendreplyToMessageId(optional): Message ID to reply to
search_messages
Search for messages across all chats or within a specific chat.
Parameters:
query: Search query to find messageschatId(optional): Limit search to specific chatlimit(optional): Number of results to return (default: 20, max: 100)
mark_as_read
Mark specific messages as read in a chat.
Parameters:
chatId: The chat ID to mark messages as readmessageIds: Array of message IDs to mark as read
User Information
get_user_info
Get information about a specific user.
Parameters:
userId: The user ID to get information for
Usage Examples
Once configured with an MCP client like Claude Desktop, you can use natural language commands:
- "Show me my recent chats"
- "Get the last 10 messages from my chat with John"
- "Send a message to the Development group saying 'Meeting at 3 PM'"
- "Search for messages containing 'project deadline'"
- "Get information about chat ID 12345"
Development
Running in Development Mode
npm run dev
Building
npm run build
Testing
# Test basic setup and Telegram connection
npm run test-setup
# Test MCP server functionality
npm run test-mcp
Watching for Changes
npm run watch
Security Notes
- Your session data is stored locally in the
session/directory - Never share your API credentials or session files
- The server only runs locally and doesn't send data to external services
- All communication happens directly between your machine and Telegram's servers
Troubleshooting
Authentication Issues
- Make sure your API credentials are correct
- Verify your phone number format includes country code (e.g., +1234567890)
- Check that you can receive Telegram messages for the verification code
Connection Problems
- Ensure you have a stable internet connection
- Try deleting the
session/directory and re-authenticating - Check that your API credentials haven't been revoked
MCP Client Issues
- Verify the path to the built server (
dist/index.js) is correct - Make sure Node.js is in your PATH
- Check the MCP client logs for error messages
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。