tg2codexMCP

Developer field guide

Telegram,
meet MCP.

Give your coding assistant the thread behind the task. Search Telegram messages, read the conversation and keep the archive on your machine.

Fig. 01 / Message anatomy
R
Release roomTelegram group
Today
Maya

The release checklist is ready for review.

09:41
01 Source
message
MCP tool call
telegram_search
query "release"
02 Client
query
Illustrated exampleTelegram → SQLite → Client

01 / Installation

Deploy
locally.

Start with one dedicated bot and one MCP client. The client launches the server when it connects.

Node.js 24stdio
  1. Build the connector

    With Node.js 24 active, run these commands in a terminal. The checks build the server and test it with synthetic messages.

    Terminal Shell
    git clone https://github.com/vladimirperepelytsia/tg2codexMCP.git
    cd tg2codexMCP
    npm ci
    npm run check
    cp -n .env.example .env
  2. Add one or more Telegram channels

    Create one dedicated bot with /newbot in @BotFather. Add that same bot to every channel you want to read. In your private .env, list their numeric chat IDs on one ALLOWED_CHAT_IDS line, separated by commas.

    .env Replace the placeholders
    TELEGRAM_BOT_TOKEN=<your_bot_token>
    ALLOWED_CHAT_IDS=<tg_channel_id>,<tg_channel_id>
    DB_PATH=/absolute/private/path/connector.sqlite
    ENABLE_SEND=false

    This example connects two channels. Replace each <tg_channel_id> with a different channel’s numeric ID, including its leading minus sign. For one channel, use just its ID. To add another later, give the bot access, append a comma and the new ID, then restart the MCP server.

    Keep the example’s stdio and polling settings. Polling acknowledges updates, so use a bot without an active webhook or another poller.

  3. Connect your MCP client

    For Codex, merge this into ~/.codex/config.toml. Use the Node 24 executable from command -v node and replace both project paths with the absolute path to your checkout.

    config.toml Codex · stdio
    [mcp_servers.telegram]
    command = "/absolute/path/to/node"
    args = [
      "--env-file=/absolute/path/to/tg2codexMCP/.env",
      "/absolute/path/to/tg2codexMCP/dist/src/main.js"
    ]
    startup_timeout_sec = 20

    Open a new Codex session and inspect /mcp for the Telegram read tools. For another client, use its configuration example:

    Running several clients at once?

    Use one shared HTTP process for the bot and database. Configure your private .env from the HTTP example, including a random read token of at least 32 characters. Launch it with npm start. Point each local client at http://127.0.0.1:8787/mcp with the same read token. Use the HTTP settings for your client.

02 / First read

Follow one
message.

With the server connected, post a new message your bot can see in the allowed chat. Use a distinctive phrase like “release checklist”, then ask your assistant to find it.

Example session
You → Assistant

“Search chat <tg_channel_id> for ‘release checklist’. Show the matching message and its ID.”

Each search reads one channel. To verify several channels, post a test message in each and repeat the prompt with that channel’s numeric ID.

No matches yet?

Check the chat ID and bot visibility. In a group with privacy mode enabled, try a command addressed to your bot. Search for its exact text after the server starts. Telegram provides pending or new updates, not the chat’s full history.

03 / Tool reference

Work with a thread.

Use these prompts in your client. Substitute your allowed chat ID and a message ID returned by a read.

Read

telegram_messages

“List the last five retained messages in chat <tg_channel_id>.”

Search

telegram_search

“Find messages containing ‘release’ in chat <tg_channel_id>. Include their IDs.”

Context

telegram_context

“Show the two messages on either side of that message ID in the same chat.”

What stays local?

The server retains allowed messages in SQLite for seven days by default. Text returned by a tool is shared with the client you choose. Sending is disabled by default. Security guide ↗

Which clients have been tested?

SDK tests cover stdio and HTTP. The individual client applications and live Telegram ingestion still await end-to-end verification. Claude Desktop manual configuration depends on version and policy. Verification matrix ↗