Telegram MCP Server
Enables interaction with Telegram chat history, including text, photos, and documents, via the GramJS MTProto userbot. It provides tools for searching chats, syncing message history, and downloading media files for local analysis.
README
Telegram MCP Server
MCP-сервер для извлечения истории чатов Telegram, включая текстовые сообщения, фото и документы. Использует GramJS (MTProto userbot) для полного доступа к личным чатам.
Требования
- Node.js 18+
- Telegram API credentials (my.telegram.org)
Установка
npm install
cp .env.example .env
# Заполнить TELEGRAM_API_ID и TELEGRAM_API_HASH в .env
Первый запуск — аутентификация
npm run auth
Введи номер телефона → код из Telegram → пароль 2FA (если есть).
Сессия сохранится в telegram.session.
Сборка и запуск
npm run build
npm start
Транспорты
Сервер поддерживает два режима работы, выбираемых переменной TRANSPORT:
| Переменная | Значение | Описание |
|---|---|---|
TRANSPORT=stdio |
по умолчанию | Локальный запуск через stdin/stdout, авторизация не нужна (процесс изолирован) |
TRANSPORT=http |
сетевой режим | HTTP-сервер на порту PORT (по умолчанию 3000), требуется AUTH_TOKEN |
stdio (по умолчанию)
Сервер общается с клиентом через stdin/stdout. Безопасность обеспечивается изоляцией процесса — доступ имеет только тот, кто его запустил.
HTTP с Bearer token авторизацией
Для сетевого доступа (например, сервер на удалённой машине). Каждый запрос должен содержать заголовок:
Authorization: Bearer <ваш_токен>
Без валидного токена сервер вернёт 401 Unauthorized.
Сгенерировать токен:
node -e "console.log(crypto.randomUUID())"
Настроить в .env:
TRANSPORT=http
PORT=3000
AUTH_TOKEN=ваш-секретный-токен
Подключение к Claude Code / Claude Desktop
Claude Code — stdio (локально)
claude mcp add telegram-mcp -- node /path/to/telegram-mcp-server/dist/index.js
Claude Code — HTTP (удалённый сервер)
claude mcp add telegram-mcp \
--transport http \
--url http://your-server:3000/mcp \
--header "Authorization: Bearer ваш-секретный-токен"
Claude Desktop (config)
{
"mcpServers": {
"telegram": {
"command": "node",
"args": ["/path/to/telegram-mcp-server/dist/index.js"],
"env": {
"TELEGRAM_API_ID": "your_id",
"TELEGRAM_API_HASH": "your_hash",
"TELEGRAM_SESSION_PATH": "/path/to/telegram.session",
"DATA_DIR": "/path/to/data"
}
}
}
}
Docker
Сборка
docker build -t telegram-mcp .
Запуск — stdio
docker run --rm -i \
-e TELEGRAM_API_ID=12345 \
-e TELEGRAM_API_HASH=abc123 \
-v ./telegram.session:/app/telegram.session \
-v ./data:/app/data \
telegram-mcp
Запуск — HTTP с авторизацией
docker run -d \
-e TRANSPORT=http \
-e AUTH_TOKEN=ваш-секретный-токен \
-e TELEGRAM_API_ID=12345 \
-e TELEGRAM_API_HASH=abc123 \
-v ./telegram.session:/app/telegram.session \
-v ./data:/app/data \
-p 3000:3000 \
telegram-mcp
Инструменты (Tools)
| Tool | Описание |
|---|---|
telegram_list_chats |
Список всех чатов |
telegram_find_chat |
Поиск чата по имени/username/ID |
telegram_get_history |
Получить сообщения (без скачивания медиа) |
telegram_sync_chat |
Основной — полная синхронизация чата с медиа |
telegram_download_media |
Скачать медиа из конкретного сообщения |
telegram_sync_status |
Статус последней синхронизации |
telegram_list_media |
Список скачанных медиафайлов |
Типичный workflow
1. telegram_find_chat("Мама") → получаем chat_id
2. telegram_sync_chat(chat_id) → скачиваем всё
3. telegram_list_media(chat_id, "photo") → список фотографий
4. Загружаем файлы из data/raw/{chat_id}/media/ в Claude для анализа
Через 2 недели:
telegram_sync_chat(chat_id) → скачает только новые сообщения
Структура данных
data/
└── raw/
└── {chat_id}/
├── messages.json # все сообщения
├── media_index.json # индекс медиафайлов
├── sync_state.json # состояние синхронизации
└── media/ # скачанные файлы
├── photo_123.jpg
├── doc_456.pdf
└── ...
Безопасность
- Сессия Telegram хранится в файле (добавлен в .gitignore)
- API credentials в .env (добавлен в .gitignore)
- HTTP транспорт защищён Bearer token авторизацией
- Данные хранятся только локально
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.