twitter-mcp

twitter-mcp

A lightweight Twitter MCP server for Claude Code with 17 tools for reading and writing tweets, including search, user profiles, and media uploads, using a hybrid API approach.

Category
访问服务器

README

twitter-mcp

A lightweight Twitter MCP server for Claude Code. Zero compilation — edit and run instantly with Bun.

Architecture

┌──────────────────────────────────────────────────────────────┐
│                       twitter-mcp v1.1                       │
│                        (MCP Server)                          │
├──────────────────────────────────────────────────────────────┤
│                    17 Tools + Media Upload                   │
│  ┌──────────────┐ ┌──────────────┐ ┌──────────────────────┐ │
│  │ search_tweets│ │ get_tweet    │ │ get_user             │ │
│  │ search_users │ │ get_article  │ │ get_user_timeline    │ │
│  │              │ │ get_replies  │ │ get_user_followers   │ │
│  │              │ │ get_quotes   │ │ get_user_following   │ │
│  │              │ │ get_thread   │ │ get_user_mentions    │ │
│  │              │ │ get_trends   │ │                      │ │
│  └──────┬───────┘ └──────┬──────┘ └──────┬───────────────┘ │
│         └────────────────┼───────────────┘                  │
│                          │                                  │
│                    API Router                                │
│         ┌────────────────┼─────────────────┐                │
│         ▼                ▼                  ▼               │
│  ┌─────────────┐  ┌─────────────┐  ┌──────────────┐        │
│  │twitterapi.io│  │Official API │  │Cookie Client │        │
│  │ (API Key)   │  │(OAuth 1.0a) │  │(ct0+auth)    │        │
│  │             │  │             │  │              │        │
│  │ 13 read     │  │ post_tweet  │  │ reply        │        │
│  │ tools       │  │ like/unlike │  │ fallback     │        │
│  │             │  │ retweet     │  │ (auto on 403)│        │
│  │             │  │ delete      │  │              │        │
│  │             │  │ media upload│  │              │        │
│  └─────────────┘  └─────────────┘  └──────────────┘        │
└──────────────────────────────────────────────────────────────┘

Why Hybrid API?

API Auth Cost Use Case
twitterapi.io API Key ~$0.15/1K calls Read operations (search, timeline, user info)
Official Twitter API OAuth 1.0a Free tier Write operations (post, like, retweet, delete)
Cookie (browser session) ct0 + auth_token Free Reply fallback (Free tier OAuth blocks replies to non-interacted tweets)

Setup

1. Install

git clone https://github.com/armatrix/twitter-mcp.git
cd twitter-mcp
bun install

2. Configure

mkdir -p ~/.twitter-mcp
cp config.example.json ~/.twitter-mcp/config.json

Edit ~/.twitter-mcp/config.json:

{
  "reader": {
    "provider": "twitterapi.io",
    "api_key": "your-twitterapi-io-key"
  },
  "writer": {
    "provider": "twitter-official",
    "api_key": "your-consumer-api-key",
    "api_secret_key": "your-consumer-api-secret",
    "access_token": "your-access-token",
    "access_token_secret": "your-access-token-secret"
  },
  "cookie": {
    "ct0": "your-ct0-cookie",
    "auth_token": "your-auth-token-cookie"
  },
  "defaults": {
    "timeline_count": 20,
    "search_count": 20
  }
}

Get credentials:

  • reader.api_key: twitterapi.io — sign up and copy API key
  • writer.*: Twitter Developer Portal → Create App → Keys and Tokens
  • cookie.*: Browser DevTools → Application → Cookies → x.com → copy ct0 and auth_token values

Cookie section is optional. If omitted, reply fallback is disabled and OAuth 403 errors on replies are returned as-is.

3. Get Cookie Credentials

  1. Open x.com in your browser and log in
  2. Open DevTools (F12) → Application → Cookies → https://x.com
  3. Copy the value of ct0 (CSRF token, rotates periodically)
  4. Copy the value of auth_token (session token, long-lived)
  5. Paste both into config.json under the cookie section

Note: ct0 rotates every few hours. When cookie auth starts failing, refresh it from the browser.

4. Add to Claude Code

claude mcp add twitter -- bun run /path/to/twitter-mcp/src/index.ts -config ~/.twitter-mcp/config.json

Verify:

claude mcp list

Tools

Read (13 tools — twitterapi.io)

Tool Description
search_tweets Search tweets by keyword (advanced search syntax)
search_users Search users by keyword
get_tweet Get tweets by ID (supports comma-separated multiple IDs, includes viewCount)
get_article Get X Article full content by tweet ID
get_tweet_replies Get replies to a tweet
get_tweet_quotes Get quote tweets
get_tweet_thread Get full thread context
get_user Get user profile by username
get_user_timeline Get user's recent tweets
get_user_followers Get user's followers
get_user_following Get accounts a user follows
get_user_mentions Get tweets mentioning a user
get_trends Get trending topics by region (WOEID)

Write (4 tools — Official Twitter API, OAuth 1.0a)

Tool Description
post_tweet Post a tweet with optional images, reply, quote-tweet. Auto-fallback to cookie auth on reply 403.
like_tweet Like a tweet by ID
unlike_tweet Remove a like from a tweet
retweet Retweet a tweet by ID
delete_tweet Delete a tweet by ID

Reply Fallback Flow

post_tweet(text, reply_to_tweet_id)
  │
  ▼
OAuth 1.0a POST /2/tweets
  │
  ├─ 200 OK → return result (method: "oauth")
  │
  └─ 403 Forbidden (Free tier reply restriction)
       │
       ▼
     Cookie client configured?
       │
       ├─ Yes → GraphQL CreateTweet → return result (method: "cookie")
       │
       └─ No → return error

Image upload: Pass media_paths with up to 4 local file paths (png/jpg/gif/webp). Images are uploaded via Twitter v1.1 media endpoint, then attached to the tweet.

post_tweet(
  text: "Hello world",
  media_paths: ["/path/to/screenshot.png", "/path/to/chart.jpg"]
)

Known Limitations

Issue Workaround
Official API Free tier blocks replies to non-interacted tweets (403) Cookie fallback auto-handles this
ct0 cookie rotates every few hours Re-extract from browser when cookie auth fails
get_user_timeline / get_tweet via twitterapi.io don't return views/impressions Use get_tweet (which goes through twitterapi.io) — it returns viewCount
Cookie client doesn't support image upload Images only via OAuth post_tweet (no fallback for image+reply combo)

Development

No build step required. Edit any .ts file and restart the MCP server.

# Run directly
bun run src/index.ts -config ~/.twitter-mcp/config.json

# Type check
bun build src/index.ts --target=bun

Project Structure

src/
├── index.ts              # MCP server entry point
├── config.ts             # Config types and loader
├── clients/
│   ├── reader.ts         # twitterapi.io client (read operations)
│   ├── writer.ts         # Official Twitter API client (OAuth 1.0a write)
│   └── cookie.ts         # Cookie-based client (GraphQL, reply fallback)
└── tools/
    ├── search.ts         # search_tweets, search_users
    ├── tweets.ts         # get_tweet, get_article, get_replies, get_quotes, get_thread
    ├── users.ts          # get_user, get_timeline, get_followers, get_following, get_mentions
    ├── discovery.ts      # get_trends
    └── write.ts          # post_tweet, like_tweet, unlike_tweet, retweet, delete_tweet

Tech Stack

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

官方
精选