Telegram integration with both MCP (Model Context Protocol) and HTTP API support. Based on telegram-mcp with added HTTP API for local script automation.
- MCP Server: Full Telegram integration for Claude Desktop, Cursor, and MCP-compatible clients
- HTTP API: REST endpoints for local scripts and automation
- Python Client: Simple client library for programmatic access
- Docker Compose: Run both services in containers
-
Get Telegram API credentials from https://my.telegram.org
-
Create
.envfile:cp .env.example .env # Edit .env with your credentials -
Generate session string:
pip install -r requirements.txt python session_string_generator.py # Add the output to .env as TELEGRAM_SESSION_STRING
docker compose up telegram-api --build -dUse from Python:
from telegram_client import TelegramClient
client = TelegramClient() # http://localhost:8080
print(client.get_chats())
client.send_message(chat_id=123, message="Hello!")
client.close()Or via curl:
curl http://localhost:8080/chats
curl -X POST http://localhost:8080/messages/send \
-H "Content-Type: application/json" \
-d '{"chat_id": 123, "message": "Hello!"}'# Register with Claude Code
claude mcp add telegram-mcp -- uv run --directory /path/to/telegram-mcp-api python main.pydocker compose up --build -d| Service | Purpose | Access |
|---|---|---|
telegram-mcp |
MCP server for Claude/Cursor | stdio |
telegram-api |
HTTP API for scripts | http://localhost:8080 |
| Endpoint | Method | Description |
|---|---|---|
/health |
GET | Health check |
/me |
GET | Current user info |
/chats |
GET | List chats (paginated) |
/chats/list |
GET | List chats with filters |
/chats/{id} |
GET | Get chat details |
/chats/{id}/messages |
GET | Get messages |
/messages/send |
POST | Send message |
/messages/search |
POST | Search messages |
/contacts |
GET | List contacts |
/drafts/save |
POST | Save draft |
See api.py for full endpoint documentation.
See the examples/ directory for ready-to-use scripts:
example_usage.py- Basic operations demosend_message.py- Send messages via CLIsearch_messages.py- Search messages in a chat
telegram-mcp-api/
├── main.py # MCP server (original)
├── telegram_core.py # Shared Telegram functionality
├── api.py # FastAPI HTTP API
├── telegram_client.py # Python client library
├── Dockerfile # MCP server container
├── Dockerfile.api # HTTP API container
├── docker-compose.yml # Container orchestration
├── requirements.txt # Python dependencies
├── session_string_generator.py
└── examples/
├── example_usage.py
├── send_message.py
└── search_messages.py
Based on telegram-mcp by chigwell.
MIT