Skip to main content

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

CI PyPI Python License: MIT

An MCP server that lets Claude interact with Twitter/X using browser cookies. No Twitter API key needed. Free forever.

English | 中文 | 日本語


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

  1. Log in to x.com in your browser
  2. Open DevTools (F12) → ApplicationCookieshttps://x.com
  3. Copy ct0 and auth_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? ct0 is the CSRF token (~160 hex chars), auth_token is your session token (40 hex chars). They are found in your browser cookies after logging in to x.com. Cookies expire — auth_token typically lasts several months, ct0 may 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_tweets Get tweets from a specific user

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


中文

为什么选 twikit-mcp?

twikit-mcp(本项目) 其他 Twitter MCP
认证 浏览器 Cookies Twitter API Key
费用 免费 $200+/月
配置 2 步,2 分钟 申请开发者账号,等审批
底层 twikit(逆向工程) tweepy(官方 API)

快速开始

1. 创建 cookies.json

  1. 用浏览器登录 x.com
  2. F12 打开 DevTools → ApplicationCookieshttps://x.com
  3. 复制 ct0auth_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.jsonsettings.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_tweets 看某人的推 "看看 @xxx 最近发了什么"

工作原理

你:"搜一下关于 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

文档

  • 技术文档 — 架构、MCP 原理、配置详解、跨机器部署
  • 贡献指南 — 测试、CI/CD、如何添加新工具

日本語

なぜ twikit-mcp?

twikit-mcp(本プロジェクト) 他の Twitter MCP
認証 ブラウザ Cookie Twitter API Key
料金 無料 $200+/月
セットアップ 2ステップ、2分 開発者アカウント申請、承認待ち
ライブラリ twikit(リバースエンジニアリング) tweepy(公式 API)

クイックスタート

1. cookies.json の作成

  1. ブラウザで x.com にログイン
  2. F12 で DevTools を開く → ApplicationCookieshttps://x.com
  3. ct0auth_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.jsonsettings.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_tweets ユーザーのツイート取得 「@xxx の最近の投稿を見せて」

仕組み

あなた:「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

ドキュメント


License

MIT

Built with twikit and MCP

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twikit_mcp-0.1.2.tar.gz (130.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twikit_mcp-0.1.2-py3-none-any.whl (90.4 kB view details)

Uploaded Python 3

File details

Details for the file twikit_mcp-0.1.2.tar.gz.

File metadata

  • Download URL: twikit_mcp-0.1.2.tar.gz
  • Upload date:
  • Size: 130.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for twikit_mcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f7f5c9f16f38ce0ea445c538b065a25f4f114cf29a2f1fb0aac74c0116779254
MD5 c1c676020c8495b7304f7872fc62ad4d
BLAKE2b-256 f138eed730a64bdcefc9df6569a741d4309c70a4dc5799e3c7fb7d1fed540a25

See more details on using hashes here.

Provenance

The following attestation bundles were made for twikit_mcp-0.1.2.tar.gz:

Publisher: publish.yml on tangivis/twitter-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twikit_mcp-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: twikit_mcp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 90.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for twikit_mcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 06abfc8afc9e795245e1438f3969e6394df1dc42a8362f14ca12c50032455680
MD5 c9b51c28c08fd00dde61b341741ba358
BLAKE2b-256 478fbf70a3e22f5982b6fa40018acb0cb552fc5025bd2b2576bf524d80415f34

See more details on using hashes here.

Provenance

The following attestation bundles were made for twikit_mcp-0.1.2-py3-none-any.whl:

Publisher: publish.yml on tangivis/twitter-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page