Twitter Bridge MCP

Twitter Bridge MCP

Enables Claude.ai to interact with Twitter/X by using browser automation to perform actions like posting, replying, and searching through a logged-in Chrome session. It provides a cost-effective alternative to the official API by bridging the Model Context Protocol with a real browser instance.

Category
访问服务器

README

Twitter Bridge MCP

Connect Claude.ai to Twitter/X — without paying $100/month for the official API.

Uses bb-browser (open-source browser automation) to control a logged-in Chrome session, wrapped as an MCP server that Claude.ai can talk to.

Claude.ai ──MCP──▶ your-server:8080 ──bb-browser──▶ Chrome (logged in) ──▶ Twitter/X

Cost: ~$5/year (just a domain for Cloudflare Tunnel).

What it can do

Tool Method Status
twitter_post Browser automation
twitter_reply Browser automation
twitter_like GraphQL API
twitter_retweet GraphQL API
twitter_quote Browser automation
twitter_follow Browser automation
twitter_unfollow Browser automation
twitter_undo GraphQL API
twitter_search Browser DOM parsing
twitter_timeline Browser DOM parsing
twitter_bookmarks Browser DOM parsing
twitter_tweets Browser DOM parsing
twitter_notifications bb-sites adapter
twitter_user bb-sites adapter
twitter_view_tweet Browser DOM parsing
twitter_dm_read Browser automation ⚠️ partial
twitter_screenshot bb-browser
browser_open bb-browser
browser_snapshot bb-browser

DM reading works but Twitter's E2E encryption may limit what's visible via browser automation.

Architecture

The server has three layers:

  1. MCP + OAuth — Claude.ai connects via Streamable HTTP transport with auto-approved OAuth 2.0 (PKCE).
  2. Tool implementations — 19 tools split between browser automation (open page → wait → parse DOM) and GraphQL API calls (for lightweight actions like like/retweet/undo).
  3. bb-browser — Controls Chrome via CDP (Chrome DevTools Protocol), inheriting the logged-in session.

Browser automation was chosen over GraphQL API for most read operations because Twitter's API requires a x-client-transaction-id header generated from webpack internals — the module IDs change on every Twitter deploy, causing random 404s. DOM parsing is slower but never breaks.

Prerequisites

  • Node.js ≥ 18
  • Chrome (or Chromium) with remote debugging enabled
  • bb-browser — Install from GitHub
  • A Twitter/X account — logged in within the Chrome profile
  • Cloudflare Tunnel (or any reverse proxy) — to expose your local server with HTTPS

Setup

1. Start Chrome with CDP

# Create a dedicated Chrome profile
mkdir -p ~/chrome-mcp-profile

# Launch Chrome with remote debugging
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
  --remote-debugging-port=9222 \
  --user-data-dir=$HOME/chrome-mcp-profile

Log in to Twitter/X in this Chrome window.

2. Install & configure

git clone https://github.com/replica882/twitter-bridge-mcp.git
cd twitter-bridge-mcp
npm install

cp .env.example .env
# Edit .env with your values

3. Run

node server.mjs
# Twitter MCP Bridge v0.6.0: http://0.0.0.0:8080/mcp

4. Expose via Cloudflare Tunnel

cloudflared tunnel --url http://localhost:8080

Or set up a named tunnel for a permanent URL.

5. Connect from Claude.ai

In Claude.ai → Settings → Connected Tools → Add Custom Connector:

  • URL: https://your-tunnel-domain.com/mcp

Claude will auto-discover OAuth endpoints and connect.

Configuration

All config is via environment variables (or .env file):

Variable Default Description
PORT 8080 Server port
CDP_PORT 9222 Chrome DevTools Protocol port
BASE_URL http://localhost:8080 Public URL (for OAuth discovery)
BB_BROWSER_PATH ~/local/bin/bb-browser Path to bb-browser binary
DM_PIN (empty) Twitter DM encryption PIN (if set up)
OAUTH_CLIENT_ID twitter-mcp-client OAuth client ID
OAUTH_CLIENT_SECRET (auto-generated) OAuth client secret

How it works

Why not the official API?

Twitter/X API Basic tier costs $100/month. This project does the same thing for $5/year by automating a real browser session.

Why not just GraphQL?

Twitter's internal GraphQL API requires a x-client-transaction-id header. This ID is generated by a function buried in Twitter's webpack bundles — the module number changes every time Twitter deploys. We use GraphQL only for simple mutations (like, retweet, delete) that don't need this header. Everything else uses DOM parsing.

Tab management

Every browser operation opens a new tab. Without cleanup, Chrome accumulates 40+ tabs and crashes. The server auto-closes excess tabs, keeping a maximum of 10.

DM PIN auto-entry

Twitter requires a PIN every time you open the DM page (E2E encryption). If DM_PIN is set, the server auto-enters it using React-compatible input simulation (native property setter + keyboard events).

Gotchas

  • Chrome profile encryption — Cookie storage is bound to a profile key. You can't copy a Chrome profile directory to migrate login state. Always use --user-data-dir and log in manually.
  • React contenteditable — Twitter's compose box is a contenteditable div. Normal DOM manipulation doesn't trigger React state updates. The server uses ClipboardEvent paste for quote tweets and bb-browser's type command for regular posts.
  • Search occasionally empty — If you search too quickly after page load, DOM might not be populated yet. The server waits 4 seconds, which works reliably.
  • launchd/systemd and dotenv — If you run the server as a system service, make sure to set WorkingDirectory to the project directory. Without this, dotenv can't find .env, BASE_URL falls back to http://localhost:8080, and OAuth discovery returns localhost URLs — Claude.ai will fail to connect. For macOS launchd, add <key>WorkingDirectory</key><string>/path/to/twitter-bridge-mcp</string> to your plist. For systemd, add WorkingDirectory=/path/to/twitter-bridge-mcp to your unit file.
  • Server restart loses OAuth tokens — OAuth tokens are stored in memory. Every server restart requires reconnecting from Claude.ai (Settings → Connected Tools → reconnect Twitter Bridge).

Credits

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选