Skip to main content
Glama
ramich2077

tgreader-mcp

by ramich2077

tgreader-mcp

Telegram channel reader MCP server — exposes Telegram channels as MCP tools via Telethon MTProto.

Designed for use with Hermes Agent, Claude Desktop, and any MCP-compatible client.

Features

  • List channels — discover channels the account is subscribed to, with optional RegExp search filter

  • Read messages — fetch posts from any channel by @username or numeric ID, with date-based pagination and text search

  • Multi-account — configure multiple Telegram accounts, switch between them per call

  • MCP stdio transport — works out of the box with any MCP client

  • Security-hardened — session files 0600, config 0600, sanitized error messages, ReDoS protection via regex library with per-match timeout

Related MCP server: telegram-mcp

Requirements

Quick start

git clone <repo-url> tgreader && cd tgreader

# Create venv and install deps (runtime + dev, editable)
./setup.sh
# or: make setup

# Activate
source .venv/bin/activate

# Login with your Telegram account
tgreader login --account main --phone +79001234567

# Check status
tgreader status

Register with Hermes Agent

Add to ~/.hermes/config.yaml:

mcp_servers:
  tgreader:
    command: /home/<user>/telegram_reader/.venv/bin/tgreader-mcp
    args: []

Install the Hermes skill

The repo ships a ready-to-use Hermes Agent skill at skills/tgreader/SKILL.md. Install it so the agent knows how to use the MCP tools:

# Copy (recommended)
cp -r skills/tgreader ~/.hermes/skills/tgreader

# Or symlink (tracks the repo, auto-updates on git pull)
ln -s ~/telegram_reader/skills/tgreader ~/.hermes/skills/tgreader

The skill teaches the agent when and how to call list_channels / read_messages, including example workflows (find vacancies, read by date range, search across channels) and pitfalls (FloodWait, session expiry, ReDoS-protected search).

Register with Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "tgreader": {
      "command": "/home/<user>/telegram_reader/.venv/bin/tgreader-mcp"
    }
  }
}

MCP tools

list_channels

List Telegram channels the account is subscribed to.

Parameter

Type

Default

Description

account

str

Account name (default: configured default)

search

str

RegExp pattern to filter by title/username (max 200 chars)

limit

int

100

Max channels to return (max 500)

Returns: {"count": N, "channels": [{"id", "title", "username", "type", "participants_count"}]}

read_messages

Read messages from a Telegram channel.

Parameter

Type

Default

Description

channel

str

Channel @username or numeric ID (required)

account

str

Account name (default: configured default)

limit

int

20

Max messages when offset_date is None (max 1000)

offset_date

str

ISO 8601 datetime — read messages before this date

search

str

RegExp pattern to filter message text (max 200 chars)

Returns: {"count": N, "channel": {"id", "title", "username"}, "messages": [{"id", "date", "text", "views", "reactions", "media_type", "link"}]}

CLI

# Login (creates session, saves to config)
tgreader login --account main --phone +79001234567

# Account management
tgreader accounts list
tgreader accounts add --name work --phone +790011122233 --label "Work account"
tgreader accounts remove main
tgreader accounts default main

# Check session status
tgreader status
tgreader status --account work

# Start MCP server (stdio)
tgreader run
# or: tgreader-mcp

Configuration

Config lives at ~/.config/tgreader/config.json (XDG-aware):

{
  "api_id": 123456,
  "api_hash": "your_api_hash_here",
  "default_account": "main",
  "accounts": {
    "main": {
      "phone": "+79001234567",
      "label": ""
    }
  }
}

Session files (.session) are stored at ~/.config/tgreader/sessions/ with 0600 permissions.

Development

# Setup
make setup           # create .venv, install deps

# Tests
make test            # full suite (113 tests)
make test-fast       # without isolation (debugging)

# Lint
make lint            # py_compile syntax check

# Run server
make run

# Clean
make clean           # remove .venv and caches

Test suite

  • 113 tests — unit + integration + BDD (pytest-bdd with Gherkin .feature files)

  • BDD features cover: login flow, channel listing, message reading

  • Security tests: ReDoS, error sanitization, session permissions, config validation

Project structure

tgreader-mcp/
├── src/tgreader_mcp/
│   ├── __init__.py      # version
│   ├── server.py        # FastMCP server — tool definitions
│   ├── client.py        # Telethon client — channel/message logic
│   ├── config.py        # Config load/save, account management
│   └── cli.py           # Click CLI — login, accounts, status
├── skills/tgreader/
│   └── SKILL.md         # Hermes Agent skill — tool usage guide
├── tests/
│   ├── test_server.py   # MCP tool tests
│   ├── test_client.py   # Telegram client tests
│   ├── test_config.py   # Config validation tests
│   ├── test_security.py # ReDoS, sanitization, permissions
│   ├── test_cli.py      # CLI command tests
│   ├── features/        # Gherkin .feature files
│   └── test_steps/      # pytest-bdd step implementations
├── pyproject.toml
├── Makefile
├── setup.sh
└── .python-version

Security

  • Session files0600 permissions, stored in ~/.config/tgreader/sessions/

  • Config file0600 permissions, atomic write (tmp → rename)

  • Error sanitization — internal exceptions (Telethon, network) are caught; only safe, generalized messages reach the LLM

  • ReDoS protectionregex library (not stdlib re) with 2s per-match timeout; RegexTimeoutError is caught and surfaced safely

  • Config validation — full type checking on load; malformed config raises ConfigError with a clear message

License

MIT © Andrey Romanchuk

Available Tools

2 tools
list_channelsA

List Telegram channels the account is subscribed to.

Args: account: Account name (default: configured default account). search: Optional RegExp pattern to filter by channel title or username (max 200 chars). limit: Maximum channels to return (default 100, max 500).

Returns JSON: {"count": N, "channels": [{"id", "title", "username", "type", "participants_count"}]}

ParametersJSON Schema
NameRequiredDescriptionDefault
accountNo
searchNo
limitNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full transparency burden. It discloses the returned data structure (Count, Channels with fields), default and maximum limits, and that search is a RegExp pattern. It does not cover side effects, authentication, or rate limits, but for a read operation the described behavior is sufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is concise (3 lines plus return structure) and well-structured with bullet points for parameters. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Description fully covers the tool's purpose, all parameters with constraints, and return format. Output schema exists but description still adds readability. Sibling tool is not related, so no cross-referencing needed. Complete for a list operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so description adds crucial meaning: 'account' is account name with default, 'search' is optional RegExp pattern with max 200 chars, 'limit' is max channels with defaults and max 500. This goes well beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states 'List Telegram channels the account is subscribed to' which uses a specific verb and resource. It easily distinguishes from sibling tool 'read_messages' which deals with messages, not channels.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Description implies usage context (listing subscribed channels) but does not explicitly provide when to use vs. alternatives, nor does it mention conditions to avoid using this tool. No exclusions or guidance on when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

read_messagesA

Read messages from a Telegram channel.

Args: channel: Channel @username or numeric ID. account: Account name (default: configured default account). limit: Max messages when offset_date is None (default 20, max 1000). offset_date: ISO 8601 datetime — read all messages before this date (capped at 1000). search: Optional RegExp pattern to filter message text (max 200 chars).

Returns JSON: {"count": N, "channel": {"id", "title", "username"}, "messages": [{"id", "date", "text", "views", "reactions", "media_type", "link"}]}

ParametersJSON Schema
NameRequiredDescriptionDefault
channelYes
accountNo
limitNo
offset_dateNo
searchNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Describes limits (default 20, max 1000 for limit/cap), offset_date behavior, search regex, and return structure. No annotations, so description reasonably covers non-destructive read operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Well-structured with Args and Returns sections, front-loaded purpose, no redundant text. Each sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers all 5 parameters, describes return format, includes relevant constraints (max limits, default account). Output schema exists but description provides additional context for completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Adds meaning beyond schema: explains limit default and max, offset_date as 'before', search as 'RegExp pattern max 200 chars', and account default. Schema has 0% description coverage, so description compensates well.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Read messages from a Telegram channel' with specific verb and resource. Distinguishes from sibling 'list_channels' by focusing on message content vs channel listing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implicitly clarifies use case (reading messages) vs sibling (listing channels), but lacks explicit when-not or alternative conditions. Still clear enough for typical usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 2 tool updatesv0.1.0
    • First observedlist_channels
    • First observedread_messages

TDQS

A4.5/5.0
Disambiguation5/5

The two tools are completely distinct: one lists channels, the other reads messages from a specific channel. There is no overlap or ambiguity.

Naming Consistency5/5

Both tool names follow the verb_noun pattern ('list_channels', 'read_messages'), making them predictable and easy to understand.

Tool Count4/5

With only 2 tools, the set is minimal but well-suited for a read-only Telegram client. It could benefit from additional tools like a channel info getter, but it is not overly sparse.

Completeness4/5

The tools cover the core read operations: listing channels and reading messages. Missing features like retrieving a single channel's details or searching across channels are minor gaps for a focused read-only tool.

Maintenance

ActivityStale
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    maintenance
    A local MCP server for Cursor and Claude Desktop that reads Telegram subscriptions over MTProto and exposes channel posts for digests and natural-language queries.
    7
    1
    MIT
  • F
    license
    A
    quality
    B
    maintenance
    Read-only MCP server for self-hosted Telegram access via Telethon. Enables reading messages, chats, and media but disallows any write operations.
    10
    -
  • A
    license
    Not graded
    quality
    B
    maintenance
    An MCP server that connects to Telegram as your real user account and exposes read-only tools to read and search messages, list chats and folders, inspect group info, and download media.
    16
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ramich2077/tgreader-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server