Telegram Community MCP
Enables hybrid search over Telegram community message history, combining full-text and semantic search with incremental sync for Claude Desktop integration.
README
Telegram Community MCP
MCP server for hybrid search over Telegram community message history. Connect it to Claude Desktop and search your chats by meaning, not just keywords.
What it does
- Hybrid search — combines full-text search (FTS5) with semantic vector search (sentence embeddings), merged via Reciprocal Rank Fusion
- MCP integration — Claude Desktop calls search tools directly, reasons over results, and pulls conversation threads for context
- Incremental sync — checkpoint-based ingestion, only fetches new messages after initial import
How it works
Claude Desktop ←→ MCP Server (stdio) ←→ SQLite (FTS5 + sqlite-vec)
←→ SentenceTransformer (embeddings)
←→ Telegram API (sync)
Search modes:
| Mode | How it works | Best for |
|---|---|---|
fts |
SQLite FTS5 with unicode tokenization | Exact word/phrase lookup |
semantic |
KNN over 384-dim embeddings (paraphrase-multilingual-MiniLM-L12-v2) |
Finding messages by meaning, cross-language |
hybrid |
Both FTS + semantic, merged with RRF (default) | General search — best of both worlds |
The embedding model is multilingual (50+ languages, ~120 MB) and runs on CPU. A query in Russian will find answers written in English and vice versa.
Performance
Tested on a mini PC (Intel N100, 16 GB RAM):
| Messages | DB size | FTS speed | Semantic speed | RAM usage |
|---|---|---|---|---|
| 100K | ~200 MB | < 50 ms | < 500 ms | ~800 MB |
| 500K | ~1 GB | < 50 ms | ~1 sec | ~1.2 GB |
| 1M | ~2 GB | < 50 ms | 2–5 sec | ~2 GB |
Semantic search uses a two-phase scheme: a coarse binary (Hamming) KNN over a bit[384] index ~32x smaller than the fp32 vectors, then an exact fp32 rerank of the top candidates. The small binary index stays cache-resident, which keeps the cold first-query latency low (e.g. on 1.5M vectors: cold semantic ~2 s vs ~12 s for a full fp32 scan; warm hybrid ~0.9 s). FTS5 scales to millions without issues. The binary index is built from existing vectors — no re-embedding — via python scripts/ingest.py --build-binary.
Initial ingestion of 120K messages takes ~90 minutes on CPU (embedding generation). Incremental syncs are near-instant.
Quick start
Prerequisites
- Python 3.11+
- uv package manager
1. Install
git clone https://github.com/nullnumber1/Telegram-Community-MCP.git
cd Telegram-Community-MCP
uv sync
2. Get Telegram API credentials
Go to my.telegram.org → API development tools → Create application.
Troubleshooting:
my.telegram.orgoften returns a generic ERROR when creating an app in a regular browser. This is a known issue. Try using a VPN (different regions), an antidetect browser, or a mobile browser. It may take several attempts.
Save your api_id and api_hash.
3. Configure
cp config.env.example config.env
Edit config.env:
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
CHAT_IDS=-1001234567890,-1009876543210
To find chat IDs, run auth first, then:
make chats
4. Authorize
make auth
Scan the QR code with Telegram (Settings → Devices → Link Desktop Device). Session is saved locally — you only need to do this once.
5. Ingest messages
make ingest
This fetches the full history of configured chats and builds the search index. Progress is printed to stdout. Safe to interrupt — resumes from the last checkpoint.
6. Connect to Claude Desktop
Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):
{
"mcpServers": {
"tg-community-search": {
"command": "uv",
"args": ["run", "--project", "/absolute/path/to/Telegram-Community-MCP", "python", "server.py"]
}
}
}
Restart Claude Desktop. The search tools should appear in the tools menu.
MCP tools
| Tool | Description | Key parameters |
|---|---|---|
search |
Search messages across all indexed chats | query, mode (fts/semantic/hybrid), limit, chat_id, date_from, date_to |
get_context |
Get surrounding thread: messages before/after + replies | message_id, window |
sync |
Fetch new messages from Telegram | chat_id (optional — all chats if omitted) |
list_chats |
Show indexed chats with message counts | — |
get_stats |
Index statistics: totals, DB size, per-chat breakdown | — |
Project structure
├── server.py # MCP server entry point
├── src/
│ ├── db.py # SQLite: schema, CRUD, FTS5, sqlite-vec queries
│ ├── embedder.py # SentenceTransformer wrapper (lazy-loading)
│ ├── search.py # Hybrid search: FTS + KNN + RRF fusion
│ └── telegram.py # Telethon client wrapper
├── scripts/
│ ├── auth.py # One-time Telegram authorization (QR code)
│ ├── ingest.py # Full import / incremental import
│ ├── list_chats.py # List all account dialogs
│ └── monitor.py # Monitor ingestion progress
├── tests/
│ ├── test_db.py # Database operation tests
│ ├── test_embedder.py # Embedder tests
│ └── test_search.py # Search and RRF fusion tests
├── config.env.example # Configuration template
├── pyproject.toml # Dependencies and tool config
├── Makefile # Dev and deployment shortcuts
└── tg-community-search.service # systemd unit (for server deployment)
Deployment (optional)
For running on a remote server (e.g., a mini PC):
- Edit
tg-community-search.service— replaceYOUR_USERwith your username - Deploy:
make deploy REMOTE_HOST=192.168.1.42 REMOTE_USER=myuser REMOTE_PASS=mypass - Set up hourly auto-sync via cron on the remote:
crontab -e # Add: 0 * * * * cd /home/myuser/tg-community-search && ~/.local/bin/uv run python scripts/ingest.py >> logs/cron-sync.log 2>&1
Development
make test # Run tests
make lint # Lint and format
make dev # MCP inspector (browser UI for testing tools)
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。