Telegram Channel Explorer MCP server

Enables access to Telegram channels and messages for searching content by keywords, listing available channels, retrieving specific messages, and filtering with regex patterns using the MTProto protocol.
Back to servers
Setup instructions
Provider
kfastov
Release date
Mar 20, 2025
Language
TypeScript
Stats
19 stars

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.

Prerequisites

Before installing the server, you'll need:

  1. Node.js: Version 18 or later recommended
  2. Telegram Account:
    • An active Telegram account
    • Two-Step Verification (2FA) must be enabled on your account (Settings → Privacy and Security → Two-Step Verification)
  3. Telegram API Credentials:

Installation and Setup

  1. Clone the repository and install dependencies:

    git clone https://github.com/your-username/telegram-mcp-server.git
    cd telegram-mcp-server
    npm install
    
  2. 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
    
  3. For PostgreSQL integration (optional), add your database connection string:

    DATABASE_URL=your_postgres_connection_string
    

Initial Login

The first time you run the server, it needs to authenticate with Telegram:

npm start

The server will:

  • Prompt you to enter the login code sent to your Telegram account
  • Ask for your 2FA password if required
  • Create a session file (./data/session.json) for automatic login in the future
  • Build a cache of your chats (./data/dialog_cache.json)

This initial setup is important before connecting through an MCP client.

Configuring MCP Clients

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:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%/Claude/claude_desktop_config.json

Important: Restart your MCP client after making configuration changes.

Available Tools

Channel and Message Management

The server provides several tools for interacting with Telegram:

  1. listChannels

    • Lists available Telegram channels/chats accessible by your account
    • Parameters:
      • limit (optional): Maximum number of channels to return (default: 50)
    • Returns channel IDs, titles, types, and access hashes
  2. searchChannels

    • Searches cached channels/chats by keywords
    • Parameters:
      • keywords: Text to search for in channel names
      • limit (optional): Maximum results to return (default: 100)
  3. getChannelMessages

    • Retrieves recent messages from a specific channel
    • Parameters:
      • channelId: Numeric ID of the channel/chat
      • limit (optional): Maximum messages to return (default: 100)
      • filterPattern (optional): JavaScript regex to filter messages by content

PostgreSQL Integration

For 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 });

Troubleshooting

  • Login Issues: If the server keeps prompting for login credentials, run npm start manually once to refresh the session
  • Missing Channels: Delete ./data/dialog_cache.json and restart the server to force a cache refresh
  • Module Errors: Ensure you've run npm install in the project directory
  • Connection Problems: Verify the MCP client configuration points to the correct server URL

How to install this MCP server

For Claude Code

To 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.

For Cursor

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.

Adding an MCP server to Cursor globally

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
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later