CLI mode¶
twikit-mcp is a multi-mode binary. Same install, three flavors:
| Mode | Command | When |
|---|---|---|
| MCP server (default) | twikit-mcp or twikit-mcp serve |
Inside an AI agent (Claude Code, Cursor, Cline, …). LLM sends JSON-RPC over stdio. |
| Human-friendly CLI | twikit-mcp tweet 20, twikit-mcp user elonmusk, etc. |
You're at a shell, you want to read a tweet / profile / timeline. Output is plain text, native unicode. |
| Machine CLI | twikit-mcp list / twikit-mcp call <tool> key=value … |
Shell scripts, automation, debugging. Raw JSON output, every one of the 57 tools available. |
All three share the same cookies file (~/.config/twitter-mcp/cookies.json).
Human-friendly subcommands¶
Pretty-printed text output, positional args, no JSON. Five subcommands cover the common "I want to read X" cases:
twikit-mcp tweet 20 # one tweet pretty-printed
twikit-mcp tweet https://x.com/jack/status/20 # URL works too
twikit-mcp user elonmusk # one profile
twikit-mcp tl 10 # last 10 from your home timeline
twikit-mcp search "AI" 5 # 5 top search results
twikit-mcp trends 20 # top 20 trending topics
twikit-mcp video 1234567890 # download video to ~/Downloads/twikit-mcp/
twikit-mcp video <url> -o ~/Movies # custom output dir
The video subcommand requires yt-dlp on PATH:
uv tool install yt-dlp # recommended (isolated)
# or: pipx install yt-dlp / pip install --user yt-dlp
ffmpeg is only needed if you pass a separate-stream format like format=bestvideo+bestaudio; the default best[ext=mp4] is single-file muxed mp4 from X and works without ffmpeg.
Sample output in a terminal (0.1.24+ Rich-rendered card with clickable links):
╭──────────────────────────────────────────────────────────────────────────────╮
│ Pathfinder Sports · @pathfinderSport │
│ Sat Feb 21 16:55:22 +0000 2009 │
│ ──────────────────────────────────────────────────────────────────────────── │
│ Άρσεναλ - Σάντερλαντ: (X) 0-0 τελικό │
│ ──────────────────────────────────────────────────────────────────────────── │
│ ❤ 7,269 🔁 5,473 │
│ https://x.com/pathfinderSport/status/1234567890 │
╰──────────────────────────────────────────────────────────────────────────────╯
In a real terminal: the author handle is bold cyan, the timestamp is dim, ❤ is red, 🔁 is green, and the URL is wrapped in an OSC 8 escape so cmd-clicking opens it in your browser (works in iTerm2, kitty, WezTerm, Windows Terminal, gnome-terminal ≥ 3.36). Emoji and CJK lines are width-correct — Rich's cell-aware measurement is used for padding, no border drift.
Width is clamped to your terminal columns (between 60 and 100). Piping to a file or another command, or setting NO_COLOR=1, auto-falls-back to byte-stable plain text — same shape as 0.1.22, safe for jq/grep/diffing:
@pathfinderSport · Pathfinder Sports
Άρσεναλ - Σάντερλαντ: (X) 0-0 τελικό
❤ 7,269 🔁 5,473 · Sat Feb 21 16:55:22 +0000 2009
https://x.com/pathfinderSport/status/1234567890
These are wrappers over the same MCP tools; if you need different args (product=Latest, custom cursor, etc.), drop down to call.
Machine subcommands¶
serve (default)¶
Run the MCP server over stdio. Default when no subcommand given — every existing mcp.json / Claude Code / Cursor config keeps working unchanged.
list¶
Print all registered tool names, sorted, one per line.
call <tool> [key=value …]¶
Invoke one tool, print its JSON output.
$ 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"
Type coercion¶
CLI args are strings; we cast to the tool's annotated types:
| Annotation | Coercion |
|---|---|
str |
passthrough |
int / float |
int(value) / float(value) |
bool |
loose: true / 1 / yes / on (case-insensitive) → True; else False |
Optional[X] / X \| None |
unwrap to X; empty string → None explicitly |
| anything else | passthrough as raw string |
KV split is on the first = only — URLs / base64 / JWTs with extra = survive.
Exit codes¶
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Argparse / usage error |
2 |
ToolError (validation rejected the input or twikit raised typed exception) |
| Other | Uncaught exception — bug, please file an issue |
Tips¶
# Pipe to jq
twikit-mcp call get_user_info screen_name=elonmusk | jq .followers_count
# Cron a snapshot
0 10 * * 1 /usr/local/bin/twikit-mcp call get_trends category=trending count=20 \
> "$HOME/trends/$(date +%F).json"
# Discover args via 'unknown arg' error
$ twikit-mcp call get_user_info bogus=x
Unknown arg `bogus` for tool `get_user_info`. Valid args: ['screen_name', 'user_id']
All tools (machine CLI)¶
All registered MCP tools, callable via the machine-mode CLI (twikit-mcp call <tool> key=value …). Auto-generated from the live tool registry — never drifts from code. For full argument signatures + return shapes, see the MCP Tools API reference.
Tweets¶
15 tool(s):
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 tool(s):
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 tool(s):
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 tool(s):
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 tool(s):
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.
Direct Messages¶
4 tool(s):
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.
Discovery & notifications¶
2 tool(s):
get_notifications¶
Fetch notifications (paginated).
get_trends¶
Get trending topics by category.
Scheduled tweets & polls¶
5 tool(s):
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>
Other¶
1 tool(s):
download_tweet_video¶
Download video(s) attached to a tweet via yt-dlp.