tgreader-mcp
Telegram channel reader MCP server — exposes Telegram channels as MCP tools via Telethon MTProto.
README
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
@usernameor 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, config0600, sanitized error messages, ReDoS protection viaregexlibrary with per-match timeout
Requirements
- Python ≥ 3.11 (developed on 3.13)
- uv (recommended) or
pip - Telegram
api_id/api_hash— get them at https://my.telegram.org
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
.featurefiles) - 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 files —
0600permissions, stored in~/.config/tgreader/sessions/ - Config file —
0600permissions, atomic write (tmp → rename) - Error sanitization — internal exceptions (Telethon, network) are caught; only safe, generalized messages reach the LLM
- ReDoS protection —
regexlibrary (not stdlibre) with 2s per-match timeout;RegexTimeoutErroris caught and surfaced safely - Config validation — full type checking on load; malformed config raises
ConfigErrorwith a clear message
License
MIT © Andrey Romanchuk
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。