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:
- Configure Environment Variables:Edit
.env
and add your X API credentials: - Build the Project:
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 control - Keep 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
x-mcp-server
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 -3330JavaScriptMIT License
- -securityAlicense-qualityEnables interaction with Twitter through a Model Context Protocol, allowing large language models to post tweets, search for tweets, and reply to tweets.Last updated -25318TypeScriptMIT 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 -511JavaScript
- -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 -108TypeScriptMIT License