ChatGPT to Telegram MCP

ChatGPT to Telegram MCP

Publish reliable, duplicate-free Telegram posts from ChatGPT — manually or as part of a scheduled workflow.

Category
访问服务器

README

<div align="center">

ChatGPT to Telegram MCP

Publish reliable, duplicate-free Telegram posts from ChatGPT — manually or as part of a scheduled workflow.

MIT License Node.js Cloudflare Workers Model Context Protocol OAuth 2.1

Features · Architecture · Quick start · Connect ChatGPT · Security

</div>

ChatGPT to Telegram MCP is a Streamable HTTP MCP server for Cloudflare Workers. It gives ChatGPT two focused tools: read the posts this server sent during the previous 48 hours, and publish one post to a fixed Telegram channel. Exact-text and source-URL deduplication prevents accidental reposts.

Use it in an ordinary ChatGPT conversation or make publishing part of a scheduled workflow when scheduled tasks and custom MCP apps are available for your account or workspace. The Worker itself does not run a cron job.

[!NOTE] This is an unofficial open-source project and is not affiliated with OpenAI or Telegram.

Features

  • ChatGPT-ready MCP endpoint using Streamable HTTP.
  • One fixed Telegram destination controlled by server configuration, not model input.
  • 48-hour history backed by Cloudflare D1.
  • Duplicate protection for normalized text and canonical source URLs.
  • OAuth 2.1 authentication with GitHub sign-in, PKCE S256, DCR, and CIMD.
  • GitHub allowlist for explicit access control.
  • Safe retries through pending D1 reservations and idempotent tool behavior.
  • Cloudflare-native deployment with Workers, KV, D1, logs, and traces.

Architecture

flowchart LR
    C["ChatGPT<br/>chat or scheduled workflow"]
    W["Cloudflare Worker<br/>OAuth + MCP server"]
    G["GitHub OAuth<br/>identity check"]
    K["Cloudflare KV<br/>OAuth state and tokens"]
    D["Cloudflare D1<br/>48-hour send history"]
    T["Telegram Bot API<br/>fixed channel"]

    C -->|"OAuth 2.1 + MCP"| W
    W <-->|"sign in"| G
    W <-->|"OAuth records"| K
    W <-->|"history and dedupe"| D
    W -->|"sendMessage"| T

Publish flow

sequenceDiagram
    participant C as ChatGPT
    participant M as MCP Worker
    participant D as D1
    participant T as Telegram

    C->>M: get_previous_messages
    M->>D: Read the previous 48 hours
    D-->>M: Posts and source URLs
    M-->>C: History
    C->>C: Prepare a non-duplicate digest
    C->>M: send_message(text, source_urls)
    M->>D: Reserve fingerprint and URLs
    alt Duplicate found
        D-->>M: Existing matches
        M-->>C: sent=false, duplicate=true
    else New post
        D-->>M: Reservation created
        M->>T: sendMessage
        T-->>M: Telegram message
        M->>D: Mark reservation as sent
        M-->>C: sent=true
    end

MCP tools

Tool Purpose Important behavior
get_previous_messages Returns up to 100 posts sent by this server during the previous 48 hours. Reads the Worker's D1 history; it cannot see manual posts or posts from other bots.
send_message Publishes one post to the configured Telegram channel. Rejects matching text or source URLs found in the 48-hour window. Include every represented article URL in source_urls.

The public tool names and response formats are stable across the project rebrand.

Prerequisites

  • Node.js 20 or newer.
  • A Cloudflare account with Wrangler authenticated.
  • A Telegram bot that can post to the target channel.
  • A GitHub OAuth App.
  • A ChatGPT account or workspace with custom MCP app support for the way you intend to use it.

Quick start

1. Install

git clone https://github.com/d8rt8v/chatgpt-to-telegram-mcp.git
cd chatgpt-to-telegram-mcp
npm install

2. Create local configuration

macOS/Linux:

cp wrangler.example.jsonc wrangler.jsonc
cp .env.example .env

PowerShell:

Copy-Item wrangler.example.jsonc wrangler.jsonc
Copy-Item .env.example .env

Both files are ignored by Git. Keep real account IDs and credentials there only.

3. Create Cloudflare resources

npx wrangler d1 create chatgpt-telegram-history
npx wrangler kv namespace create OAUTH_KV

Copy the returned D1 and KV IDs into wrangler.jsonc without changing the DB and OAUTH_KV binding names.

4. Configure the GitHub OAuth App

For a Worker deployed at https://chatgpt-tg-mcp.<subdomain>.workers.dev, set:

  • Homepage URL: https://chatgpt-tg-mcp.<subdomain>.workers.dev
  • Authorization callback URL: https://chatgpt-tg-mcp.<subdomain>.workers.dev/callback

Put the OAuth Client ID and Client Secret in .env.

5. Configure environment values

Variable Description
TELEGRAM_BOT_TOKEN Token issued by BotFather.
TELEGRAM_CHANNEL_ID Fixed destination, such as @channel_name or a numeric channel ID.
GITHUB_CLIENT_ID GitHub OAuth App Client ID.
GITHUB_CLIENT_SECRET GitHub OAuth App Client Secret.
ALLOWED_GITHUB_LOGINS One GitHub login or a comma-separated allowlist, for example alex,editor2.

All five values are uploaded as encrypted Worker secrets. Wrangler also loads .env for local development when no .dev.vars file exists.

6. Migrate and deploy

npm run db:migrate:remote
npm run deploy
npm run secrets:push

npm run secrets:push runs wrangler secret bulk .env. A production deployment does not receive values from the local .env file automatically.

<details> <summary><strong>Migrating an existing deployment</strong></summary>

Keep the existing D1 database ID, KV namespace ID, binding names, and migration state in your local wrangler.jsonc. The rebrand changes only the Worker name and public URL; it does not recreate or erase D1/KV data.

Before deploying:

  1. Fill the two blank secret values in the local .env.
  2. Change the GitHub OAuth App homepage and callback to the new chatgpt-tg-mcp URL.
  3. Deploy the renamed Worker and push .env with npm run secrets:push.
  4. Reconnect the MCP app in ChatGPT.

The old Worker is not deleted automatically. After the new endpoint is verified, retire the old Worker or remove its OAuth and Telegram secrets; otherwise it remains a second write-capable endpoint and existing MCP tokens may continue to publish through it. Deleting the old Worker does not delete the separately managed D1 database or KV namespace reused by the new deployment.

If the existing D1 migration is already applied, do not apply it again just for the rebrand.

</details>

Connect ChatGPT

Add the public MCP endpoint as a custom app/server:

https://chatgpt-tg-mcp.<subdomain>.workers.dev/mcp

Choose OAuth authentication. ChatGPT should discover the OAuth endpoints automatically; do not paste GitHub credentials into ChatGPT. Sign in with a GitHub account listed in ALLOWED_GITHUB_LOGINS.

Interactive use works anywhere your ChatGPT account or workspace supports the custom MCP app. Scheduled publishing is an additional use case where scheduled workflows can access the app. Availability depends on the ChatGPT plan and workspace configuration; see OpenAI's documentation for Scheduled Tasks and Workspace Agents.

Authentication

  1. ChatGPT discovers the protected-resource and authorization-server metadata.
  2. It registers with DCR or uses CIMD and starts an authorization-code flow with PKCE S256.
  3. The Worker displays a consent page and redirects to GitHub.
  4. Only users in ALLOWED_GITHUB_LOGINS are accepted.
  5. The Worker issues its own access and refresh tokens to ChatGPT.

The GitHub token is used only for the identity check and is not stored in MCP token properties.

Verify a deployment

curl https://chatgpt-tg-mcp.<subdomain>.workers.dev/health
curl -i https://chatgpt-tg-mcp.<subdomain>.workers.dev/mcp
curl https://chatgpt-tg-mcp.<subdomain>.workers.dev/.well-known/oauth-protected-resource/mcp
curl https://chatgpt-tg-mcp.<subdomain>.workers.dev/.well-known/oauth-authorization-server

Expected results:

  • /health returns {"ok":true,"service":"chatgpt-to-telegram-mcp","authentication":"oauth"}.
  • /mcp returns 401 without a token and includes a WWW-Authenticate challenge.
  • Both /.well-known/ endpoints return OAuth metadata as JSON.

Local development

Create a separate GitHub OAuth App for local work with:

  • Homepage: http://localhost:8787
  • Callback: http://localhost:8787/callback

Then run:

npm run db:migrate:local
npm run dev

OAuth cookies are Secure, so the production workers.dev URL remains the most reliable way to test the complete browser flow.

Commands

Command Description
npm run dev Start the local Worker.
npm test Run the Node.js test suite.
npm run check Check JavaScript syntax.
npm run db:migrate:local Apply D1 migrations locally through the DB binding.
npm run db:migrate:remote Apply D1 migrations to the configured remote database.
npm run deploy Deploy the Worker.
npm run secrets:push Upload all .env values as Worker secrets.

Security

  • Telegram destination selection remains server-side; the model cannot choose a different channel.
  • GitHub login matching is case-insensitive and denies every account outside the allowlist.
  • Access tokens expire after one hour, refresh tokens after 30 days, and dynamic client registrations after 90 days.
  • Plain PKCE and the OAuth implicit flow are disabled.
  • OAuth state and CSRF values are one-time and expire after ten minutes.
  • The Telegram bot token, GitHub secret, account IDs, and live Wrangler configuration are excluded from Git.
  • Telegram is called only after D1 successfully reserves the content fingerprint and source URLs.

Limitations

  • Telegram bots cannot read arbitrary historical channel messages. get_previous_messages returns only posts recorded by this Worker.
  • Deduplication covers the previous 48 hours, not the entire lifetime of the channel.
  • Semantic duplicate detection is performed by ChatGPT using the returned history; the server enforces exact normalized-text and canonical-URL matches.
  • Scheduled execution is provided by the ChatGPT workflow using this MCP server, not by a Cloudflare cron trigger.

License

Released under the MIT License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选