npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

telegram-mcp-server

v1.0.0

Published

MCP server for a Telegram client built with the MTProto library and FastMCP framework

Readme

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.