Telegram MCP Server is a specialized server that enables AI assistants like Claude to interact with your Telegram account using the user client API rather than the bot API. It allows for more powerful interactions with your Telegram account through a standardized interface based on the FastMCP framework.
Before installing the server, you'll need:
api_id
and api_hash
by creating a new application at Telegram's API Development ToolsClone the repository and install dependencies:
git clone https://github.com/your-username/telegram-mcp-server.git
cd telegram-mcp-server
npm install
Configure the server by creating a .env
file with your Telegram credentials:
TELEGRAM_API_ID=YOUR_API_ID
TELEGRAM_API_HASH=YOUR_API_HASH
TELEGRAM_PHONE_NUMBER=YOUR_PHONE_NUMBER_WITH_COUNTRY_CODE
For PostgreSQL integration (optional), add your database connection string:
DATABASE_URL=your_postgres_connection_string
The first time you run the server, it needs to authenticate with Telegram:
npm start
The server will:
./data/session.json
) for automatic login in the future./data/dialog_cache.json
)This initial setup is important before connecting through an MCP client.
Configure client software (Claude Desktop, Cursor, etc.) to connect to the MCP server:
{
"mcpServers": {
"telegram": {
"url": "http://localhost:8080/sse",
"disabled": false,
"timeout": 30
}
}
}
For Claude Desktop, the config file is located at:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
Important: Restart your MCP client after making configuration changes.
The server provides several tools for interacting with Telegram:
listChannels
limit
(optional): Maximum number of channels to return (default: 50)searchChannels
keywords
: Text to search for in channel nameslimit
(optional): Maximum results to return (default: 100)getChannelMessages
channelId
: Numeric ID of the channel/chatlimit
(optional): Maximum messages to return (default: 100)filterPattern
(optional): JavaScript regex to filter messages by contentFor persistent storage of chat data:
import { Database } from './db.js';
import TelegramClient from './telegram-client.js';
const db = new Database(process.env.DATABASE_URL);
await db.connect();
await db.init();
const client = new TelegramClient(...);
await client.initializeDialogCache();
await client.saveDialogsToDb(db); // store chats
await client.saveChatMessagesToDb(chatId, db, { batchSize: 100, after: 0 });
npm start
manually once to refresh the session./data/dialog_cache.json
and restart the server to force a cache refreshnpm install
in the project directoryTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "telegram" '{"url":"http://localhost:8080/sse","disabled":false,"timeout":30}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"telegram": {
"url": "http://localhost:8080/sse",
"disabled": false,
"timeout": 30
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"telegram": {
"url": "http://localhost:8080/sse",
"disabled": false,
"timeout": 30
}
}
}
3. Restart Claude Desktop for the changes to take effect