跳转至

MCP 工具 API 参考

在文档构建时,从 twitter_mcp.server 里的 @mcp.tool() 装饰函数自动生成。共 59 个工具。每个工具下面都同时给出 MCP 和 CLI 两种调用形式。

形式 何时用
MCP 在 AI agent(Claude Code、Cursor 等)里 — LLM 自己选工具并从你的 prompt 里填参数。
CLI shell 脚本、调试、自动化。twikit-mcp call <tool> key=value … — 参数名一样,类型从字符串转换。

工具的 docstring 是真理之源 — 如果下面某段看起来不对,改 twitter_mcp/server.py 里的 docstring,下一次构建就会同步过来。


推文 (Tweets)

bookmark_tweet

bookmark_tweet(tweet_id: str, folder_id: Union = None)

Bookmark a tweet. Optionally add it to a bookmark folder.

Args: tweet_id: The tweet ID to bookmark. folder_id: Optional bookmark folder ID.

CLI:

twikit-mcp call bookmark_tweet tweet_id=20 folder_id=<folder_id>

delete_bookmark

delete_bookmark(tweet_id: str)

Remove a tweet from bookmarks.

Args: tweet_id: The tweet ID to un-bookmark.

CLI:

twikit-mcp call delete_bookmark tweet_id=20

delete_retweet

delete_retweet(tweet_id: str)

Un-retweet a tweet by ID.

Args: tweet_id: The tweet ID to un-retweet.

CLI:

twikit-mcp call delete_retweet tweet_id=20

delete_tweet

delete_tweet(tweet_id: str)

Delete a tweet by ID.

Args: tweet_id: The tweet ID to delete.

CLI:

twikit-mcp call delete_tweet tweet_id=20

get_bookmarks

get_bookmarks(count: int = 20, cursor: Union = None)

Get bookmarked tweets (paginated).

Args: count: Number of bookmarks to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_bookmarks count=5 cursor=<cursor>

get_favoriters

get_favoriters(tweet_id: str, count: int = 40, cursor: Union = None)

Get users who liked a tweet (paginated).

Args: tweet_id: The tweet ID. count: Number of users to fetch (default 40, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_favoriters tweet_id=20 count=5

get_retweeters

get_retweeters(tweet_id: str, count: int = 40, cursor: Union = None)

Get users who retweeted a tweet (paginated).

Args: tweet_id: The tweet ID. count: Number of users to fetch (default 40, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_retweeters tweet_id=20 count=5

get_timeline

get_timeline(count: int = 20)

Fetch home timeline tweets.

Args: count: Number of tweets to fetch (default 20).

CLI:

twikit-mcp call get_timeline count=5

get_tweet

get_tweet(tweet_id: str)

Fetch a tweet by ID.

Args: tweet_id: The tweet ID (numeric string) or full URL.

CLI:

twikit-mcp call get_tweet tweet_id=20

get_tweet_replies

get_tweet_replies(tweet_id: str, cursor: Union = None)

Fetch replies (comments) to a tweet (issue #94).

Uses X's TweetDetail GraphQL endpoint via vendored twikit's Client.get_tweet_by_id, which populates tweet.replies as a paginated Result[Tweet]. One page per call; pass the returned next_cursor to fetch more.

Args: tweet_id: The tweet ID (numeric string) or full URL. cursor: Pagination cursor from a previous response's next_cursor; omit for the first page.

Returns: JSON with tweet_id, replies (compact list — id/author/text/ created_at/likes/retweets), next_cursor, count.

CLI:

twikit-mcp call get_tweet_replies tweet_id=20 cursor=<cursor>

like_tweet

like_tweet(tweet_id: str)

Like a tweet by ID.

Args: tweet_id: The tweet ID.

CLI:

twikit-mcp call like_tweet tweet_id=20

retweet

retweet(tweet_id: str)

Retweet a tweet by ID.

Args: tweet_id: The tweet ID.

CLI:

twikit-mcp call retweet tweet_id=20

search_tweets

search_tweets(query: str, count: int = 20, product: str = 'Latest')

Search tweets.

Args: query: Search query string. count: Number of results (default 20). product: "Latest" or "Top" (default "Latest").

CLI:

twikit-mcp call search_tweets query="AI" count=5

send_tweet

send_tweet(text: str, reply_to: Union = None)

Send a tweet. Optionally reply to a tweet by ID.

Args: text: Tweet content (max 280 chars). reply_to: Optional tweet ID to reply to.

CLI:

twikit-mcp call send_tweet text="hello world" reply_to=<reply_to>

unfavorite_tweet

unfavorite_tweet(tweet_id: str)

Unlike a tweet by ID.

Args: tweet_id: The tweet ID to unlike.

CLI:

twikit-mcp call unfavorite_tweet tweet_id=20

用户 (Users)

block_user

block_user(screen_name: str)

Block a user by screen name.

Note: X aggressively rate-limits / risk-scans block + mute. Avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call block_user screen_name=elonmusk

follow_user

follow_user(screen_name: str)

Follow a user by screen name.

Note: X aggressively rate-limits follow / unfollow — avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call follow_user screen_name=elonmusk

get_user_followers

get_user_followers(screen_name: Union = None, user_id: Union = None, count: int = 20, cursor: Union = None)

Get a user's followers list.

Note: X aggressively rate-limits follower / following requests — use sparingly, paginate via cursor, don't loop without backoff.

Caller must provide exactly one of screen_name / user_id.

Args: screen_name: Twitter username (without @). user_id: Twitter numeric user ID. count: Number of followers to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_user_followers screen_name=elonmusk user_id=<user_id>

get_user_following

get_user_following(screen_name: Union = None, user_id: Union = None, count: int = 20, cursor: Union = None)

Get accounts that a user follows (their following list).

Note: X aggressively rate-limits follower / following requests — use sparingly, paginate via cursor, don't loop without backoff.

Caller must provide exactly one of screen_name / user_id.

Args: screen_name: Twitter username (without @). user_id: Twitter numeric user ID. count: Number to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_user_following screen_name=elonmusk user_id=<user_id>

get_user_info

get_user_info(screen_name: Union = None, user_id: Union = None)

Get a user's profile metadata by screen name OR numeric user ID.

Caller must provide exactly one of screen_name / user_id.

Args: screen_name: Twitter username (without @). user_id: Twitter numeric user ID.

CLI:

twikit-mcp call get_user_info screen_name=elonmusk user_id=<user_id>

get_user_tweets

get_user_tweets(screen_name: str, count: int = 20)

Get recent tweets from a specific user.

Args: screen_name: Twitter username (without @). count: Number of tweets to fetch (default 20).

CLI:

twikit-mcp call get_user_tweets screen_name=elonmusk count=5

mute_user

mute_user(screen_name: str)

Mute a user by screen name.

Note: X aggressively rate-limits / risk-scans block + mute. Avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call mute_user screen_name=elonmusk

search_user

search_user(query: str, count: int = 20, cursor: Union = None)

Search for users by query (paginated).

Args: query: Search query string. count: Number of users to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call search_user query="AI" count=5

unblock_user

unblock_user(screen_name: str)

Unblock a user by screen name.

Note: X aggressively rate-limits / risk-scans block + mute. Avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call unblock_user screen_name=elonmusk

unfollow_user

unfollow_user(screen_name: str)

Unfollow a user by screen name.

Note: X aggressively rate-limits follow / unfollow — avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call unfollow_user screen_name=elonmusk

unmute_user

unmute_user(screen_name: str)

Unmute a user by screen name.

Note: X aggressively rate-limits / risk-scans block + mute. Avoid bulk usage or your account may be temporarily restricted.

Args: screen_name: Twitter username (without @).

CLI:

twikit-mcp call unmute_user screen_name=elonmusk

列表 (Lists)

add_list_member

add_list_member(list_id: str, screen_name: Union = None, user_id: Union = None)

Add a user to a Twitter List.

Caller must provide exactly one of screen_name / user_id.

Args: list_id: The list ID (required). screen_name: Twitter username (without @). user_id: Twitter numeric user ID.

CLI:

twikit-mcp call add_list_member list_id=1234567890 screen_name=elonmusk

create_list

create_list(name: str, description: str = '', is_private: bool = False)

Create a new Twitter List.

Args: name: The name for the new list (required, must not be empty). description: Description for the list (default empty). is_private: If True, the list is private (default False = public).

CLI:

twikit-mcp call create_list name=<name> description=<description>

edit_list

edit_list(list_id: str, name: Union = None, description: Union = None, is_private: Union = None)

Edit a Twitter List's metadata.

At least one of name, description, or is_private must be provided. Pass an empty string for description to clear it.

Args: list_id: The list ID (required). name: New name for the list. description: New description (empty string clears it). is_private: True to make private, False to make public.

CLI:

twikit-mcp call edit_list list_id=1234567890 name=<name>

get_list

get_list(list_id: str)

Get a Twitter List by ID.

Args: list_id: The list ID.

CLI:

twikit-mcp call get_list list_id=1234567890

get_list_members

get_list_members(list_id: str, count: int = 20, cursor: Union = None)

Get members of a Twitter List (paginated).

Args: list_id: The list ID. count: Number of members to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_list_members list_id=1234567890 count=5

get_list_subscribers

get_list_subscribers(list_id: str, count: int = 20, cursor: Union = None)

Get subscribers of a Twitter List (paginated).

Args: list_id: The list ID. count: Number of subscribers to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_list_subscribers list_id=1234567890 count=5

get_list_tweets

get_list_tweets(list_id: str, count: int = 20, cursor: Union = None)

Get tweets from a Twitter List (paginated).

Args: list_id: The list ID. count: Number of tweets to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_list_tweets list_id=1234567890 count=5

get_lists

get_lists(count: int = 20, cursor: Union = None)

Get the authenticated user's Twitter Lists (paginated).

Args: count: Number of lists to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_lists count=5 cursor=<cursor>

remove_list_member

remove_list_member(list_id: str, screen_name: Union = None, user_id: Union = None)

Remove a user from a Twitter List.

Caller must provide exactly one of screen_name / user_id.

Args: list_id: The list ID (required). screen_name: Twitter username (without @). user_id: Twitter numeric user ID.

CLI:

twikit-mcp call remove_list_member list_id=1234567890 screen_name=elonmusk

社群 (Communities)

get_communities_timeline

get_communities_timeline(count: int = 20, cursor: Union = None)

Get tweets from communities the authenticated user has joined (paginated).

Args: count: Number of tweets to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_communities_timeline count=5 cursor=<cursor>

get_community

get_community(community_id: str)

Get a Twitter Community by ID.

Args: community_id: The community ID.

CLI:

twikit-mcp call get_community community_id=1234567890

get_community_members

get_community_members(community_id: str, count: int = 20, cursor: Union = None)

Get members of a Twitter Community (paginated).

Args: community_id: The community ID. count: Number of members to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_community_members community_id=1234567890 count=5

get_community_moderators

get_community_moderators(community_id: str, count: int = 20, cursor: Union = None)

Get moderators of a Twitter Community (paginated).

Args: community_id: The community ID. count: Number of moderators to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_community_moderators community_id=1234567890 count=5

get_community_tweets

get_community_tweets(community_id: str, tweet_type: str, count: int = 40, cursor: Union = None)

Get tweets from a Twitter Community (paginated).

Args: community_id: The community ID. tweet_type: One of "Top", "Latest", or "Media". count: Number of tweets to fetch (default 40, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_community_tweets community_id=1234567890 tweet_type=<tweet_type>

join_community

join_community(community_id: str)

Join a Twitter Community.

Args: community_id: The community ID to join.

CLI:

twikit-mcp call join_community community_id=1234567890

leave_community

leave_community(community_id: str)

Leave a Twitter Community.

Args: community_id: The community ID to leave.

CLI:

twikit-mcp call leave_community community_id=1234567890

request_to_join_community

request_to_join_community(community_id: str, answer: Union = None)

Request to join a Twitter Community.

For communities with restricted join policies that require moderator approval, an answer to the join request question may be required.

Args: community_id: The community ID to request to join. answer: Optional answer to the join request question (required for some communities with moderator approval policy).

CLI:

twikit-mcp call request_to_join_community community_id=1234567890 answer=<answer>

search_community

search_community(query: str, cursor: Union = None)

Search for Twitter Communities by query (paginated).

Note: twikit's search_community does not support a count parameter.

Args: query: Search query string. cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call search_community query="AI" cursor=<cursor>

search_community_tweet

search_community_tweet(community_id: str, query: str, count: int = 20, cursor: Union = None)

Search tweets within a Twitter Community (paginated).

Args: community_id: The community ID. query: Search query string. count: Number of tweets to fetch (default 20, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call search_community_tweet community_id=1234567890 query="AI"

文章 (Articles)

get_article

get_article(article_id: str, format: str = 'plain')

Fetch an X Article (long-form post) by rest_id or URL.

Two-hop reader flow (issue #10):

  1. ArticleRedirectScreenQuery resolves the article rest_id to the underlying tweet rest_id.
  2. TweetResultByRestId (twikit's existing helper) fetches the tweet with article fieldToggles enabled. The body lives at tweet.article.article_results.result.

Requires authentication via cookies — same as every other authenticated tool here. No env-var setup.

Args: article_id: Article rest_id (numeric string) or full /i/article/ URL. format: Output shape, one of: - "preview" (~1 KB) — rest_id, title, preview_text, cover_image - "plain" (~20 KB, default) — above + plain_text + media URL list + lifecycle_state. The LLM-friendly shape. - "full" (~150 KB+) — raw GraphQL payload including the heavy content_state rich-block tree. Use only when you need it (rich-content rendering, archiving, structure analysis).

CLI:

twikit-mcp call get_article article_id=<article_id> format=<format>

get_article_preview

get_article_preview(tweet_id: str)

Get title/preview/cover of an X Article embedded in a tweet.

Uses X's public syndication endpoint — no authentication required.

Args: tweet_id: ID (numeric string) or full URL of a tweet that links to an article.

CLI:

twikit-mcp call get_article_preview tweet_id=20

私信 (DMs)

delete_dm

delete_dm(message_id: str)

Delete a direct message by ID.

Note: Deletes a PRIVATE message. Do not bulk-call. X has aggressive anti-spam on DMs and may suspend the account.

Args: message_id: The message ID to delete.

CLI:

twikit-mcp call delete_dm message_id=<message_id>

get_dm_history

get_dm_history(screen_name: str, max_id: Union = None)

Get DM conversation history with a user.

Note: Retrieves PRIVATE messages. Do not bulk-call. X has aggressive anti-spam on DMs and may suspend the account.

Args: screen_name: Twitter username (without @). max_id: If specified, retrieves messages older than this ID (for pagination). Pass the value from a previous response's next_cursor here on the next call to walk further back in time.

CLI:

twikit-mcp call get_dm_history screen_name=elonmusk max_id=<max_id>

send_dm

send_dm(screen_name: str, text: str, media_id: Union = None)

Send a direct message to a user by screen name.

Note: Sends a PRIVATE message. Do not bulk-call. X has aggressive anti-spam on DMs and may suspend the account.

Args: screen_name: Twitter username (without @) to send the DM to. text: Message content (required, must not be empty). media_id: Optional media ID to attach.

CLI:

twikit-mcp call send_dm screen_name=elonmusk text="hello world"

send_dm_to_group

send_dm_to_group(group_id: str, text: str, media_id: Union = None)

Send a direct message to a group conversation.

Note: Sends a PRIVATE message. Do not bulk-call. X has aggressive anti-spam on DMs and may suspend the account.

Args: group_id: The group conversation ID. text: Message content (required, must not be empty). media_id: Optional media ID to attach.

CLI:

twikit-mcp call send_dm_to_group group_id=<group_id> text="hello world"

发现与通知

get_notifications

get_notifications(notification_type: str = 'All', count: int = 40, cursor: Union = None)

Fetch notifications (paginated).

Args: notification_type: One of "All", "Verified", "Mentions" (default "All"). count: Number to fetch (default 40, max 100). cursor: Pagination cursor from a previous response's next_cursor.

CLI:

twikit-mcp call get_notifications notification_type=<notification_type> count=5

get_trends(category: str = 'trending', count: int = 20)

Get trending topics by category.

Args: category: One of "trending", "for-you", "news", "sports", "entertainment" (default "trending"). count: Number of trends to fetch (default 20).

CLI:

twikit-mcp call get_trends category=<category> count=5

定时推文与投票

create_poll

create_poll(choices: list, duration_minutes: int)

Create an X poll and return its card URI.

X polls have 2-4 choices and a duration in minutes. Pass the returned card_uri to send_tweet's poll_uri parameter to attach the poll.

Args: choices: Poll choices (2-4 entries required; each must be non-empty). duration_minutes: Poll duration in minutes (must be > 0).

CLI:

twikit-mcp call create_poll choices=<choices> duration_minutes=100

create_scheduled_tweet

create_scheduled_tweet(scheduled_at: int, text: str = '', media_ids: Union = None)

Schedule a tweet to be posted at a future Unix timestamp.

Scheduled tweets follow X's standard rate limits, no special caveats needed.

Args: scheduled_at: Unix epoch seconds when the tweet should be posted (must be in the future). text: Tweet text. At least one of text or media_ids must be provided. media_ids: List of media IDs to attach to the scheduled tweet.

CLI:

twikit-mcp call create_scheduled_tweet scheduled_at=100 text="hello world"

delete_scheduled_tweet

delete_scheduled_tweet(scheduled_tweet_id: str)

Delete a scheduled tweet by its scheduled tweet ID.

Scheduled tweets follow X's standard rate limits, no special caveats needed.

Args: scheduled_tweet_id: The ID of the scheduled tweet (from create_scheduled_tweet or get_scheduled_tweets). This is NOT a regular tweet ID.

CLI:

twikit-mcp call delete_scheduled_tweet scheduled_tweet_id=<scheduled_tweet_id>

get_scheduled_tweets

get_scheduled_tweets()

Return all scheduled tweets for the authenticated user.

Note: returns the FULL list in one call — twikit's API does not paginate scheduled tweets. This is fine in practice since X caps scheduled tweets per account at a small number.

Scheduled tweets follow X's standard rate limits, no special caveats needed.

CLI:

twikit-mcp call get_scheduled_tweets

vote

vote(selected_choice: str, card_uri: str, tweet_id: str, card_name: str)

Vote on an X poll.

X polls have 2-4 choices and a duration in minutes. The card_uri and card_name come from the tweet's poll card metadata (obtainable via get_tweet).

Args: selected_choice: The label of the choice to vote for (must be non-empty). card_uri: The poll card URI (from the tweet's poll card metadata). tweet_id: The ID of the tweet containing the poll. card_name: The name of the poll card (from the tweet's poll card metadata).

CLI:

twikit-mcp call vote selected_choice=<selected_choice> card_uri=<card_uri> tweet_id=20 card_name=<card_name>

其他

download_tweet_video

download_tweet_video(tweet_id: str, output_dir: Union = None, format: str = 'best[ext=mp4]')

Download video(s) attached to a tweet via yt-dlp.

Args: tweet_id: Tweet ID (numeric string) or full URL. output_dir: Where to save. Default: $TWIKIT_DOWNLOAD_DIR or ~/Downloads/twikit-mcp/. format: yt-dlp format selector. Default "best[ext=mp4]" (single muxed mp4, no ffmpeg required). Pass "bestvideo+bestaudio" for separate-stream max-quality merge (requires ffmpeg).

Returns: JSON with path, size_bytes, duration_sec, format, width, height, url, tweet_id. Raises ToolError if yt-dlp / ffmpeg is missing, the tweet has no video, or download fails.

CLI:

twikit-mcp call download_tweet_video tweet_id=20 output_dir=<output_dir>