telegram-search-mcp
Provides read-only search and reading of local Obsidian vault notes, including Markdown, frontmatter tags, aliases, wikilinks, and backlinks.
Provides full-text search and reply-chain context for exported Telegram chat archives in JSONL format, with exact chat and message IDs, senders, timestamps, and permalinks.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
telegram-search-mcp
Search exported Telegram chats and X posts with SQLite FTS5, then follow the reply chain for context. A read-only MCP interface also lets you search local Obsidian notes.
English | 简体中文
Overview
High-volume Telegram groups hold valuable troubleshooting logs, firsthand reports, and discussions—yet native chat search lacks ranking, cross-language synonym matching, and thread-level context. Feeding raw chat dumps straight to an LLM also causes hallucinations and broken citations.
The CLI builds a SQLite FTS5 index from Telegram JSONL archives and optional X exports. Obsidian notes are read directly from the configured vault, not imported into the database.
Every search hit carries exact chat_id, message_id, sender, timestamp, and permalink, allowing AI agents (Codex, Claude Desktop, Cursor, etc.) to inspect full reply chains before answering with grounded quotes.
Data boundary: Indexing and search run locally without a Telegram session or API key. An MCP client receives the text it requests; if that client uses a hosted model, its own data policy applies.
Related MCP server: Keepygaga RAG
Features
Zero External Database Dependencies — Powered by Node.js built-in
node:sqlitewith FTS5 full-text indexing and BM25 ranking.Bilingual CJK/English Search & Alias Expansion — Segments Chinese/English text via
Intl.Segmenter, supports multi-tier FTS fallback (strict AND->pairwise->relaxed OR), and expands customizable bilingual synonym groups (e.g.,k8s<->Kubernetes<->容器编排).Reply-Chain Context Reconstruction —
read_contextwalks upreply_to_idancestors, collects direct replies, and fetches surrounding chronological messages so agents never quote out of context.Multi-Source Unified Retrieval — Query Telegram group archives, optional X/Twitter posts & bookmarks, and an optional local Obsidian vault (with frontmatter tags, aliases,
[[wikilinks]], and backlinks) through one MCP server.Hot-Reload Ready — Each MCP tool call opens SQLite fresh, so scheduled background
build-dbruns take effect immediately without restarting your AI client.Data-Safety Guardrails —
build-dbrebuilds atomically inside a single transaction and refuses to wipe an existing database if the export directory is missing or empty.Privacy-First External Config — Keep private chat IDs, excluded groups, and domain-specific synonym tables completely outside the repository via
--configorTG_INTEL_CONFIG.
Architecture
flowchart LR
subgraph Sources["Local Data Sources (Offline)"]
TG["Telegram Exports<br/>(*.jsonl)"]
X["X / Twitter Exports<br/>(optional *.json)"]
OB["Obsidian Vault<br/>(optional *.md)"]
CFG["Private Config<br/>(TG_INTEL_CONFIG)"]
end
subgraph Engine["Indexing & Query Engine (Node.js 22+ / TS)"]
BUILD["CLI: build-db<br/>Transactional Rebuild + Guard"]
DB[("SQLite intel.db<br/>messages + FTS5 + BM25")]
WIKI["Markdown & Wikilink<br/>Graph Scanner"]
end
subgraph Interface["Read-Only Interfaces"]
MCP["MCP Server (stdio)<br/>6 Read-Only Tools"]
CLI["CLI Commands<br/>query-db / context / db-stats"]
end
subgraph Clients["AI Agents & Users"]
AGENT["Codex / Claude Desktop /<br/>Cursor / MCP Clients"]
end
TG --> BUILD
X --> BUILD
CFG --> BUILD
BUILD --> DB
CFG -.->|Runtime Aliases| MCP
DB --> MCP
DB --> CLI
OB --> WIKI --> MCP
MCP <-->|JSON-RPC over stdio| AGENTQuick Start
Prerequisites
Node.js
>= 22.13(uses built-innode:sqlite)
1. Install & Verify
git clone https://github.com/deimos6677/telegram-search-mcp.git
cd telegram-search-mcp
npm install
npm test2. Build a Demo Database (Included Sample Data)
Try it immediately with the anonymized fixtures in examples/:
npx tsx src/cli.ts build-db \
--db data/demo.db \
--input examples \
--config examples/config.example.json
npx tsx src/cli.ts query-db "PostgreSQL" --db data/demo.db --days 0
npx tsx src/cli.ts context 10001 102 --db data/demo.db
npx tsx src/cli.ts db-stats --db data/demo.db3. Input JSONL Format
Place one or more *.jsonl files in your export directory (one JSON object per line):
{"id":"101","chatId":"10001","senderId":"u1","senderName":"Alice","timestamp":1790000000,"text":"Docker PostgreSQL volume permission error","replyToId":null,"links":[{"url":"https://example.com/guide"}]}Required:
id,chatId,senderId,senderName,timestamp(Unix seconds),textOptional:
replyToId,links,deletedAt(messages withdeletedAtare skipped)
MCP Integration
Run Standalone
TG_INTEL_DB=/path/to/intel.db \
TG_INTEL_CONFIG=/path/to/private-config.json \
TG_INTEL_WIKI_DIR=/path/to/obsidian-vault \
npm run mcpConfigure in Codex / Claude Desktop / Cursor
{
"mcpServers": {
"telegram-search-mcp": {
"command": "node",
"args": [
"/absolute/path/to/telegram-search-mcp/node_modules/tsx/dist/cli.mjs",
"/absolute/path/to/telegram-search-mcp/src/mcp-server.ts"
],
"env": {
"TG_INTEL_DB": "/absolute/path/to/intel.db",
"TG_INTEL_CONFIG": "/absolute/path/to/private-config.json",
"TG_INTEL_WIKI_DIR": "/absolute/path/to/obsidian-vault"
}
}
}
}
TG_INTEL_CONFIGandTG_INTEL_WIKI_DIRare both optional. Wiki tools (search_wiki,read_wiki) are automatically registered only whenTG_INTEL_WIKI_DIRpoints to an existing directory.
Exposed MCP Tools
Tool | Description |
| Full-text FTS5 + BM25 search with bilingual alias expansion. Filter by |
| Reconstructs full conversation context: reply ancestor chain, direct replies, and surrounding chronological messages ( |
| Lists recent substantive messages (noise-filtered), newest first. |
| Returns total message counts, date coverage, and per-channel latest sync timestamp. |
| Searches or lists Markdown notes in an Obsidian vault by title, alias, tag, or body (requires |
| Reads a full Obsidian note together with outgoing |
For recommended agent prompting & citation rules, see SKILL.md.
Custom Configuration (TG_INTEL_CONFIG)
Keep personal chat IDs and custom synonym tables out of source control by placing a JSON file outside the repo (see examples/config.example.json):
The IDs below are synthetic. No public group username is provided. If a configured file is missing, the build stops rather than indexing without its exclusions.
{
"chats": {
"10001": { "name": "Engineering Group" }
},
"excludedChats": ["99999"],
"aliasGroups": [
["k8s", "kubernetes", "容器编排"],
["pg", "postgres", "postgresql"]
],
"compoundFixes": [
["云\\s+原\\s+生", "云原生"]
]
}Pass
--config <path>tobuild-db, or setTG_INTEL_CONFIGfor both CLI and MCP server.chatsmaps raw numeric chat IDs to readable names and optional publict.me/<username>/<msg_id>links.excludedChatsskips specified chats during database builds.aliasGroups&compoundFixesextend the built-in generic query expansion rules at search time.
CLI Reference
Command | Usage |
|
|
|
|
|
|
|
|
| Legacy v0.1 JSON thread-clustering pipeline ( |
Privacy & Security
100% Local Processing — No telemetry, no external network calls, no LLM API keys.
Git Safeguards —
.gitignoreexplicitly excludesdata/,out/,*.db,*.sqlite*,*.jsonl(except sample fixtures),.env*,chats.json,sender-names.json, andintel-config.json.Never Commit Real Archives — Always store private exports, databases, and personal
config.jsonfiles outside Git history.
Project Structure
├── src/
│ ├── db.ts # SQLite FTS5 schema, transactional builder, BM25 query & Obsidian wiki reader
│ ├── mcp-server.ts # Read-only MCP stdio server exposing 4 core + 2 optional wiki tools
│ ├── cli.ts # CLI entry point for building, querying, and inspecting indexes
│ ├── thread.ts # Message clustering, noise filtering & deduplication (v0.1 thread index)
│ ├── score.ts # Heuristic thread scoring
│ ├── ingest.ts # JSONL export reader
│ ├── search.ts # In-memory thread search
│ ├── store.ts # JSON index persistence
│ └── types.ts # Shared TypeScript interfaces
├── examples/ # Anonymized JSONL and config.example.json fixtures
├── test/ # Node built-in test runner suite (MCP, FTS5, guardrails, config, threads)
├── SKILL.md # Agent retrieval & evidence-citation workflow guide
├── README.md # English documentation
└── README_zh.md # Simplified Chinese documentationLimitations
Lexical / keyword search (FTS5 + BM25 + alias expansion) only; no vector embeddings.
build-dbperforms a full transactional rebuild rather than row-level incremental updates.Operates on exported snapshots rather than a live Telegram bot/MTProto stream.
License
MIT — see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Search and reason over your Obsidian-style Markdown vault, right from ChatGPT.
Private, multimodal knowledge store for agents: hybrid search with cited, provenance-backed results.
Personal context for every AI: search, read, and write back to your private Markdown library.
Persistent memory and knowledge management for AI agents with semantic search and 50+ tools.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceProvides cited retrieval over local-first knowledge sources (TXT, CSV, Google Sheets, Zoho Mail, MBOX) via SQLite FTS5, with tools for searching and checking source status, returning evidence links instead of generated answers.MIT
- AlicenseAqualityCmaintenanceEnables local-first hybrid knowledge retrieval from authorized Markdown and plain-text files, combining full-text and vector search with reranking and traceable source references via a single search tool.1MIT
- FlicenseNot gradedqualityCmaintenanceEnables agents to search a local, fully offline personal document library (Markdown/txt/PDF/docx) via SQLite FTS5 trigram search with subject-terminology expansion, returning every hit with its domain, document title, section path, and page or offset provenance. It also exposes domain statistics, incremental ingestion, and document deprecation as tools, alongside a read-only, runtime-persona-scoped ask/coverage mode.-
- AlicenseNot gradedqualityBmaintenanceGives AI agents fast, read-only access to a local knowledge base of Markdown notes and other text documents via a SQLite full-text index. Enables ranked section-level search, reading whole notes or single sections, heading outlines, note listing, and link/backlink navigation without slow disk walks.Apache 2.0