- Explore MCP Servers
- telegram_mcp
Telegram Mcp
What is Telegram Mcp
telegram_mcp is a server designed to interact with the Telegram API using the MTProto protocol. It provides a REST API for seamless communication with Telegram services.
Use cases
Use cases for telegram_mcp include building chatbots that respond to user messages, automating message sending for notifications, retrieving chat histories for analysis, and integrating Telegram functionalities into other applications.
How to use
To use telegram_mcp, clone the repository, install the dependencies, configure the .env file with your Telegram API ID and API Hash, and then start the server. You can also run it in development mode for automatic reloading.
Key features
Key features of telegram_mcp include REST API endpoints for checking server status, executing Telegram API methods, retrieving chat lists, fetching messages from chats, sending messages, and listing available API methods.
Where to use
telegram_mcp can be used in various fields such as chatbots, automated messaging systems, data analysis tools, and any application that requires interaction with Telegram services.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Overview
What is Telegram Mcp
telegram_mcp is a server designed to interact with the Telegram API using the MTProto protocol. It provides a REST API for seamless communication with Telegram services.
Use cases
Use cases for telegram_mcp include building chatbots that respond to user messages, automating message sending for notifications, retrieving chat histories for analysis, and integrating Telegram functionalities into other applications.
How to use
To use telegram_mcp, clone the repository, install the dependencies, configure the .env file with your Telegram API ID and API Hash, and then start the server. You can also run it in development mode for automatic reloading.
Key features
Key features of telegram_mcp include REST API endpoints for checking server status, executing Telegram API methods, retrieving chat lists, fetching messages from chats, sending messages, and listing available API methods.
Where to use
telegram_mcp can be used in various fields such as chatbots, automated messaging systems, data analysis tools, and any application that requires interaction with Telegram services.
Clients Supporting MCP
The following are the main client software that supports the Model Context Protocol. Click the link to visit the official website for more information.
Content
Telegram MCP Server
English version | Русская версия
Server for working with Telegram API through Model Context Protocol (MCP). Allows AI agents and other MCP clients to interact with Telegram.
Requirements
- Node.js 14+ (or higher)
- npm
- API ID and API Hash from Telegram
Installation
-
Clone the repository:
git clone https://github.com/kdoronin/telegram_mcp cd telegram-mcp -
Install dependencies:
npm install(This will install the necessary packages:
gramjs,@modelcontextprotocol/sdk,zod, etc.) -
Create and configure the
.envfile:# Copy the example .env file cp .env.example .envEdit the
.envfile and specify yourAPI_IDandAPI_HASH. -
Get API ID and API Hash:
- Go to my.telegram.org
- Log in to your account
- Navigate to “API development tools”
- Create a new application
- Copy
api_idandapi_hashto your.envfile
Running
Important note about running
The main server file mcp-server.js is located in the project root, which allows running it without path issues.
Option 1: Via npm (recommended)
npm run mcp # Run from the project root directory
Option 2: Direct node execution
# Run from the project root directory
node mcp-server.js
Option 3: As an executable file
# From the project root
./mcp-server.js
Option 4: After global installation
npm install -g . # Install the package globally
telegram-mcp # Run the globally installed package
Integration with MCP clients
Configuration in Cursor
- Open Cursor settings
- Go to Features -> MCP Servers
- Click “Add new MCP server”
- Configure the server:
- Name:
telegram(or any other) - Type:
command - Command:
node /full/path/to/project/mcp-server.js - Alternatively:
npx telegram-mcp(after global installation)
- Name:
Configuration in Claude Desktop
- Open Claude Desktop settings
- Go to Tools -> MCP
- Click “Add New Server”
- Configure the server:
- Name:
telegram(or any other) - Type:
command - Command:
node /full/path/to/project/mcp-server.js - Alternatively:
npx telegram-mcp(after global installation)
- Name:
Checking functionality
When the server starts:
- It will load settings from the
.envfile - Check for saved sessions
- If there are no sessions, it will offer to create a new one (you will need to enter a phone number and confirmation code)
Available Tools
The MCP server provides the following tools:
getDialogs: Gets a list of user dialogs (chats).- Parameters:
session(string, required),limit(integer, optional, default: 100).
- Parameters:
getMessages: Gets messages from the specified chat.- Parameters:
session(string, required),chatId(string, required),limit(integer, optional, default: 100).
- Parameters:
sendMessage: Sends a message to the specified chat.- Parameters:
session(string, required),chatId(string, required),message(string, required).
- Parameters:
executeMethod: Executes an arbitrary Telegram API method (use with caution).- Parameters:
session(string, required),method(string, required),params(object, optional).
- Parameters:
Note: The session parameter is usually the user’s phone number in international format (e.g., +79001234567).
Usage examples in prompts
Using the telegram.getDialogs tool for session +79001234567, show me the last 5 chats.
With telegram.sendMessage for session +79001234567, send the message "Hello from my AI assistant!" to chat with ID 'username_or_chat_id'.
Authorization
When using a session (phone number) for the first time, the server will request a confirmation code in the console where it is running. Enter the code received from Telegram to authorize the session.
If you have two-factor authentication (2FA) enabled, you will also need to enter your Telegram password. If the password is entered incorrectly, the system will prompt you to enter it again (up to 3 attempts).
After successful authorization, the session will be saved to a file inside the sessions/ directory and will be used for subsequent requests.
Session file structure
Sessions are stored in the sessions/ directory as JSON files named after the phone number (e.g., +79001234567.json). Each file contains:
- A session string (encrypted authorization token)
- A timestamp of creation/update
Troubleshooting
-
Error “Your API ID or Hash cannot be empty or undefined”
- Check that the
.envfile is in the project root - Make sure API_ID and API_HASH are correctly specified in it
- Run the server from the project root directory
- Check that the
-
Server doesn’t see the saved session
- Check the execution path (should be from the project root)
- Check for the session file in the
sessions/directory - Try running with
npm run mcp
-
Authorization error
- If you entered an incorrect 2FA password, the system will prompt you to re-enter it
- If all attempts are exhausted, delete the session file and try again
Security
- Do not share your API ID and API Hash with third parties.
- Run the server in a trusted environment.
- Session files contain sensitive data. Store them in a secure location and do not share them.
- The
executeMethodtool allows executing any Telegram API methods. Use it with caution, as it can perform destructive actions.
License
MIT
Dev Tools Supporting MCP
The following are the main code editors that support the Model Context Protocol. Click the link to visit the official website for more information.










