local-only server
The server can only run on the client’s local machine because it depends on local resources.
Integrations
Handles configuration management through environment variables, specifically for storing Telegram API credentials including API ID, API hash, and phone number.
Enables interaction with Telegram messaging platform, providing tools to search channels by keywords, list available channels, retrieve messages from channels, and filter messages by regex patterns.
Telegram Client Library and MCP Server
This project provides both a Telegram client library and an MCP (Model Context Protocol) server for AI assistants to interact with Telegram.
Features
Telegram Client Library
- Authentication with Telegram (including 2FA support)
- Session management (automatic reuse of existing sessions)
- Retrieving chats/dialogs
- Fetching messages from specific chats
- Filtering messages by pattern (e.g., regex)
MCP Server
- Search channels by keywords - Find Telegram channels by searching for keywords in their names
- List available channels - View all accessible channels
- Get messages from channels - Retrieve messages from any accessible channel
- Filter messages by pattern - Apply regex patterns to filter messages
Setup
- Create a
.env
file with your Telegram API credentials:
- Install dependencies:
Usage
Using the Telegram Client Library
Run the example client:
Using the MCP Server
- Start the MCP server:
- The MCP server will be available at:
- You can test the MCP server using the included client:
For more details about the MCP server, see MCP-README.md.
For information about the code architecture, see CODE_STRUCTURE.md.
API Reference
TelegramClient
Constructor
apiId
: Your Telegram API IDapiHash
: Your Telegram API HashphoneNumber
: Your phone number in international formatsessionPath
: (Optional) Path to save the session file (default: './data/session.json')
Methods
login()
: Authenticates with Telegram (handles both new logins and session reuse)getDialogs(limit, offset)
: Gets a list of dialogs (chats)getChatMessages(chat, limit)
: Gets messages from a specific chatfilterMessagesByPattern(messages, pattern)
: Filters an array of messages by a regex patternhasSession()
: Checks if a valid session exists
Files in this Repository
telegram-client.js
: The main client libraryclient.js
: An example client with additional helper functionsindex.js
: Original example using the client librarymcp-server.js
: The MCP server main entry pointtelegram-mcp.js
: The MCP server implementation with Telegram toolshttp-server.js
: The HTTP/SSE server transport layermcp-client-example.js
: A simple client to test the MCP server
Using with Claude or other MCP-compatible Assistants
The MCP server can be used with Claude or other MCP-compatible assistants. When connected, the assistant will have access to your Telegram channels and messages through the tools provided by the server.
Example workflow:
- Start the MCP server
- Connect Claude to the MCP server using the MCP URL
- Ask Claude to search for channels, retrieve messages, or filter messages by pattern
License
MIT
This server cannot be installed
A Model Context Protocol server that enables AI assistants to interact with Telegram, allowing them to search channels, list available channels, retrieve messages, and filter messages by regex patterns.
- Features
- Setup
- Usage
- API Reference
- Files in this Repository
- Using with Claude or other MCP-compatible Assistants
- License