Skip to main content
Glama
telegram-mcp

telegram-mcp

by Maxsh

MCP Telegram Server

CI tests coverage release node license

A Model Context Protocol (MCP) server that lets AI assistants read, search and manage Telegram channels, groups and private conversations on behalf of your user account (not a bot).

Contents: Features · Quick start · Setup · Tools · MCP client configuration · Development · Testing · Contributing · Releases · Security · Troubleshooting

Quick start

git clone https://github.com/Maxsh/telegram-mcp.git && cd telegram-mcp
npm ci && npm run build
export TELEGRAM_API_ID=... TELEGRAM_API_HASH=...   # from https://my.telegram.org/apps
npm start   # stdio MCP server; authorize via the telegram_authorize tool

Then register node /absolute/path/to/telegram-mcp/dist/index.js in your MCP client (see MCP client configuration). A step-by-step walkthrough lives in SETUP.md.

Related MCP server: telegram-mcp-connect

Features

  • User-account access — acts on behalf of the authenticated Telegram user, not a bot token

  • Read anywhere — recent messages, search and chat info across channels, groups and private chats, plus discovery of available channels

  • Pagination and time windows — offsetId paging for busy channels; sinceMinutes / sinceHours / sinceDate windows with IANA time zones (DST-correct)

  • Batch fetch — up to 25 channels in one call, each with its own result or error

  • Digest-friendly output — maxTextLength, fields, excludeMedia; media captions, t.me links, forwardedFrom

  • Session management — interactive authorization with 2FA, pre-generated session strings, logout

Setup

Set the environment variables (.env file or exports):

TELEGRAM_API_ID=your_api_id            # from https://my.telegram.org/apps
TELEGRAM_API_HASH=your_api_hash
TELEGRAM_SESSION=your_session_string   # optional

Authentication options

  • Interactive (easiest start): use any tool and the server asks for authorization — call telegram_authorize with your phone number, then telegram_verify_code with the code (and your 2FA password, if enabled). The session lives in memory for the server's lifetime.

  • Pre-generated session: run npm run generate-session once (prompts for phone, code, 2FA) and store the printed string as TELEGRAM_SESSION — it persists across restarts. Never commit it.

telegram_logout invalidates the current session at any time.

Available tools

Tool

Purpose

get_recent_messages

Recent messages from a channel, group or private chat; offsetId pagination and time windows

get_messages_multi

Batch-fetch recent messages from up to 25 channels, with per-channel results and errors

get_private_messages

Private conversation messages with contact formatting

get_channel_info

Metadata for any chat, including a ready-to-use peer id

search_messages

Text search within a chat

get_available_channels

List channels and groups the user can access

mark_messages_read

Mark messages as read (groups and private chats; broadcast channels don't support read status)

check_unread_messages

Find chats with unread messages

get_chat_status

Diagnostics for read status and chat capabilities

telegram_authorize

Start the interactive authorization

telegram_verify_code

Complete authorization with the code and optional 2FA password

telegram_logout

Log out and invalidate the session

MCP clients also receive each tool's exact input schema via tools/list, so arguments are validated before a call is dispatched.

Full parameters, examples and response schemas: docs/TOOLS.md. Response shapes are a stable contract: fields may be added, but removing or renaming one is a breaking change.

MCP client configuration

Add to your Claude Desktop claude_desktop_config.json (other MCP clients are configured analogously):

{
  "mcpServers": {
    "telegram": {
      "command": "node",
      "args": ["/path/to/mcp-telegram-server/dist/index.js"],
      "env": {
        "TELEGRAM_API_ID": "your_api_id",
        "TELEGRAM_API_HASH": "your_api_hash",
        "TELEGRAM_SESSION": "your_session_string"
      }
    }
  }
}

Development

npm run dev     # run from source with tsx
npm run watch   # rebuild on change

Project rules for agents and contributors: AGENTS.md.

Testing

npm test              # unit tests + smoke test
npm run test:unit     # unit tests only (tests/*.test.ts, fake Telegram client)
npm run test:smoke    # spawns the built server and checks tools/list
npm run test:coverage # unit tests with a coverage report

The unit suite (tests/*.test.ts) runs on Node's built-in test runner with a fake Telegram client — no network access and no credentials. It covers every tool (get_recent_messages pagination and output options, get_messages_multi, get_channel_info, search_messages, get_available_channels, mark_messages_read, check_unread_messages, get_private_messages, get_chat_status, the authorization flow), the pure helpers (time zones, id normalization, media typing, output shaping), and the tool catalog/dispatch contract.

scripts/live-check.ts is a manual end-to-end check against the real Telegram API (needs credentials in ~/.secrets/telegram-*) and is intentionally not part of CI.

Continuous integration

.github/workflows/ci.yml runs on every push and pull request, on Node 22, 24 and 26:

  • build (tsc, strict), unit tests under c8, smoke test;

  • run Summary with passed/failed/skipped counts, per-suite breakdown, failure details and coverage (statements/branches/functions/lines);

  • JUnit check run with failure annotations (dorny/test-reporter);

  • coverage comment on pull requests (Cobertura, irongut/CodeCoverageSummary);

  • raw reports (JUnit XML, Cobertura, LCOV) as downloadable artifacts.

The tests and coverage badges above are shields.io endpoint badges generated by scripts/ci-summary.ts and published to the badges branch on every push to main, so they always show the latest main build.

Reproduce the CI report locally:

npm run test:ci && npm run ci:summary   # markdown summary on stdout, reports in reports/ and coverage/

Contributing

All changes go through pull requests with tests — see CONTRIBUTING.md and the full rules in AGENTS.md (which also apply to AI coding agents). Changes are recorded in CHANGELOG.md.

Releases

Versions follow SemVer; release notes come from CHANGELOG.md (Keep a Changelog). Pushing a vX.Y.Z tag on main runs .github/workflows/release.yml, which verifies the tag, builds, tests and publishes the GitHub Release with an npm pack tarball. The process is described in AGENTS.md → Releases.

Security notes

  • Session security: Keep your session string secure. It provides full access to your Telegram account.

  • API credentials: Never share your API ID and hash publicly.

  • Channel access: The server can only access channels that your Telegram account has permission to read.

  • Rate limiting: Telegram has rate limits. The server doesn't implement rate limiting, so use responsibly.

  • Reporting vulnerabilities: privately, see SECURITY.md.

Troubleshooting

Quick checks:

  • "Authorization required" → telegram_authorize, then telegram_verify_code (add password for 2FA). Invalid code? Codes expire within minutes — request a new one.

  • mark_messages_read doesn't stick → debug with get_chat_status; broadcast channels and secret chats don't support read status.

  • Rate limits / network errors → retry later; the server already retries connections.

The full guide lives in docs/TROUBLESHOOTING.md.

License

MIT

Available Tools

12 tools
check_unread_messagesC

Check for unread messages in private chats and groups

Inputs: limit, onlyWithUnread, includeChannels.

get_available_channelsB

Get list of available channels and groups that the user has access to

Inputs: limit, includeGroups.

get_channel_infoC

Get information about a Telegram channel, group, or private chat

Inputs: channel (required).

get_chat_statusC

Get detailed status information about a chat including unread count and read status

Inputs: chat (required).

get_messages_multiA

Get recent messages from multiple Telegram channels in one call (1-25 channels). Returns per-channel results and per-channel errors, so one bad channel does not fail the call. Same response fields as get_recent_messages per channel.

Inputs: channels (required), tz, limit, sinceDate, +4 more.

get_private_messagesC

Get messages from a private chat conversation

Inputs: contact (required), tz, limit, offsetId, +4 more.

get_recent_messagesA

Get recent messages from a Telegram channel, group, or private chat. Returns resolved channel info (id/peer/username/type), hasMore/nextOffsetId for pagination, and lastMessageDate so an empty window can be told apart from a dead channel.

Inputs: channel (required), tz, limit, fields, +6 more.

mark_messages_readB

Mark messages as read in a Telegram chat, group, or private conversation (not supported for broadcast channels)

Inputs: channel (required), maxId, messageIds.

search_messagesC

Search for messages in a Telegram channel, group, or private chat

Inputs: query (required), channel (required), tz, limit, +5 more.

telegram_authorizeB

Start Telegram authorization process with phone number

Inputs: phoneNumber (required).

telegram_logoutB

Logout from Telegram and invalidate the current session

Inputs: no named parameters.

telegram_verify_codeB

Complete Telegram authorization with verification code and optional 2FA password

Inputs: code (required), password.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.1/5.0

    Scored across 12 tools

    Disambiguation3/5

    Several read-oriented tools overlap: get_recent_messages already covers private chats that get_private_messages targets, check_unread_messages overlaps with get_chat_status and get_recent_messages, and get_messages_multi is a batched variant of get_recent_messages. Descriptions clarify some distinctions, but boundaries remain fuzzy enough to cause misselection.

    Naming Consistency4/5

    Most tools follow a clear verb_noun pattern such as get_channel_info, search_messages, and mark_messages_read. The telegram_ prefix on authorization tools is a minor deviation but still readable and predictable.

    Tool Count5/5

    Twelve tools is a well-scoped size for a Telegram client MCP covering authorization, channel discovery, message retrieval, search, unread tracking, and read marking. Each tool has a plausible role in that surface.

    Completeness2/5

    The server covers reading, searching, auth, and read receipts, but there is no tool to send a message, which is a core Telegram operation. Other lifecycle gaps such as editing, deleting, forwarding, or joining/leaving chats further limit the surface for a messaging integration.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables reading Telegram chats and searching messages through natural language, connecting to MCP clients like Claude Code, Codex, and Cursor.
      13 npm
      1
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      This MCP server enables agents to connect to Telegram accounts and bots to search chats, review unread messages, build sourced digests, inspect media and documents, and prepare or execute confirmed actions with scoped permissions.
      1
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Enables MCP clients to read and search personal Telegram chats, manage messages and chats, clean up spam or deleted-account conversations, and adjust privacy and login settings through Telegram’s official MTProto API. Destructive actions preview by default and require confirmation before execution.
      18
      2
      MIT