Telegram MCP Server
# Telegram MCP Server
A [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server that exposes Telegram Bot API operations as tools for AI assistants like Claude. Send messages, files, photos, read chat history, and pin messages — all through a standardized MCP interface.
## Features
| Tool | Description |
|------|-------------|
| **send_telegram_message** | Send text messages with Markdown formatting and optional silent mode |
| **send_telegram_file** | Send a local file as a document |
| **send_telegram_file_direct** | Send a file from in-memory content (UTF-8 or Base64) without writing to disk |
| **send_telegram_photo** | Send a local image as a photo |
| **send_telegram_photo_direct** | Send a photo from Base64-encoded content without writing to disk |
| **get_telegram_messages** | Retrieve the latest messages from the configured chat |
| **pin_telegram_message** | Pin a message to the top of the chat |
## Architecture
```
┌──────────────────────┐
│ Claude / AI │
└──────────┬───────────┘
│ stdio (MCP)
┌──────────▼───────────┐
│ MCP Server │
│ (index.ts) │
│ │
│ 7 tool handlers │
└──────────┬───────────┘
│ HTTPS
┌──────────▼───────────┐
│ Telegram Bot API │
└──────────────────────┘
```
The server communicates with the MCP client (e.g. Claude) over **stdio** and makes HTTPS calls to the Telegram Bot API. It is a single-file, stateless TypeScript application executed on-the-fly with [tsx](https://github.com/privatenumber/tsx).
## Prerequisites
- **Node.js** >= 18
- **npm**
- A **Telegram Bot Token** (create one via [@BotFather](https://t.me/BotFather))
- The **Chat ID** of the conversation the bot should interact with
## Setup
### 1. Clone the repository
```bash
git clone https://github.com/GeorgBreithaupt/ChlodwigTelegramMCP.git
cd ChlodwigTelegramMCP
```
### 2. Install dependencies
```bash
npm install
```
### 3. Configure environment variables
Create a `.env` file in the project root:
```env
TELEGRAM_BOT_TOKEN=your-bot-token-here
TELEGRAM_CHAT_ID=your-chat-id-here
```
| Variable | Required | Description |
|----------|----------|-------------|
| `TELEGRAM_BOT_TOKEN` | Yes | Bot API token from [@BotFather](https://t.me/BotFather) (format: `123456:ABC-DEF...`) |
| `TELEGRAM_CHAT_ID` | Yes | Numeric ID of the target chat / user |
> **Tip:** To find your Chat ID, send a message to your bot and visit `https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates` — the `chat.id` field contains the value you need.
### 4. Run the server (standalone)
```bash
npx tsx index.ts
```
The server starts listening on stdio for MCP requests. In practice it is launched automatically by the MCP client.
## MCP Client Configuration
Add the following to your MCP client config to register this server.
### Claude Code (`.mcp.json`)
```json
{
"mcpServers": {
"telegram": {
"command": "npx",
"args": ["--quiet", "tsx", "/absolute/path/to/ChlodwigTelegramMCP/index.ts"]
}
}
}
```
### Claude Desktop (`claude_desktop_config.json`)
```json
{
"mcpServers": {
"telegram": {
"command": "npx",
"args": ["--quiet", "tsx", "/absolute/path/to/ChlodwigTelegramMCP/index.ts"]
}
}
}
```
Config file location:
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
## Tool Reference
### send_telegram_message
Send a text message with optional Markdown formatting.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `text` | string | Yes | Message text (supports Markdown) |
| `silent` | boolean | No | Send without notification sound |
### send_telegram_file
Send a file from the local filesystem as a document.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `filePath` | string | Yes | Absolute path to the file |
| `caption` | string | No | Caption for the document |
### send_telegram_file_direct
Send a file from in-memory content — no disk write required.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `fileName` | string | Yes | Name for the file (e.g. `report.csv`) |
| `fileContent` | string | Yes | File content as a string |
| `encoding` | string | No | `utf-8` (default) or `base64` |
| `caption` | string | No | Caption for the document |
### send_telegram_photo
Send a local image file as a photo.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `filePath` | string | Yes | Absolute path to the image |
| `caption` | string | No | Caption for the photo |
### send_telegram_photo_direct
Send a photo from Base64-encoded content — no disk write required.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `photoContent` | string | Yes | Base64-encoded image data |
| `fileName` | string | Yes | File name (e.g. `chart.png`) |
| `caption` | string | No | Caption for the photo |
### get_telegram_messages
Retrieve the most recent messages from the configured chat.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `limit` | number | No | Number of messages to return (default: 10) |
### pin_telegram_message
Pin a message to the top of the chat.
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `messageId` | number | Yes | ID of the message to pin |
## Tech Stack
| Component | Technology |
|-----------|-----------|
| Language | TypeScript |
| Runtime | Node.js (via [tsx](https://github.com/privatenumber/tsx)) |
| MCP SDK | [@modelcontextprotocol/sdk](https://www.npmjs.com/package/@modelcontextprotocol/sdk) |
| Transport | stdio |
| Env management | [dotenv](https://www.npmjs.com/package/dotenv) |
| HTTP client | Native `fetch` API |
## License
[ISC](LICENSE)
TDQS
Scored across 7 tools
The send actions are mostly distinct by content type: message, file, photo, and pinning. The local-file vs _direct variants overlap conceptually, but their descriptions clearly differentiate disk-based sending from in-memory/base64 content.
All tools use consistent snake_case and follow a predictable verb_telegram_resource pattern (send_telegram_message, get_telegram_messages, pin_telegram_message). The _direct suffix is applied consistently to file and photo variants.
Seven tools are well-scoped for a Telegram chat integration: sending text, files, photos, fetching messages, and pinning. Each tool earns its place without excessive surface area.
Core messaging workflows are covered: send text/files/photos, fetch new text messages, and pin. Minor lifecycle operations such as edit, delete, unpin, or retrieving received media are missing, but agents can work around these gaps for most tasks.