Used for data validation when processing requests and responses between the client and Twitter API.
The primary language used to implement the MCP server and interact with Twitter's API.
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
andauth_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
- Clone this repository:
- Install dependencies:
- Run the server:
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:
- Open your browser and go to Twitter/X
- Log in to your account
- Open Developer Tools (F12)
- Go to Application/Storage → Cookies → twitter.com (or x.com)
- Find and copy these cookie values:
ct0
- CSRF token cookieauth_token
- Authentication token cookie
Both cookies are required for all operations.
Usage
Available Tools
1. Authenticate
Test authentication with cookies:
2. Tweet
Post a new tweet:
3. Get User Info
Get information about a Twitter user:
4. Search Tweets
Search for tweets:
5. Get Timeline
Get tweets from your timeline:
6. Like Tweet
Like a tweet by ID:
7. Retweet
Retweet a tweet by ID:
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 contentct0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie
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 cookieauth_token
(string): Twitter auth_token cookie
10. React to Direct Message
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
11. Delete Direct Message
Delete a direct message:
get_tweet_replies
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
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"
- Options:
count
(integer, optional): Number of trends to retrieve (default: 20, max: 50)ct0
(string): Twitter ct0 cookieauth_token
(string): Twitter auth_token cookie
Examples:
Available Resources
Resources can be accessed but require the TWITTER_CT0
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A Model Context Protocol server that enables AI assistants to interact with Twitter functionality using cookie-based authentication, allowing for timeline access, tweet management, user information retrieval, and search capabilities.
Related MCP Servers
- -securityFlicense-qualityProvides AI agents with comprehensive Twitter functionality through the Model Context Protocol standard, enabling reading tweets, posting content, managing interactions, and accessing timeline data with robust error handling.Last updated -41JavaScript
- -securityFlicense-qualityA versatile Model Context Protocol server that enables AI assistants to manage calendars, track tasks, handle emails, search the web, and control smart home devices.Last updated -2Python
- -securityAlicense-qualityA Model Context Protocol server that enables AI to interact with Twitter, allowing functions like searching tweets, comparing sentiments across accounts, and retrieving timeline content.Last updated -MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI models and applications to interact directly with Twitter/X, providing capabilities to create posts, reply to tweets, retrieve user data, and manage account actions.Last updated -874TypeScriptMIT License