Twitter/X MCP server powered by twikit — no API key needed, free forever
Project description
twikit-mcp
Twitter/X MCP Server — No API Key Required
An MCP server that lets Claude interact with Twitter/X using browser cookies. No Twitter API key needed. Free forever.
English
Why twikit-mcp?
| twikit-mcp (this project) | Other Twitter MCP servers | |
|---|---|---|
| Auth | Browser cookies | Twitter API Key |
| Cost | Free | $200+/month |
| Setup | 2 steps, 2 minutes | Apply for developer account, wait for approval |
| Library | twikit (reverse-engineered) | tweepy (official API) |
Quick Start
1. Create cookies.json
- Log in to x.com in your browser
- Open DevTools (F12) → Application → Cookies →
https://x.com - Copy
ct0andauth_token
mkdir -p ~/.config/twitter-mcp
cat > ~/.config/twitter-mcp/cookies.json << 'EOF'
{"ct0": "YOUR_CT0", "auth_token": "YOUR_AUTH_TOKEN"}
EOF
chmod 600 ~/.config/twitter-mcp/cookies.json
What are these?
ct0is the CSRF token (~160 hex chars),auth_tokenis your session token (40 hex chars). They are found in your browser cookies after logging in to x.com. Cookies expire —auth_tokentypically lasts several months,ct0may be shorter. Re-extract from your browser when expired.
2. Install & register
Choose one of the following methods:
Option A: uvx (recommended if you have uv)
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- uvx twikit-mcp
# Or run directly
uvx twikit-mcp
Option B: pip
pip install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
# Or run directly
TWITTER_COOKIES=~/.config/twitter-mcp/cookies.json twikit-mcp
Option C: pipx (isolated install)
pipx install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
Using with other MCP clients
This is a standard MCP server (stdio transport). It works with any MCP-compatible client — not just Claude Code.
Add to your MCP client config (e.g. mcp.json, settings.json):
{
"mcpServers": {
"twitter": {
"command": "twikit-mcp",
"env": {
"TWITTER_COOKIES": "/home/YOU/.config/twitter-mcp/cookies.json"
}
}
}
}
Works with: Claude Code, Claude Desktop, Cursor, Windsurf, opencode, Cline, etc.
That's it. Start talking:
> Search tweets about AI
> What did @elonmusk post recently?
> Send a tweet saying: Hello from Claude!
Available Tools
| Tool | Description |
|---|---|
send_tweet |
Post a tweet or reply |
get_tweet |
Fetch a tweet by ID or URL |
get_timeline |
Get home timeline |
search_tweets |
Search tweets (Latest/Top) |
like_tweet |
Like a tweet |
retweet |
Retweet a tweet |
get_user_info |
Get a user's profile metadata (id, name, bio, follower counts, ...) |
get_user_tweets |
Get tweets from a specific user |
follow_user |
Follow a user by screen name |
unfollow_user |
Unfollow a user by screen name |
get_article_preview |
Get title / preview / cover of an X Article embedded in a tweet (no auth) |
get_article |
Fetch an X Article's body — format="preview" | "plain" | "full" (default "plain") |
X Articles note: long-form posts at
https://x.com/i/article/<id>live in a different ID namespace than tweets.get_tweetrefuses them with a clear error pointing toget_article.get_article_previewworks without auth via the public syndication endpoint.get_articleruns a two-hop reader flow internally:ArticleRedirectScreenQueryresolves the article rest_id to the underlying tweet rest_id, thenTweetResultByRestIdfetches the tweet's article body. Theformatarg controls how much of the response makes it through to the LLM:
"preview"(~1 KB) —rest_id,title,preview_text,cover_image. Card-display use case."plain"(~20 KB, default) — addsplain_text, flatmediaURL list,lifecycle_state. The 80% LLM-reading-an-article case; fits inside Claude Code'sMAX_MCP_OUTPUT_TOKENS."full"(~150 KB+) — raw GraphQL payload including the heavycontent_stateblock tree. Only ask for this if you actually need rich-content rendering / archiving / structure analysis.Both queryIds are hardcoded like the 80+ other twikit endpoints; if X rotates them, refresh from the public
bundle.Articles.*.js/bundle.TwitterArticles.*.jschunks onabs.twimg.com(no auth needed for discovery).
Check version
twikit-mcp --version
# or: twikit-mcp -v
# or: python -m twitter_mcp.server --version
How It Works
You: "Search tweets about AI"
→ Claude Code (understands intent)
→ MCP Protocol (JSON-RPC over stdio)
→ twikit-mcp (this server)
→ twikit (browser-like requests)
→ Twitter GraphQL API
Claude Code automatically manages the server process — it starts when Claude Code launches and stops when it exits. No background services, no manual setup.
Windows
mkdir %APPDATA%\twitter-mcp
# Create cookies.json with your ct0 and auth_token
# uvx
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- uvx twikit-mcp
# Or with pip
pip install twikit-mcp
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- twikit-mcp
Documentation
- Technical Guide — Architecture, MCP internals, configuration details
- Contributing — Testing, CI/CD, how to add new tools
中文
为什么选 twikit-mcp?
| twikit-mcp(本项目) | 其他 Twitter MCP | |
|---|---|---|
| 认证 | 浏览器 Cookies | Twitter API Key |
| 费用 | 免费 | $200+/月 |
| 配置 | 2 步,2 分钟 | 申请开发者账号,等审批 |
| 底层 | twikit(逆向工程) | tweepy(官方 API) |
快速开始
1. 创建 cookies.json
- 用浏览器登录 x.com
- F12 打开 DevTools → Application → Cookies →
https://x.com - 复制
ct0和auth_token
mkdir -p ~/.config/twitter-mcp
cat > ~/.config/twitter-mcp/cookies.json << 'EOF'
{"ct0": "你的ct0", "auth_token": "你的auth_token"}
EOF
chmod 600 ~/.config/twitter-mcp/cookies.json
这两个值是什么?
ct0是 CSRF token(约160位十六进制),auth_token是会话 token(40位十六进制),都在浏览器 Cookies 中。Cookies 会过期——auth_token通常有效数月,ct0可能更短。过期后从浏览器重新提取即可。
2. 安装 & 注册
选择以下 任一 方式:
方式 A: uvx(推荐,需要安装 uv)
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- uvx twikit-mcp
# 或直接运行
uvx twikit-mcp
方式 B: pip
pip install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
# 或直接运行
TWITTER_COOKIES=~/.config/twitter-mcp/cookies.json twikit-mcp
方式 C: pipx(隔离安装)
pipx install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
在其他 MCP 客户端中使用
这是标准的 MCP server(stdio 传输),不限于 Claude Code,任何支持 MCP 的客户端都能用。
在你的 MCP 客户端配置中添加(如 mcp.json、settings.json):
{
"mcpServers": {
"twitter": {
"command": "twikit-mcp",
"env": {
"TWITTER_COOKIES": "/home/你的用户名/.config/twitter-mcp/cookies.json"
}
}
}
}
兼容:Claude Code、Claude Desktop、Cursor、Windsurf、opencode、Cline 等。
搞定。直接说人话:
> 搜一下关于 AI 的推文
> 看看 @elonmusk 最近发了什么
> 发一条推说:Hello from Claude!
可用工具
| 工具 | 功能 | 怎么用 |
|---|---|---|
send_tweet |
发推/回复 | "发一条推说..." |
get_tweet |
获取推文 | "看看这条推文 [链接]" |
get_timeline |
刷时间线 | "看看我的时间线" |
search_tweets |
搜索推文 | "搜一下关于 XX 的推文" |
like_tweet |
点赞 | "点赞这条推" |
retweet |
转推 | "转推这个" |
get_user_info |
查看用户资料(id、名字、简介、粉丝数等) | "查一下 @xxx 的资料" |
get_user_tweets |
看某人的推 | "看看 @xxx 最近发了什么" |
follow_user |
关注用户 | "关注 @xxx" |
unfollow_user |
取消关注 | "取关 @xxx" |
get_article_preview |
拿 X Article 的标题/摘要/封面(无需登录) | "这篇文章在讲什么 [链接]" |
get_article |
拿 X Article 的正文,format="preview" | "plain" | "full"(默认 "plain") |
"把这篇文章读给我听 [链接]" |
X Articles 说明:
https://x.com/i/article/<id>这种长文与普通推文是两个 ID 命名空间。get_tweet遇到 article URL 会直接拒绝并提示用get_article。get_article_preview走公共 syndication 端点,不需要登录。get_article内部是两跳 reader 流程,通过format参数控制返回大小:
"preview"(~1 KB) —rest_id/title/preview_text/cover_image,卡片场景"plain"(~20 KB,默认) — 上面 +plain_text+ 扁平化mediaURL 列表 +lifecycle_state,LLM 读全文的 80% 场景,刚好放得下 Claude Code 的MAX_MCP_OUTPUT_TOKENS"full"(~150 KB+) — 原始 GraphQL 响应,含庞大的content_state富文本块树,只在做富文本渲染/归档/结构分析时才需要两个 queryId 都跟其他 80+ 端点一样硬编码 — 如果 X 改了 hash,从公开的
bundle.Articles.*.js/bundle.TwitterArticles.*.jschunk 里 grep 出新值即可,无需登录态。
查看版本
twikit-mcp --version
# 或:twikit-mcp -v
# 或:python -m twitter_mcp.server --version
工作原理
你:"搜一下关于 AI 的推文"
→ Claude Code(理解意图)
→ MCP 协议(JSON-RPC,stdio 通信)
→ twikit-mcp(本 server)
→ twikit(模拟浏览器请求)
→ Twitter GraphQL API
Claude Code 自动管理 server 进程——启动时拉起,退出时关闭。不需要手动运行任何东西,不占后台资源。
Windows
mkdir %APPDATA%\twitter-mcp
# 创建 cookies.json,写入 ct0 和 auth_token
# uvx
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- uvx twikit-mcp
# 或使用 pip
pip install twikit-mcp
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- twikit-mcp
文档
日本語
なぜ twikit-mcp?
| twikit-mcp(本プロジェクト) | 他の Twitter MCP | |
|---|---|---|
| 認証 | ブラウザ Cookie | Twitter API Key |
| 料金 | 無料 | $200+/月 |
| セットアップ | 2ステップ、2分 | 開発者アカウント申請、承認待ち |
| ライブラリ | twikit(リバースエンジニアリング) | tweepy(公式 API) |
クイックスタート
1. cookies.json の作成
- ブラウザで x.com にログイン
- F12 で DevTools を開く → Application → Cookies →
https://x.com ct0とauth_tokenをコピー
mkdir -p ~/.config/twitter-mcp
cat > ~/.config/twitter-mcp/cookies.json << 'EOF'
{"ct0": "あなたのct0", "auth_token": "あなたのauth_token"}
EOF
chmod 600 ~/.config/twitter-mcp/cookies.json
これは何?
ct0は CSRF トークン(約160桁の16進数)、auth_tokenはセッショントークン(40桁の16進数)で、ブラウザの Cookie から取得します。Cookie は有効期限があります —auth_tokenは通常数ヶ月、ct0はより短い場合があります。期限切れの際はブラウザから再取得してください。
2. インストール & 登録
以下の いずれか の方法を選んでください:
方法 A: uvx(推奨、uv が必要)
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- uvx twikit-mcp
# または直接実行
uvx twikit-mcp
方法 B: pip
pip install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
# または直接実行
TWITTER_COOKIES=~/.config/twitter-mcp/cookies.json twikit-mcp
方法 C: pipx(隔離インストール)
pipx install twikit-mcp
# Claude Code
claude mcp add twitter -s user \
-e "TWITTER_COOKIES=$HOME/.config/twitter-mcp/cookies.json" \
-- twikit-mcp
他の MCP クライアントでの使用
これは標準的な MCP サーバー(stdio トランスポート)です。Claude Code 専用ではなく、MCP 対応のすべてのクライアントで使用できます。
MCP クライアントの設定ファイル(mcp.json、settings.json など)に追加:
{
"mcpServers": {
"twitter": {
"command": "twikit-mcp",
"env": {
"TWITTER_COOKIES": "/home/ユーザー名/.config/twitter-mcp/cookies.json"
}
}
}
}
対応クライアント:Claude Code、Claude Desktop、Cursor、Windsurf、opencode、Cline など。
以上です。自然言語で話しかけてください:
> AIに関するツイートを検索して
> @elonmusk の最近の投稿を見せて
> 「Hello from Claude!」とツイートして
利用可能なツール
| ツール | 機能 | 使い方 |
|---|---|---|
send_tweet |
ツイート投稿・返信 | 「〜とツイートして」 |
get_tweet |
ツイート取得 | 「このツイートを見て [URL]」 |
get_timeline |
タイムライン取得 | 「タイムラインを見せて」 |
search_tweets |
ツイート検索 | 「〜について検索して」 |
like_tweet |
いいね | 「このツイートにいいねして」 |
retweet |
リツイート | 「これをリツイートして」 |
get_user_info |
ユーザープロフィール取得(id・名前・bio・フォロワー数など) | 「@xxx のプロフィールを見せて」 |
get_user_tweets |
ユーザーのツイート取得 | 「@xxx の最近の投稿を見せて」 |
follow_user |
ユーザーをフォロー | 「@xxx をフォロー」 |
unfollow_user |
フォロー解除 | 「@xxx をフォロー解除」 |
get_article_preview |
X Article のタイトル/プレビュー/カバー画像取得(認証不要) | 「この記事の概要を教えて [URL]」 |
get_article |
X Article の本文取得、format="preview" | "plain" | "full"(デフォルト "plain") |
「この記事を読んで [URL]」 |
X Articles について:
https://x.com/i/article/<id>の長文記事はツイートとは別の ID 名前空間に属します。get_tweetは article URL を渡されると拒否し、get_articleを案内します。get_article_previewは公開 syndication エンドポイント経由で認証不要。get_articleは内部で 2 ホップ reader フローを走り、format引数で出力サイズを制御:
"preview"(~1 KB) —rest_id/title/preview_text/cover_image、カード表示用途"plain"(~20 KB、デフォルト) — 上記 +plain_text+ フラットなmediaURL リスト +lifecycle_state、LLM が記事を読む 80% のケース、Claude Code のMAX_MCP_OUTPUT_TOKENSに収まる"full"(~150 KB+) — 重いcontent_stateブロックツリーを含む生 GraphQL レスポンス、リッチコンテンツのレンダリング・アーカイブ・構造解析が必要な場合のみどちらの queryId も他の 80+ エンドポイント同様ハードコードされており、X がハッシュをローテートした場合は公開されている
bundle.Articles.*.js/bundle.TwitterArticles.*.jsチャンクから新しいハッシュを取得できます(認証不要)。
バージョン確認
twikit-mcp --version
# または: twikit-mcp -v
# または: python -m twitter_mcp.server --version
仕組み
あなた:「AIに関するツイートを検索して」
→ Claude Code(意図を理解)
→ MCP プロトコル(JSON-RPC、stdio 通信)
→ twikit-mcp(本サーバー)
→ twikit(ブラウザリクエストをシミュレート)
→ Twitter GraphQL API
Claude Code がサーバープロセスを自動管理します。起動時にプロセスを立ち上げ、終了時に自動停止。手動操作やバックグラウンドサービスは不要です。
Windows
mkdir %APPDATA%\twitter-mcp
# cookies.json を作成し、ct0 と auth_token を記入
# uvx
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- uvx twikit-mcp
# または pip
pip install twikit-mcp
claude mcp add twitter -s user ^
-e "TWITTER_COOKIES=%APPDATA%\twitter-mcp\cookies.json" ^
-- twikit-mcp
ドキュメント
- 技術ドキュメント — アーキテクチャ、MCP の仕組み、設定詳細
- コントリビューションガイド — テスト、CI/CD、新しいツールの追加方法
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twikit_mcp-0.1.14.tar.gz.
File metadata
- Download URL: twikit_mcp-0.1.14.tar.gz
- Upload date:
- Size: 214.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a03b865a63220720c1e78f7b1ffad0c163be9c2a5ae0817965187f3ae2806e8a
|
|
| MD5 |
9dd4b5e66c2898e385c2377a21e0c518
|
|
| BLAKE2b-256 |
9c9f7d5e22d78bee3a7ff1ab41abd62e340513e12cfc614f9a89b5ee7012f5b7
|
Provenance
The following attestation bundles were made for twikit_mcp-0.1.14.tar.gz:
Publisher:
publish.yml on tangivis/twitter-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twikit_mcp-0.1.14.tar.gz -
Subject digest:
a03b865a63220720c1e78f7b1ffad0c163be9c2a5ae0817965187f3ae2806e8a - Sigstore transparency entry: 1434188148
- Sigstore integration time:
-
Permalink:
tangivis/twitter-mcp@b18f86e930049f87eb490bfedd2ca509e0426458 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tangivis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b18f86e930049f87eb490bfedd2ca509e0426458 -
Trigger Event:
push
-
Statement type:
File details
Details for the file twikit_mcp-0.1.14-py3-none-any.whl.
File metadata
- Download URL: twikit_mcp-0.1.14-py3-none-any.whl
- Upload date:
- Size: 95.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a0e530e42a6525cf3469c2d3cad7d5cc4e568106fbfa072d7a76e665e494bf4
|
|
| MD5 |
1cc63ee3c198463d463ea9765dc1bce6
|
|
| BLAKE2b-256 |
a5a4aa02bca3d92d65088d30c20a967e1757fa8a848b1aaed0626d6248ef75c7
|
Provenance
The following attestation bundles were made for twikit_mcp-0.1.14-py3-none-any.whl:
Publisher:
publish.yml on tangivis/twitter-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twikit_mcp-0.1.14-py3-none-any.whl -
Subject digest:
6a0e530e42a6525cf3469c2d3cad7d5cc4e568106fbfa072d7a76e665e494bf4 - Sigstore transparency entry: 1434188270
- Sigstore integration time:
-
Permalink:
tangivis/twitter-mcp@b18f86e930049f87eb490bfedd2ca509e0426458 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tangivis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b18f86e930049f87eb490bfedd2ca509e0426458 -
Trigger Event:
push
-
Statement type: