Skip to main content

Twitter MCP Server

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.

Features

  • Cookie Authentication: LLM model provides ct0 and auth_token cookies directly in tool calls
  • Session Caching: Automatically caches authenticated sessions for efficiency
  • Timeline Access: Get tweets from your timeline
  • User Information: Retrieve user profiles and statistics
  • Tweet Search: Search for tweets with specific queries
  • Tweet Management: Post, like, and retweet tweets
  • User Tweets: Get tweets from specific users
  • Direct Messaging: Send DMs, get DM history, react to messages, and delete messages
  • Authentication Testing: Test cookies before use
  • Tweet Operations: Post tweets, like/unlike tweets, retweet/delete retweets, bookmark tweets
  • Tweet Retrieval: Get tweets by ID, search tweets, get user timelines, get tweet replies
  • User Operations: Follow/unfollow users, get user information, search users
  • Trending Topics: Get trending topics across different categories (trending, news, sports, entertainment, for-you)

Disclaimer

This 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.

Installation

  1. Clone this repository:
git clone <repository-url>
cd twitter-mcp
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the server:
python server.py

Authentication

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!

Getting Twitter Cookies

The LLM model will need to provide both Twitter cookies. Here's how to obtain them:

  1. Open your browser and go to Twitter/X
  2. Log in to your account
  3. Open Developer Tools (F12)
  4. Go to Application/Storage → Cookies → twitter.com (or x.com)
  5. Find and copy these cookie values:
    • ct0 - CSRF token cookie
    • auth_token - Authentication token cookie

Both cookies are required for all operations.

Usage

Available Tools

1. Authenticate

Test authentication with cookies:

{
  "tool": "authenticate",
  "arguments": {
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

2. Tweet

Post a new tweet:

{
  "tool": "tweet",
  "arguments": {
    "text": "Hello from MCP! 🚀",
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

3. Get User Info

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"
  }
}

4. Search Tweets

Search for tweets:

{
  "tool": "search_tweets",
  "arguments": {
    "query": "artificial intelligence",
    "count": 10,
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

5. Get Timeline

Get tweets from your timeline:

{
  "tool": "get_timeline",
  "arguments": {
    "count": 20,
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

6. Like Tweet

Like a tweet by ID:

{
  "tool": "like_tweet",
  "arguments": {
    "tweet_id": "1234567890123456789",
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

7. Retweet

Retweet a tweet by ID:

{
  "tool": "retweet",
  "arguments": {
    "tweet_id": "1234567890123456789",
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

8. Send Direct Message

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 content
  • ct0 (string): Twitter ct0 cookie
  • auth_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"
  }
}

9. Get DM History

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 cookie
  • auth_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"
  }
}

10. React to Direct Message

Add an emoji reaction to a direct message.

Parameters:

  • message_id (string): The ID of the message to react to
  • emoji (string): The emoji to add (e.g., "👍", "❤️", "😀")
  • conversation_id (string): The conversation ID containing the message
  • ct0 (string): Twitter ct0 cookie
  • auth_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"
  }
}

11. Delete Direct Message

Delete a direct message:

{
  "tool": "delete_dm",
  "arguments": {
    "message_id": "1234567890123456789",
    "ct0": "your_ct0_cookie_here",
    "auth_token": "your_auth_token_cookie_here"
  }
}

get_tweet_replies

Get replies to a specific tweet.

Parameters:

  • tweet_id (string): The ID of the tweet to get replies for
  • count (integer, optional): Number of replies to retrieve (default: 20)
  • ct0 (string): Twitter ct0 cookie
  • auth_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"
  }
}

get_trends

Get trending topics on Twitter.

Parameters:

  • category (string, optional): The category of trends to retrieve (default: "trending")
    • Options: "trending", "for-you", "news", "sports", "entertainment"
  • count (integer, optional): Number of trends to retrieve (default: 20, max: 50)
  • ct0 (string): Twitter ct0 cookie
  • auth_token (string): Twitter auth_token cookie
{
  "name": "get_trends",
  "arguments": {
    "category": "trending",
    "count": 20,
    "ct0": "your_ct0_token",
    "auth_token": "your_auth_token"
  }
}

Examples:

// Get general trending topics
{
  "name": "get_trends",
  "arguments": {
    "ct0": "your_ct0_token",
    "auth_token": "your_auth_token"
  }
}

// Get sports trends
{
  "name": "get_trends", 
  "arguments": {
    "category": "sports",
    "count": 10,
    "ct0": "your_ct0_token",
    "auth_token": "your_auth_token"
  }
}

// Get personalized trends
{
  "name": "get_trends",
  "arguments": {
    "category": "for-you",
    "ct0": "your_ct0_token", 
    "auth_token": "your_auth_token"
  }
}

Available Resources

Resources can be accessed but require the TWITTER_CT0

Metadata

Release files for iflow-mcp_gkydev_twitter-mcp-server 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iflow-mcp_gkydev_twitter-mcp-server 0.1.0
File Size Uploaded
iflow_mcp_gkydev_twitter_mcp_server-0.1.0.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iflow-mcp_gkydev_twitter-mcp-server 0.1.0
File Interpreter ABI Platform
iflow_mcp_gkydev_twitter_mcp_server-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / iflow_mcp_gkydev_twitter_mcp_server-0.1.0.tar.gz

Download URL iflow_mcp_gkydev_twitter_mcp_server-0.1.0.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
eb12aea1adc56d76e2748e3a4525266f9d5565983b65f0f135175a7fafa4f8a8
BLAKE2b-256 checksum
How to use checksums
d56e85a7e5c7597d5f1bc1eddca77cc9f7bcf1c7535e65e1f9c15b160c0a2ca9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / iflow_mcp_gkydev_twitter_mcp_server-0.1.0-py3-none-any.whl

Download URL iflow_mcp_gkydev_twitter_mcp_server-0.1.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3a76ad41573b2e8d3d32f2c79fd489b8e6e82469cb1fbf138732584a91276d3
BLAKE2b-256 checksum
How to use checksums
b9c36369b9eeaf8329f6104d2b0ef94778927701ece85c8bd00477ccb3cb8cc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page