The X MCP Server provides tools to interact with the X (Twitter) API through a Model Context Protocol server:
Post Tweets: Create and post tweets up to 280 characters, with optional replies to existing tweets by specifying
reply_to_tweet_id
Get User Timeline: Retrieve your recent tweets with customizable count limits (default 10, maximum 100)
Search Tweets: Search for tweets using specific queries with adjustable result counts (default 10, maximum 100)
Error Handling: Comprehensive handling for missing API credentials, invalid tweet content, API rate limits, network errors, and invalid parameters
Security: Secure management of API credentials and sensitive data through environment variables
X MCP Server
A Model Context Protocol (MCP) server for posting tweets to X (Twitter) and interacting with the X API.
Features
Post Tweets: Create and post tweets to X (Twitter)
Get User Timeline: Retrieve your recent tweets
Search Tweets: Search for tweets using queries
Reply to Tweets: Reply to existing tweets
Error Handling: Comprehensive error handling and validation
Prerequisites
X Developer Account: You need a Twitter/X developer account
Go to Twitter Developer Portal
Create a new app and get your API credentials
Node.js: Version 18 or higher
Setup
Clone and Install Dependencies:
npm installConfigure Environment Variables:
cp env.example .envEdit
.env
and add your X API credentials:X_API_KEY=your_api_key_here X_API_SECRET=your_api_secret_here X_ACCESS_TOKEN=your_access_token_here X_ACCESS_TOKEN_SECRET=your_access_token_secret_hereBuild the Project:
npm run build
Usage
Running the Server
Available Tools
The server provides the following tools:
1. post_tweet
Post a new tweet to X.
Parameters:
text
(required): The tweet content (max 280 characters)reply_to_tweet_id
(optional): ID of the tweet to reply to
Example:
2. get_user_timeline
Get your recent tweets.
Parameters:
count
(optional): Number of tweets to retrieve (default: 10, max: 100)
Example:
3. search_tweets
Search for tweets using a query.
Parameters:
query
(required): Search querycount
(optional): Number of results (default: 10, max: 100)
Example:
MCP Client Configuration
To use this server with an MCP client, add it to your client configuration:
Development
Project Structure
Scripts
npm run build
: Compile TypeScript to JavaScriptnpm start
: Run the compiled servernpm run dev
: Run in development mode with hot reloadnpm test
: Run tests (when implemented)
Error Handling
The server includes comprehensive error handling for:
Missing API credentials
Invalid tweet content (length, format)
API rate limits
Network errors
Invalid parameters
Security Notes
Never commit your
.env
file to version controlKeep your API credentials secure
Use environment variables for all sensitive data
Consider using a
.gitignore
file to exclude sensitive files
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests if applicable
Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
Check the error messages for common issues
Verify your API credentials are correct
Ensure you have the necessary X API permissions
Check the X API documentation for rate limits and restrictions
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.
Enables users to interact with X (Twitter) through the X API. Supports posting tweets, retrieving user timelines, searching tweets, and replying to tweets with comprehensive error handling.
Related MCP Servers
- AsecurityAlicenseAqualityServer for X (Twitter) integration that provides tools for reading your timeline and engaging with tweets. Designed for use with Claude desktop.Last updated -339MIT License
- AsecurityAlicenseAqualityEnables interaction with Twitter through a Model Context Protocol, allowing large language models to post tweets, search for tweets, and reply to tweets.Last updated -53221MIT License
- -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 -117
- -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 -210MIT License