CLI モード¶
twikit-mcp はマルチモードのバイナリです。同じインストールで、3 種類の使い方:
| モード | コマンド | 使う場面 |
|---|---|---|
| MCP サーバー(デフォルト) | twikit-mcp または twikit-mcp serve |
AI エージェント(Claude Code、Cursor、Cline など)、LLM が stdio 経由で JSON-RPC を送る |
| ヒューマン CLI | twikit-mcp tweet 20、twikit-mcp user elonmusk など |
シェルでツイート / プロフィール / タイムラインを直接読みたいとき。出力はプレーンテキスト、ネイティブ Unicode |
| マシン CLI | twikit-mcp list / twikit-mcp call <tool> key=value … |
シェルスクリプト、自動化、デバッグ。生 JSON 出力、57 ツール全部呼べる |
3 モードとも同じ cookies ファイル(~/.config/twitter-mcp/cookies.json)を共有します。
ヒューマン用サブコマンド¶
整形済みテキスト、位置引数、JSON なし。「X を読みたい」の典型ケースを 5 つカバー:
twikit-mcp tweet 20 # 1 ツイートを整形表示
twikit-mcp tweet https://x.com/jack/status/20 # URL も可
twikit-mcp user elonmusk # 1 プロフィール
twikit-mcp tl 10 # 自分のホームタイムライン直近 10 件
twikit-mcp search "AI" 5 # "AI" のトップ 5 検索結果
twikit-mcp trends 20 # トップ 20 トレンド
twikit-mcp video 1234567890 # 動画を ~/Downloads/twikit-mcp/ にダウンロード
twikit-mcp video <url> -o ~/Movies # 出力ディレクトリを指定
video サブコマンドは PATH に yt-dlp が必要:
ffmpeg は format=bestvideo+bestaudio のような複数ストリームのマージが必要な format を渡したときだけ必要です。デフォルトの best[ext=mp4] は X が直接配信する単一ファイル mp4(マージ済み)なので、ffmpeg なしで動作します。
ターミナルでの出力例(0.1.24+ Rich レンダリングのカード + クリック可能リンク):
╭──────────────────────────────────────────────────────────────────────────────╮
│ Pathfinder Sports · @pathfinderSport │
│ Sat Feb 21 16:55:22 +0000 2009 │
│ ──────────────────────────────────────────────────────────────────────────── │
│ Άρσεναλ - Σάντερλαντ: (X) 0-0 τελικό │
│ ──────────────────────────────────────────────────────────────────────────── │
│ ❤ 7,269 🔁 5,473 │
│ https://x.com/pathfinderSport/status/1234567890 │
╰──────────────────────────────────────────────────────────────────────────────╯
実際のターミナルでは、作者名は太字シアン、タイムスタンプは薄色、❤ は赤、🔁 は緑、URL は OSC 8 エスケープで包まれます — iTerm2 / kitty / WezTerm / Windows Terminal / gnome-terminal ≥ 3.36 で cmd-クリックすればブラウザで開きます。emoji と CJK の行は列幅が正しい(Rich の cell-aware 計測でパディング — 0.1.23 にあった右ボーダーのずれは解消)。
幅はターミナルの列数に合わせて [60, 100] にクランプされます。ファイルやパイプにリダイレクト、または NO_COLOR=1 を設定するとバイト安定なプレーンテキストへ自動フォールバック — 形は 0.1.22 と同じで、jq / grep / diff にそのまま使えます:
@pathfinderSport · Pathfinder Sports
Άρσεναλ - Σάντερλαντ: (X) 0-0 τελικό
❤ 7,269 🔁 5,473 · Sat Feb 21 16:55:22 +0000 2009
https://x.com/pathfinderSport/status/1234567890
これらは同じ MCP ツール群の薄いラッパーです。より細かな引数(product=Latest / カスタム cursor など)が必要なら call を使ってください。
マシン用サブコマンド¶
serve(デフォルト)¶
MCP サーバーを stdio で起動。サブコマンドなしのデフォルト動作 — 既存の mcp.json / Claude Code / Cursor 設定はそのまま動きます。
list¶
登録されたツール名を一行ずつソートして出力。
call <tool> [key=value …]¶
ツールを 1 回呼び出し、JSON 出力をプリント。
$ twikit-mcp call get_user_info screen_name=elonmusk
{"id":"44196397","screen_name":"elonmusk", …}
$ twikit-mcp call search_tweets query=AI count=5 product=Top
[…]
$ twikit-mcp call get_tweet tweet_id=20 | jq .text
"just setting up my twttr"
型変換¶
CLI 引数は文字列で渡されるので、ツールのアノテーションに合わせて変換:
| アノテーション | 変換 |
|---|---|
str |
そのまま |
int / float |
int(value) / float(value) |
bool |
緩い一致:true / 1 / yes / on(大文字小文字不問)→ True;それ以外 → False |
Optional[X] / X \| None |
X にアンラップ;空文字列 → None を明示的にエスケープ |
| その他 | 文字列のままパススルー |
KV 分割は最初の = のみ — URL / base64 / JWT に含まれる追加の = は保持されます。
終了コード¶
| Code | 意味 |
|---|---|
0 |
成功 |
1 |
argparse / 使用法エラー |
2 |
ToolError(引数バリデーション失敗 or twikit が型付き例外を投げた) |
| その他 | キャッチされなかった例外 — バグなので issue を立ててください |
Tips¶
# jq にパイプ
twikit-mcp call get_user_info screen_name=elonmusk | jq .followers_count
# cron で定期スナップショット
0 10 * * 1 /usr/local/bin/twikit-mcp call get_trends category=trending count=20 \
> "$HOME/trends/$(date +%F).json"
# 未知の引数エラーで有効な args を発見
$ twikit-mcp call get_user_info bogus=x
Unknown arg `bogus` for tool `get_user_info`. Valid args: ['screen_name', 'user_id']
すべてのツール(マシン CLI)¶
すべての登録済み MCP ツール、マシンモード CLI で呼び出せます(twikit-mcp call <tool> key=value …)。自動生成、ドリフトしません。完全な引数シグネチャと戻り値の形は MCP ツール API リファレンス を参照。
ツイート (Tweets)¶
全 15 ツール:
bookmark_tweet¶
Bookmark a tweet. Optionally add it to a bookmark folder.
delete_bookmark¶
Remove a tweet from bookmarks.
delete_retweet¶
Un-retweet a tweet by ID.
delete_tweet¶
Delete a tweet by ID.
get_bookmarks¶
Get bookmarked tweets (paginated).
get_favoriters¶
Get users who liked a tweet (paginated).
get_retweeters¶
Get users who retweeted a tweet (paginated).
get_timeline¶
Fetch home timeline tweets.
get_tweet¶
Fetch a tweet by ID.
get_tweet_replies¶
Fetch replies (comments) to a tweet (issue #94).
like_tweet¶
Like a tweet by ID.
retweet¶
Retweet a tweet by ID.
search_tweets¶
Search tweets.
send_tweet¶
Send a tweet. Optionally reply to a tweet by ID.
unfavorite_tweet¶
Unlike a tweet by ID.
ユーザー (Users)¶
全 11 ツール:
block_user¶
Block a user by screen name.
follow_user¶
Follow a user by screen name.
get_user_followers¶
Get a user's followers list.
get_user_following¶
Get accounts that a user follows (their following list).
get_user_info¶
Get a user's profile metadata by screen name OR numeric user ID.
get_user_tweets¶
Get recent tweets from a specific user.
mute_user¶
Mute a user by screen name.
search_user¶
Search for users by query (paginated).
unblock_user¶
Unblock a user by screen name.
unfollow_user¶
Unfollow a user by screen name.
unmute_user¶
Unmute a user by screen name.
リスト (Lists)¶
全 9 ツール:
add_list_member¶
Add a user to a Twitter List.
create_list¶
Create a new Twitter List.
edit_list¶
Edit a Twitter List's metadata.
get_list¶
Get a Twitter List by ID.
get_list_members¶
Get members of a Twitter List (paginated).
get_list_subscribers¶
Get subscribers of a Twitter List (paginated).
get_list_tweets¶
Get tweets from a Twitter List (paginated).
get_lists¶
Get the authenticated user's Twitter Lists (paginated).
remove_list_member¶
Remove a user from a Twitter List.
コミュニティ (Communities)¶
全 10 ツール:
get_communities_timeline¶
Get tweets from communities the authenticated user has joined (paginated).
get_community¶
Get a Twitter Community by ID.
get_community_members¶
Get members of a Twitter Community (paginated).
get_community_moderators¶
Get moderators of a Twitter Community (paginated).
get_community_tweets¶
Get tweets from a Twitter Community (paginated).
join_community¶
Join a Twitter Community.
leave_community¶
Leave a Twitter Community.
request_to_join_community¶
Request to join a Twitter Community.
search_community¶
Search for Twitter Communities by query (paginated).
search_community_tweet¶
Search tweets within a Twitter Community (paginated).
記事 (Articles)¶
全 2 ツール:
get_article¶
Fetch an X Article (long-form post) by rest_id or URL.
get_article_preview¶
Get title/preview/cover of an X Article embedded in a tweet.
DM¶
全 4 ツール:
delete_dm¶
Delete a direct message by ID.
get_dm_history¶
Get DM conversation history with a user.
send_dm¶
Send a direct message to a user by screen name.
send_dm_to_group¶
Send a direct message to a group conversation.
発見と通知¶
全 2 ツール:
get_notifications¶
Fetch notifications (paginated).
get_trends¶
Get trending topics by category.
予約投稿と投票¶
全 5 ツール:
create_poll¶
Create an X poll and return its card URI.
create_scheduled_tweet¶
Schedule a tweet to be posted at a future Unix timestamp.
delete_scheduled_tweet¶
Delete a scheduled tweet by its scheduled tweet ID.
get_scheduled_tweets¶
Return all scheduled tweets for the authenticated user.
vote¶
Vote on an X poll.
twikit-mcp call vote selected_choice=<selected_choice> card_uri=<card_uri> tweet_id=20 card_name=<card_name>
その他¶
全 1 ツール:
download_tweet_video¶
Download video(s) attached to a tweet via yt-dlp.