X (Twitter) MCP server
A Model Context Protocol (MCP) server for interacting with Twitter (X) via AI tools. This server allows you to fetch tweets, post tweets, search Twitter, manage followers, and more, all through natural language commands in AI Tools.
Features
- Fetch user profiles, followers, and following lists.
- Post, delete, and favorite tweets.
- Search Twitter for tweets and trends.
- Manage bookmarks and timelines.
- Built-in rate limit handling for the Twitter API.
- Uses Twitter API v2 with proper authentication (API keys and tokens), avoiding the username/password hack to minimize the risk of account suspensions.
- Provides a complete implementation of Twitter API v2 endpoints for user management, tweet management, timelines, and search functionality.
Prerequisites
- Python 3.10 or higher: Ensure Python is installed on your system.
- Twitter Developer Account: You need API credentials (API Key, API Secret, Access Token, Access Token Secret, and Bearer Token) from the Twitter Developer Portal.
- Optional: Claude Desktop: Download and install the Claude Desktop app from the Anthropic website.
- Optional: Node.js (for MCP integration): Required for running MCP servers in Claude Desktop.
- A package manager like
uv
orpip
for Python dependencies.
Installation
Option 1: Installing via Smithery (Recommended)
To install X (Twitter) MCP server for Claude Desktop automatically via Smithery:
Option 2: Install from PyPI
The easiest way to install x-twitter-mcp
is via PyPI:
Option 3: Install from Source
If you prefer to install from the source repository:
- Clone the Repository:Copy
- Set Up a Virtual Environment (optional but recommended):Copy
- Install Dependencies:
Using
uv
(recommended, as the project usesuv.lock
):Alternatively, usingCopypip
:Copy - Configure Environment Variables:
- Create a
.env
file in the project root (you can copy.env.example
if provided). - Add your Twitter API credentials:Copy
- Create a
Running the Server
You can run the server in two ways:
Option 1: Using the CLI Script
The project defines a CLI script x-twitter-mcp-server
.
If installed from PyPI:
If installed from source with uv
:
Option 2: Using FastMCP Directly (Source Only)
If you installed from source and prefer to run the server using FastMCP’s development mode:
The server will start and listen for MCP connections. You should see output like:
Using with Claude Desktop
To use this MCP server with Claude Desktop, you need to configure Claude to connect to the server. Follow these steps:
Step 1: Install Node.js
Claude Desktop uses Node.js to run MCP servers. If you don’t have Node.js installed:
- Download and install Node.js from nodejs.org.
- Verify installation:Copy
Step 2: Locate Claude Desktop Configuration
Claude Desktop uses a claude_desktop_config.json
file to configure MCP servers.
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
If the file doesn’t exist, create it.
Step 3: Configure the MCP Server
Edit claude_desktop_config.json
to include the x-twitter-mcp
server. Replace /path/to/x-twitter-mcp-server
with the actual path to your project directory (if installed from source) or the path to your Python executable (if installed from PyPI).
If installed from PyPI:
If installed from source with uv
:
"command": "x-twitter-mcp-server"
: Uses the CLI script directly if installed from PyPI."env"
: If installed from PyPI, you may need to provide environment variables directly in the config (since there’s no.env
file). If installed from source, the.env
file will be used."env": {"PYTHONUNBUFFERED": "1"}
: Ensures output is unbuffered for better logging in Claude.
Step 4: Restart Claude Desktop
- Quit Claude Desktop completely.
- Reopen Claude Desktop to load the new configuration.
Step 5: Verify Connection
- Open Claude Desktop.
- Look for a hammer or connector icon in the input area (bottom right corner). This indicates MCP tools are available.
- Click the icon to see the available tools from
x-twitter-mcp
, such aspost_tweet
,search_twitter
,get_user_profile
, etc.
Step 6: Test with Claude
You can now interact with Twitter using natural language in Claude Desktop. Here are some example prompts:
- Fetch a User Profile:Claude will call theCopy
get_user_profile
tool and return the user’s details. - Post a Tweet:Claude will use theCopy
post_tweet
tool to post the tweet and confirm the action. - Search Twitter:Claude will invoke theCopy
search_twitter
tool and return relevant tweets. - Get Trends:Claude will use theCopy
get_trends
tool to fetch trending topics.
When prompted, grant Claude permission to use the MCP tools for the chat session.
Available Tools
Below is a list of all tools provided by the x-twitter-mcp
server, along with example executions in Claude Desktop using natural language prompts.
User Management Tools
get_user_profile
- Description: Get detailed profile information for a user.
- Claude Desktop Example:Claude will return the user’s profile details, including ID, name, username, profile image URL, and description.Copy
get_user_by_screen_name
- Description: Fetches a user by screen name.
- Claude Desktop Example:Claude will return the user’s profile details.Copy
get_user_by_id
- Description: Fetches a user by ID.
- Claude Desktop Example:Claude will return the user’s profile details.Copy
get_user_followers
- Description: Retrieves a list of followers for a given user.
- Claude Desktop Example:Claude will return a list of up to 50 followers.Copy
get_user_following
- Description: Retrieves users the given user is following.
- Claude Desktop Example:Claude will return a list of up to 50 users.Copy
get_user_followers_you_know
- Description: Retrieves a list of common followers.
- Claude Desktop Example:Claude will return a list of up to 50 common followers (simulated by filtering followers).Copy
get_user_subscriptions
- Description: Retrieves a list of users to which the specified user is subscribed.
- Claude Desktop Example:Claude will return a list of up to 50 users (using following as a proxy for subscriptions).Copy
Tweet Management Tools
post_tweet
- Description: Post a tweet with optional media, reply, and tags.
- Claude Desktop Example:Claude will post the tweet and return the tweet details.Copy
delete_tweet
- Description: Delete a tweet by its ID.
- Claude Desktop Example:Claude will delete the tweet and confirm the action.Copy
get_tweet_details
- Description: Get detailed information about a specific tweet.
- Claude Desktop Example:Claude will return the tweet’s details, including ID, text, creation date, and author ID.Copy
create_poll_tweet
- Description: Create a tweet with a poll.
- Claude Desktop Example:Claude will create the poll tweet and return the tweet details.Copy
vote_on_poll
- Description: Vote on a poll.
- Claude Desktop Example:Claude will return a mock response (since Twitter API v2 doesn’t support poll voting).Copy
favorite_tweet
- Description: Favorites a tweet.
- Claude Desktop Example:Claude will favorite the tweet and confirm the action.Copy
unfavorite_tweet
- Description: Unfavorites a tweet.
- Claude Desktop Example:Claude will unfavorite the tweet and confirm the action.Copy
bookmark_tweet
- Description: Adds the tweet to bookmarks.
- Claude Desktop Example:Claude will bookmark the tweet and confirm the action.Copy
delete_bookmark
- Description: Removes the tweet from bookmarks.
- Claude Desktop Example:Claude will remove the bookmark and confirm the action.Copy
delete_all_bookmarks
- Description: Deletes all bookmarks.
- Claude Desktop Example:Claude will delete all bookmarks and confirm the action.Copy
Timeline & Search Tools
get_timeline
- Description: Get tweets from your home timeline (For You).
- Claude Desktop Example:Claude will return up to 20 tweets from your For You timeline.Copy
get_latest_timeline
- Description: Get tweets from your home timeline (Following).
- Claude Desktop Example:Claude will return up to 20 tweets from your Following timeline.Copy
search_twitter
- Description: Search Twitter with a query.
- Claude Desktop Example:Claude will return up to 10 recent tweets about AI.Copy
get_trends
- Description: Retrieves trending topics on Twitter.
- Claude Desktop Example:Claude will return up to 10 trending topics.Copy
get_highlights_tweets
- Description: Retrieves highlighted tweets from a user’s timeline.
- Claude Desktop Example:Claude will return up to 20 tweets from the user’s timeline (simulated as highlights).Copy
get_user_mentions
- Description: Get tweets mentioning a specific user.
- Claude Desktop Example:Claude will return up to 20 tweets mentioning the user.Copy
Troubleshooting
- Server Not Starting:
- Ensure your
.env
file has all required Twitter API credentials (if installed from source). - If installed from PyPI, ensure environment variables are set in
claude_desktop_config.json
or your shell. - Check the terminal output for errors when running
x-twitter-mcp-server
. - Verify that
uv
or your Python executable is correctly installed and accessible.
- Ensure your
- Claude Not Detecting the Server:
- Confirm the path in
claude_desktop_config.json
is correct. - Ensure the
command
andargs
point to the correct executable and script. - Restart Claude Desktop after updating the config file.
- Check Claude’s Developer Mode logs (Help → Enable Developer Mode → Open MCP Log File) for errors.
- Confirm the path in
- Rate Limit Errors:
- The server includes rate limit handling, but if you hit Twitter API limits, you may need to wait for the reset window (e.g., 15 minutes for tweet actions).
- Syntax Warnings:
- If you see
SyntaxWarning
messages from Tweepy, they are due to docstring issues in Tweepy with Python 3.13. The server includes a warning suppression to handle this.
- If you see
Contributing
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE
file for details.
Author
- Rafal Janicki - rafal@kult.io
You must be authenticated.
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.
Tools
X (Twitter) MCP server
Related MCP Servers
- AsecurityAlicenseAqualityA Model Context Protocol (MCP) server for managing social media posts, currently supporting X (formerly Twitter).Last updated -37JavaScriptMIT License
- AsecurityAlicenseAqualityAn MCP server that allows Claude to create, manage and publish X/Twitter posts directly through the chat interface.Last updated -535PythonMIT License
- AsecurityAlicenseAqualityAn MCP server that enables Claude to interact with Twitter, allowing for posting tweets and searching Twitter content.Last updated -290151TypeScriptMIT License
- -securityAlicense-qualityA headless MCP server that provides Twitter API access without requiring local credential setup, enabling core Twitter operations like searching tweets, getting user tweets, posting tweets, and replying to tweets.Last updated -PythonMIT License