letopis-mcp
Provides read-only access to Telegram chat archives, with tools for archive overview, full-text search, aggregated statistics, message selection, and retrieval of local context around messages.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@letopis-mcpWhat did we discuss about moving hosting in June?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
📜 Летопись (Letopis)
Archive and smart search engine for Telegram chat history
Raw messages in JSONL · full-text search with Russian morphology · downloader with manager
Idea
Letopis is not a bot and not a service, but a CLI tool designed so that an LLM agent (primarily Claude Code) can read your Telegram chat history and answer questions from it, just like from a regular knowledge base.
The archive is stored as plain files — .jsonl, one per chat and month, append-only. An SQLite index with full-text search (FTS5) is built on top; it understands Russian word forms: the query «хостинг» finds messages containing the word «хостингами». Voice message transcripts, file names, and poll text are also connected to the search.
$ ./tg search переезд хостинг --chat devops --from 2025-06Engine and data are separated. This repository contains only code — the chat archives themselves,
config.toml,.env, and the Telegram session live in a separate private repository, which keeps you in control of what is public and what is not. More in the Structure section.
Related MCP server: telegram-user-mcp
✨ Features
🔎 Full-text search | SQLite FTS5 + |
📦 Archive as files |
|
⬇️ Downloader with manager |
|
🎙️ Voice transcriptions | locally (faster-whisper), via Telegram Premium or OpenAI Whisper API |
🌐 Web viewer | chats → topic chips, infinite scroll, filters, voice player, reply jumps |
⌨️ TUI viewer | the same functionality in the terminal ( |
👥 Multiple accounts | different chats can be downloaded by different Telegram accounts |
🤖 Built for agents | JSON output, compact short formats, stable CLI contract |
🚀 Quick start
git clone https://github.com/Toligrim/letopis.git
cd letopis
python3 -m venv .venv && .venv/bin/pip install -e .
.venv/bin/pip install faster-whisper # опционально: локальная транскрипция голосовыхLetopis is just the engine. To connect it to a specific archive, create a separate data repository and put the ./tg wrapper there:
#!/bin/sh
exec "$HOME/projects/letopis/.venv/bin/tg" "$@"Everything then runs from the root of the data repository:
chmod +x tg
./tg login # авторизация Telegram-сессии (телефон / код / 2FA)
./tg download --chat mychat --media all
./tg index && ./tg meta
./tg search приветThe engine finds the data root itself: when started, tg looks upward from the current directory for a folder where config.toml and archive/ are located next to each other (or this is explicitly set via the TG_ROOT environment variable).
🤖 Read-only MCP for ChatGPT
Letopis can work as a read-only MCP retrieval gateway for ChatGPT: the server uses the same data/index.db as regular search, but only returns five safe retrieval tools — archive overview, search, aggregates, message lookup, and local context. The MCP process does not sync Telegram, download files, or modify the index.
Installation and launch
Install the MCP SDK and test dependencies into the engine environment:
.venv/bin/pip install -e ".[mcp,test]"Launch via the entrypoint:
.venv/bin/letopis-mcpAlternative form — .venv/bin/python -m tgarchive server. Wait, actually source says .venv/bin/python -m tgarchive.mcp.server? The prompt says: "— .venv/bin/python -m tgarchive.mcp.server." Wait check the source: "Альтернативная форма — .venv/bin/python -m tgarchive.mcp.server." Yes, keep tgarchive.mcp.server. So continue.
By default the server listens on http://127.0.0.1:8765/mcp and accepts only loopback events. For production, set a stable cursor secret and index path in the process environment, for example:
export LETOPIS_MCP_DB=/srv/letopis-data/data/index.db
export LETOPIS_MCP_CURSOR_SECRET='случайный-длинный-секрет'
.venv/bin/letopis-mcpEnvironment variables
Variable | Replaced | Purpose | |
| value of | Path to the SQLite index; relative path is calculated from the project root | |
| none; a temporary random secret per process | HMAC-SHA256 for opaque cursors. Required in production: without it, cursors do not survive a process restart | |
|
| Loopback bind address; the app rejects non-loopback addresses | |
|
| TCP port of the Streamable HTTP endpoint | |
|
| Structured log level ( | |
|
| Max concurrent read-only DB operations | |
|
| Deadline for the SQLite query and waiting for a concurrency slot | |
|
| Max completed calls in the global rolling window | |
|
| Max characters returned in the rolling window | |
|
| Rolling window length in seconds |
The rate limit is intentionally process-global: v1 has no OAuth and no identified principals, so this is not a per-user ACL. MCP reads these variables as process configuration and does not load .env automatically.
Connecting to ChatGPT
The recommended scheme does not publish Letopis directly to the internet:
ChatGPT ↔ OpenAI Secure MCP Tunnel ↔ tunnel-client на этом хосте
↔ 127.0.0.1:8765/mcpSpecific commands and setup steps for Secure MCP Tunnel depend on the current OpenAI workspace and current OpenAI documentation. Verify them at connection time; this repository does not make up an unverified OAuth/tunnel command.
Deployment security
The MCP process needs only data/index.db and the necessary SQLite sidecar files data/index.db-wal / data/index.db-shm. It should not have access to .env, telegram.session, archive/, media, or the manifest. Run the server as a separate Unix user with minimal rights, and perform sync and indexing as a separate process with the required write access.
🗂 Structure
репозиторий с данными/
├── config.toml # настройки: аккаунты, транскрипция, веб-порт
├── .env # api_id / api_hash Telegram
├── telegram.session # сессия аккаунта (и доп. сессии из [accounts])
├── tg -> letopis/.venv/bin/tg # обёртка-энтрипоинт
├── data/
│ └── index.db # SQLite + FTS5 — производный, пересобирается
└── archive/
├── manifest.json # какие чаты отслеживаем, каким аккаунтом, какие медиа качаем
└── <chat_id>/
├── 2025-06.jsonl # сырые сообщения этого месяца — источник истины
├── 2025-07.jsonl
├── transcripts.jsonl # расшифровки голосовых/кружков
├── media_index.jsonl # реестр скачанных файлов
└── media/ # сами файлыJSONL — the source of truth. Files by month;
synconly appends new messages and never touches old ones.index.db— the derived layer. It can be deleted and rebuilt (./tg index --rebuild) at any time without data loss.manifest.json— the manager. It survives index rebuilds and keeps track of which chats/topics are tracked and which media types to download for them.
This split (engine in git, open; data separate and private) allows you to freely develop and share the code without risking a leak of your conversations.
🧭 Commands
Search — the main feature for agents
Command | What it does |
| Full-text search. Flags: |
| Chronological slice of the conversation as a whole |
| Messages around a specific one ( |
| Overview of the chats in the archive |
| Topics of a forum chat |
| State of the archive and index |
Viewers — manual mode
Command | What it does |
| Local web interface: chats → topic chips, infinite scroll, search with filters, jump to date, author filter (click a nickname), inline photo/video, voice player with transcription, replies that jump to thread, |
| The same in terminal: |
Downloader and manager
Command | What it does |
| All account chats (✓ — already in archive) |
| Download chat/topics and add to tracking. Flags: |
| Download new messages for all tracked chats |
| Download files for already downloaded messages |
| Transcribe voice messages to text so they go into search |
| Remove chat from tracking (files remain on disk) |
| Update chat names / re-ندукст archive |
| Authorize a Telegram session (tphone / code / 2FA) |
A chat can be specified by id, alias from config.toml, part of the title, @username, or a t.me/... link. New messages are downloaded with all reactions, polls, and service events.
🎙 Voice transcription
The provider is configured in config.toml [transcription]:
| Provider | Cost | Requirements |
| --- | --- |
| whisper-local | free, local | faster-whisper, small model by default |
| telegram | free | Telegram Premium on the account |
| openai | paid (Whisper API) | OPENAI_API_KEY in `.```
Command | What it does |
| Local web interface: chats → topic chips, infinite scroll, search with filters, jump to date, filter by author (click a nickname), inline photo/video, voice player with transcription, replies that jump to thread, |
| Same in terminal: |
Downloader and manager
Command | What it does |
| All chats of the account (✓ — already in archive) |
| Download a chat/topics and enable tracking. Flags: |
| Download new messages of all tracked chats |
| Download files for already downloaded messages |
| Transcribe voice messages to text so they appear in search |
| Stop tracking a chat (files stay on disk) |
| Update chat names / re-index archive |
| Authorize a Telegram session (phone / code / 2FA) |
A chat can be specified as an id, an alias from config.toml, part of the name, @username, or a t.me/... link. New messages are downloaded with all reactions, polls, and service events.
🎙 Voice transcription
The provider is set in config.toml [transcription]:
Provider | Cost | Requirements |
| free, local |
|
| free | Telegram Premium on the account |
| paid (Whisper API) |
|
👥 Multiple accounts
[accounts]
default = "telegram.session"
backup = "sessions/backup.session"tg login --account backup authorizes a new session. The download / sync / dialogs / meta commands have the --account flag. Each chat in the manifest is tied to its own account.
🗺 Status
Stage | Status | What's included |
A | ✅ ready | Index, search, CLI, Claude Code integration |
B | ✅ ready | Downloader ( |
C | ✅ ready | Viewers: |
Next: scheduled auto-sync, image OCR, Azure Speech provider, data export.
🔒 Security
telegram.session and .env give full access to your Telegram account. Keep them in a private repository with the data, do not commit them to this repository, and never publish them anywhere.
Made so the agent remembers conversations better than you do.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseBqualityAmaintenanceMCP server that exposes any Telegram-Archive instance to LLMs, enabling message search, chat browsing, and access to archived Telegram history.7544GPL 3.0
- AlicenseNot gradedqualityBmaintenanceAn 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.9MIT
- AlicenseAqualityCmaintenanceA local MCP server that enables full-text and semantic search over your own Telegram chats using your personal MTProto login, with everything running locally.7MIT
- AlicenseNot gradedqualityBmaintenanceRead-only MCP server for Telegram chats and channels that provides digest summaries, message search, and action items.27MIT
Related MCP Connectors
Agent-native MCP server over the public saagarpatel.dev corpus. Read-only, stateless.
Search your AI chat history (ChatGPT, Claude, Codex) from any MCP client. Remote, private, read-only
Telegram bridge for your MCP-compatible agent. Bidirectional, no LLM in our stack.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/Toligrim/Letopis-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server