Skip to main content
Glama
nullnumber1

Telegram Community MCP

by nullnumber1

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

Related MCP server: lore

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.org often 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):

  1. Edit tg-community-search.service — replace YOUR_USER with your username

  2. Deploy:

    make deploy REMOTE_HOST=192.168.1.42 REMOTE_USER=myuser REMOTE_PASS=mypass
  3. 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

Available Tools

5 tools
get_contextB

Get thread context around a message: window messages before/after, plus all replies to the message.

ParametersJSON Schema
NameRequiredDescriptionDefault
windowNo
message_idYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.1/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It explains what is returned (window before/after, all replies), which conveys behavioral scope, but does not disclose permissions, rate limits, or whether it's a read-only operation. For a read tool with no annotations, this is minimal.

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?

Single sentence, front-loaded with the core purpose, and ends with the scope. No wasted words.

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

Completeness3/5

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

With an output schema present, the description needn't explain return values. However, it lacks usage context (when to use vs siblings) and full parameter semantics. It is adequate but incomplete for an agent to select and invoke correctly without checking other tools.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'window messages before/after', implying the window parameter controls the number of messages, but does not specify that it's an integer count or its default (10). The message_id is clearly required. The description adds some meaning but leaves the window parameter semantics underspecified.

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

Purpose4/5

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

States a specific verb (get) and resource (context around a message), and clarifies the scope: window messages before/after plus all replies. This distinguishes it from sibling tools like search, though it doesn't explicitly contrast with sync or list_chats.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives like search or get_stats. The description implies usage (to get context around a message) but provides no explicit when/when-not criteria or prerequisites.

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

get_statsA

Index statistics: total messages, per-chat breakdown, DB size.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.5/5.0
Behavior3/5

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

With no annotations, the description carries the full behavioral burden. It discloses the categories of data returned, but omits read-only status, side effects, permissions, or caching behavior. For a simple stats tool this is minimally adequate but leaves clear gaps.

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?

A single, front-loaded sentence that identifies the resource and its contents with no filler or repetition.

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

Completeness4/5

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

An output schema exists, so the description need not explain return values in detail. It still lists the main statistics, which is sufficient for a no-parameter read tool. It could mention read-only safety, but the core context is complete.

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?

The tool takes zero parameters, so there is no parameter semantics to explain. Per the scoring rules, zero parameters sets a baseline of 4.

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

Purpose4/5

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

The description names a specific resource ('Index statistics') and enumerates the contents ('total messages, per-chat breakdown, DB size'). It does not explicitly contrast with siblings like list_chats, but the purpose is unambiguous and distinct.

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

Usage Guidelines2/5

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

It describes what statistics are returned but gives no guidance on when to use this tool versus alternatives such as list_chats or search. There are no conditions, exclusions, or prerequisites stated.

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

list_chatsA

Show indexed chats: name, ID, message count, last sync date.

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior3/5

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

With no annotations, the description carries the full behavioral burden, and it does disclose the meaningful scope constraint that only *indexed* chats are shown. However, it says nothing about ordering, pagination, or result-size limits for what could be a long list.

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

Conciseness4/5

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

A single compact sentence with the scope constraint ('indexed') front-loaded before the field list. It is a fragment rather than a full sentence, but no words are wasted.

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

Completeness4/5

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

An output schema exists, so the description need not explain return values, and an empty input schema means no parameter semantics are required. The only real gap is pagination/ordering behavior for a potentially long list.

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?

The tool takes zero parameters, which sets the baseline at 4. The field list in the description describes the return shape rather than adding parameter semantics, but there is nothing for it to clarify.

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

Purpose4/5

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

States a clear verb ('Show') and resource ('indexed chats') plus the returned fields, so an agent knows exactly what comes back. It does not explicitly contrast itself with the sibling 'search' or 'get_stats', so sibling differentiation is left implicit.

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?

Usage is only implied: a zero-argument listing tool is fairly self-explanatory, but the description never says when to pick this over 'search' (e.g., to enumerate all indexed chats vs. query them). No exclusions or prerequisites are given.

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

syncA

Sync new messages from Telegram.

Without arguments — all configured chats.
With chat_id — only the specified chat.
Returns the number of added messages.
ParametersJSON Schema
NameRequiredDescriptionDefault
chat_idNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.9/5.0
Behavior3/5

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

With no annotations provided, the description carries the full behavioral burden. It does disclose that messages are added and that the return value is a count of added messages, which is useful. However, it omits side effects (what gets stored, idempotency on re-sync), auth/network requirements, and whether the operation is read-only or mutating.

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?

Three short, front-loaded sentences with no redundancy. The default behavior is stated first, then the parameter override, then the return value.

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

Completeness4/5

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

For a single-parameter tool with an output schema, the description covers the key operational modes and the return semantics. The lack of annotations means a bit more side-effect detail would help, but nothing essential for correct invocation is missing.

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?

Schema description coverage is 0%, so the description must compensate, and it does: it explains that chat_id scopes the sync to one chat while its absence means all configured chats. That adds real meaning beyond the bare integer/null schema, though it does not clarify how chat_id is obtained.

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

Purpose4/5

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

The description names a specific verb and resource ('Sync new messages from Telegram'), making the action unambiguous despite the terse tool name 'sync'. It is clearly distinct from siblings like search, get_stats, and list_chats, though it does not explicitly reference any of them.

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?

It explicitly describes the two invocation modes: no arguments syncs all configured chats, while passing chat_id restricts the sync to that chat. This is clear contextual guidance, but there is no statement of when NOT to use it or which sibling to prefer for related needs.

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.

  1. 5 tool updatesv0.1.0
    • First observedget_context
    • First observedget_stats
    • First observedlist_chats
    • First observedsearch
    • First observedsync

TDQS

A3.7/5.0

Scored across 5 tools

Disambiguation5/5

Each tool targets a distinct operation: sync ingests messages, get_stats reports index metrics, search queries messages, get_context expands a thread, and list_chats enumerates chats. Search and get_context both retrieve messages but are clearly differentiated (query vs. thread expansion around a known message). No meaningful overlap.

Naming Consistency4/5

Three tools follow a clean verb_noun pattern (get_stats, get_context, list_chats), while sync and search are bare verbs. This is a minor deviation but still readable and consistent in spirit (all lowercase snake_case).

Tool Count5/5

Five tools is well within the ideal 3-15 range and each earns its place in the ingest-search-context lifecycle. Nothing is redundant or superfluous.

Completeness4/5

The read/index domain is well covered: sync, stats, search, thread context, and chat listing form a coherent lifecycle. Minor gaps exist (no fetch-by-message-ID, no chat add/remove or re-index management), but agents can work around these via search and list_chats.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Claude Desktop to search and query personal document collections (PDF, Word, Markdown, text) using semantic search and conversational AI with full context preservation across exchanges.
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Enables local semantic search over documents and code for Claude Code and Claude Desktop, running entirely offline with local embeddings and vector storage.
    12
    82 PyPI
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Claude Desktop to perform local-first semantic search, ingest documents, and manage a private knowledge base with hybrid search, PII redaction, and multi-format support.
    1
    MIT