
Twitter interaction MCP server with cookie-based authentication for posting, searching, and messaging.
Twitter interaction MCP server with cookie-based authentication for posting, searching, and messaging.
A Model Context Protocol (MCP) server that provides Twitter functionality using the twikit
library. This server allows AI assistants to interact with Twitter through a standardized protocol with cookie-based authentication - the LLM model provides ct0
and auth_token
cookies directly in tool calls.
ct0
and auth_token
cookies directly in tool callsThis project utilizes an unofficial API to interact with X (formerly Twitter) through the twikit
library. The methods employed for authentication and data retrieval are not officially endorsed by X/Twitter and may be subject to change or discontinuation without notice.
This tool is intended for educational and experimental purposes only. Users should be aware of the potential risks associated with using unofficial APIs, including but not limited to account restrictions or suspension. The developers of this project are not responsible for any misuse or consequences arising from the use of this tool.
git clone <repository-url> cd twitter-mcp
pip install -r requirements.txt
python server.py
The server expects the LLM model to provide Twitter cookies directly in each tool call via the ct0
and auth_token
parameters. No pre-configuration is required!
The LLM model will need to provide both Twitter cookies. Here's how to obtain them:
ct0
- CSRF token cookieauth_token
- Authentication token cookieBoth cookies are required for all operations.
Test authentication with cookies:
{ "tool": "authenticate", "arguments": { "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Post a new tweet:
{ "tool": "tweet", "arguments": { "text": "Hello from MCP! 🚀", "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Get information about a Twitter user:
{ "tool": "get_user_info", "arguments": { "username": "elonmusk", "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Search for tweets:
{ "tool": "search_tweets", "arguments": { "query": "artificial intelligence", "count": 10, "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Get tweets from your timeline:
{ "tool": "get_timeline", "arguments": { "count": 20, "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Like a tweet by ID:
{ "tool": "like_tweet", "arguments": { "tweet_id": "1234567890123456789", "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Retweet a tweet by ID:
{ "tool": "retweet", "arguments": { "tweet_id": "1234567890123456789", "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Send a direct message to a user.
Parameters:
recipient_username
(string): The username (without @) to send the message to (automatically converted to user_id internally)text
(string): The message contentct0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie{ "name": "send_dm", "arguments": { "recipient_username": "username", "text": "Hello from MCP!", "ct0": "your_ct0_token", "auth_token": "your_auth_token" } }
Get direct message history with a specific user.
Parameters:
recipient_username
(string): The username (without @) to get DM history with (automatically converted to user_id internally)count
(integer, optional): Number of messages to retrieve (default: 20, max: 100)ct0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie{ "name": "get_dm_history", "arguments": { "recipient_username": "username", "count": 50, "ct0": "your_ct0_token", "auth_token": "your_auth_token" } }
Add an emoji reaction to a direct message.
Parameters:
message_id
(string): The ID of the message to react toemoji
(string): The emoji to add (e.g., "👍", "❤️", "😀")conversation_id
(string): The conversation ID containing the messagect0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie{ "name": "add_reaction_to_message", "arguments": { "message_id": "message_id_here", "emoji": "👍", "conversation_id": "conversation_id_here", "ct0": "your_ct0_token", "auth_token": "your_auth_token" } }
Delete a direct message:
{ "tool": "delete_dm", "arguments": { "message_id": "1234567890123456789", "ct0": "your_ct0_cookie_here", "auth_token": "your_auth_token_cookie_here" } }
Get replies to a specific tweet.
Parameters:
tweet_id
(string): The ID of the tweet to get replies forcount
(integer, optional): Number of replies to retrieve (default: 20)ct0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie{ "name": "get_tweet_replies", "arguments": { "tweet_id": "1234567890", "count": 10, "ct0": "your_ct0_token", "auth_token": "your_auth_token" } }
Resources can be accessed but require the TWITTER_CT0