Sponsored by Deepsite.site

Telegram MCP Server

Created By
kfastov9 months ago
MCP server implementation for Telegram
Content

Telegram MCP Server

An MCP server allowing AI assistants (like Claude) to interact with your Telegram account using the user client API (not the bot API). Built with @mtproto/core and the FastMCP framework.

Features

Tools

  • listChannels

    • Lists available Telegram channels/chats accessible by the account, based on the server's cache.
    • Parameters:
      • limit (number, optional): Maximum number of channels to return (default: 50).
    • Output: A list of channels/chats with their ID, title, type, and access hash (if applicable).
  • searchChannels

    • Searches the cached channels/chats by keywords in their names.
    • Parameters:
      • keywords (string): Keywords to search for in channel names.
      • limit (number, optional): Maximum number of results to return (default: 100).
    • Output: A list of matching channels/chats.
  • getChannelMessages

    • Retrieves recent messages from a specific channel/chat using its ID.
    • Parameters:
      • channelId (number): The numeric ID of the channel/chat (obtained from listChannels or searchChannels).
      • limit (number, optional): Maximum number of messages to return (default: 100).
      • filterPattern (string, optional): A JavaScript-compatible regular expression to filter messages by their text content.
    • Output: A list of messages containing ID, date, text, and sender ID.

Prerequisites

  1. Node.js: Version 18 or later recommended.
  2. Telegram Account:
    • You need 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

  1. Clone this repository:
    git clone https://github.com/your-username/telegram-mcp-server.git # Replace with your repo URL
    cd telegram-mcp-server
    
  2. Install dependencies:
    npm install
    

Configuration

There are two separate configurations that need to be set up:

  1. MCP Server Configuration:

    Configure the Telegram MCP server using environment variables (in a .env file or directly in your environment):

    TELEGRAM_API_ID=YOUR_API_ID
    TELEGRAM_API_HASH=YOUR_API_HASH
    TELEGRAM_PHONE_NUMBER=YOUR_PHONE_NUMBER_WITH_COUNTRY_CODE # e.g., +15551234567
    

    Replace the placeholder values with your actual credentials.

  2. MCP Client Configuration:

    Configure client software (Claude Desktop, Cursor, etc.) to connect to the MCP server by modifying their configuration files:

    {
      "mcpServers": {
        "telegram": {
          "url": "http://localhost:8080/sse",
          "disabled": false,
          "timeout": 30
        }
      }
    }
    

    For Claude Desktop, the config file is located at:

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

    Important: Restart your MCP client to apply the changes.

Running the Server

  1. Initial Login (Important First Step): The first time you run the server (or if your session expires/is invalid), it needs to authenticate with Telegram. Run it directly from your terminal:

    npm start
    
    • The server will use the credentials from your .env file.
    • It will prompt you in the terminal to enter the login code sent to your Telegram account and your 2FA password if required.
    • Upon successful login, a session file (./data/session.json) will be created. This file allows the server to log in automatically in the future without requiring codes/passwords.
    • The server will also attempt to build or load a cache of your chats (./data/dialog_cache.json). This can take some time on the first run, especially with many chats. Subsequent starts will be faster if the cache exists.
  2. Normal Operation: You'll need to start the server manually by running npm start in the project directory.

    Once the server is running, your MCP client (e.g., Claude Desktop) will connect to it via the URL specified in its configuration (http://localhost:8080/sse by default).

Troubleshooting

  • Login Prompts: If the server keeps prompting for login codes/passwords when started by the MCP client, ensure the data/session.json file exists and is valid. You might need to run npm start manually once to refresh the session. Also, check that the file permissions allow the user running the MCP client to read/write the data directory.
  • Cache Issues: If channels seem outdated or missing, you can delete ./data/dialog_cache.json and restart the server (run npm start manually) to force a full refresh. This might take time.
  • Cannot Find Module: Ensure you run npm install in the project directory. If the MCP client starts the server, make sure the working directory is set correctly or use absolute paths.
  • Other Issues: If you encounter any other problems, feel free to open an issue in this server repo.

Telegram Client Library

This repository also contains the underlying telegram-client.js library used by the MCP server. For details on using the library directly (e.g., for custom scripting), see LIBRARY.md.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
WindsurfThe new purpose-built IDE to harness magic
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Amap Maps高德地图官方 MCP Server
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
ChatWiseThe second fastest AI chatbot™
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Playwright McpPlaywright MCP server
CursorThe AI Code Editor
DeepChatYour AI Partner on Desktop