This MCP server enables comprehensive X/Twitter management through AI assistants like Claude, allowing you to create, publish, and interact with tweets using dual OAuth authentication (1.0a for writes, 2.0 for reads) with automatic fallback.
Core Capabilities:
Draft Management: Create, list, publish, and delete draft tweets, threads, replies, and quote tweets
Direct Actions: Reply, retweet, and quote tweet without creating drafts
Media Support: Upload images, videos, and GIFs with alt text support
Content Retrieval: Search tweets, retrieve tweet information, and batch processing
Diagnostics: API connection testing with detailed troubleshooting information
Error Handling: Robust error management with draft preservation on publish failures
Enables creation, management and publishing of X/Twitter posts, threads, and replies directly through chat interface, including draft management and direct tweet interactions
X(Twitter) MCP Server
English | ไธญๆ
An MCP server to create, manage and publish X/Twitter posts directly through Claude code and Gemini CLI chat.
Note: This project is modified from vidhupv/x-mcp, with added reply functionality for tweets.
Features
๐ Dual Authentication Support
โ OAuth 1.0a: For write operations (posting tweets, retweeting, etc.)
โ OAuth 2.0: For read operations (getting tweets, searching, etc.)
โ Automatic Client Selection: System automatically chooses the best authentication method
โ Smart Fallback: Automatically falls back to OAuth 1.0a when OAuth 2.0 is unavailable
๐ Tweet Management
โ Create draft tweets
โ Create draft tweet threads
โ Create draft replies to existing tweets
โ List all drafts
โ Publish drafts (tweets, threads, and replies)
โ Reply to tweets directly (without creating drafts)
โ Retweet existing tweets
โ Quote tweet with comments
โ Create draft quote tweets
โ Delete drafts
โ Auto-delete failed drafts (configurable)
โ Draft preservation on publish failure (configurable)
๐ท Media Support
โ Upload media files (images, videos, GIFs)
โ Create tweets with media attachments
โ Add alt text for accessibility
โ Get media file information
๐ Tweet Retrieval (Enhanced)
โ Get tweet content and information (with dual authentication support)
โ Search recent tweets (improved error handling)
โ Batch retrieve multiple tweets (more stable connections)
โ Detailed error diagnostics and suggestions
โ API connection testing tools
Quick Setup
Installing via Smithery
To install X(Twitter) MCP Server for Claude code automatically via Smithery:
Manual Installation for Claude code
Clone the repository:
Install UV globally using Homebrew in Terminal:
Create claude_desktop_config.json:
For MacOS: Open directory
~/Library/Application Support/Claude/
and create the file inside itFor Windows: Open directory
%APPDATA%/Claude/
and create the file inside it
Add this configuration to claude_desktop_config.json:
Basic Configuration (OAuth 1.0a Only)
Recommended Configuration (OAuth 1.0a + OAuth 2.0 Dual Authentication)
๐ก Recommended to use dual authentication configuration: Adding
TWITTER_BEARER_TOKEN
can significantly improve the stability and success rate of tweet retrieval functions.
Get your X/Twitter API credentials:
Go to X API Developer Portal
Create a project
In User Authentication Settings: Set up with Read and Write permissions, Web App type
Set Callback URL to
http://localhost/
and Website URL tohttp://example.com/
Generate and copy all keys and tokens from Keys and Tokens section
Update the config file:
Replace
/path/to/x-mcp
with your actual repository pathAdd your X/Twitter API credentials
Quit Claude completely and reopen it
Configuration for Gemini CLI
If you want to use this MCP server with Gemini CLI instead of Claude code:
Install Gemini CLI:
Create or update your MCP configuration file:
Create a file named
~/.gemini/settings.json
Add the following configuration:
Start Gemini CLI with MCP support:
Update the config file:
Replace
/path/to/x-mcp
with your actual repository pathAdd your X/Twitter API credentials
Advanced Configuration
Auto-Delete Failed Drafts
When tweet publishing fails, you can choose whether to automatically delete drafts:
Enable auto-delete (default): Automatically delete drafts when publishing fails to avoid accumulating invalid drafts
Disable auto-delete: Preserve drafts when publishing fails, allowing manual retry or modification
Configuration Methods
Via Environment Variable: Add
"AUTO_DELETE_FAILED_DRAFTS": "true"
or"false"
in your configuration fileVia Commands: Use "Enable auto-delete failed drafts" or "Disable auto-delete failed drafts"
Check Status: Use "Check current auto-delete configuration"
Usage Examples
Works with both Claude code and Gemini CLI:
"Tweet 'Just learned how to tweet through AI - mind blown! ๐คโจ'"
"Create a thread about the history of pizza"
"Show me my draft tweets"
"Publish this draft!"
"Delete that draft"
"Reply to tweet 1234567890 with 'Great point! Thanks for sharing.'"
"Create a draft reply to tweet 1234567890 saying 'I completely agree with this perspective.'"
"Retweet tweet 1234567890"
"Quote tweet 1234567890 with comment 'This is exactly what I was thinking!'"
"Create a draft quote tweet for 1234567890 with comment 'Amazing insight here'"
"Upload image /path/to/image.jpg with alt text 'Beautiful sunset over the mountains'"
"Create tweet with media 'Check out this amazing photo!' using media IDs 123456789"
"Create draft tweet with media 'My latest project' and attach /path/to/video.mp4"
"Enable auto-delete failed drafts"
"Disable auto-delete failed drafts"
"Check current auto-delete configuration"
"Get tweet 1234567890 content and information"
"Search for tweets containing 'AI OR artificial intelligence' from the last 7 days"
"Get information for tweets 123456789, 987654321, 555666777"
Troubleshooting
Basic Issues
If not working:
Make sure UV is installed globally (if not, uninstall with
pip uninstall uv
and reinstall withbrew install uv
)Or find UV path with
which uv
and replace"command": "uv"
with the full pathVerify all X/Twitter credentials are correct
Check if the x-mcp path in config matches your actual repository location
๐ง API Connection Testing
Quick Diagnosis:
Running this command in Claude will:
Test OAuth 1.0a and OAuth 2.0 connections
Check API permissions and limitations
Provide detailed diagnostic information and suggestions
Run Test Script:
๐จ 401 Unauthorized Error Fix
Problem Symptoms:
Getting "401 Unauthorized" error when posting tweets
Can post tweets but cannot retrieve tweets
Solutions:
Add Bearer Token (Recommended):
"env": { "TWITTER_API_KEY": "your_api_key", "TWITTER_API_SECRET": "your_api_secret", "TWITTER_ACCESS_TOKEN": "your_access_token", "TWITTER_ACCESS_TOKEN_SECRET": "your_access_token_secret", "TWITTER_BEARER_TOKEN": "your_bearer_token" }Regenerate API Credentials:
Visit Twitter Developer Portal
Regenerate all API keys and tokens
Ensure permissions are set to "Read and write"
Check Project Settings:
User authentication settings: Read and write permissions
App type: Web App
Callback URL:
http://localhost/
Website URL:
http://example.com/
๐ Tweet Retrieval Issues
Dual Authentication Benefits:
OAuth 2.0 for read operations (more stable)
OAuth 1.0a for write operations (required)
Automatic fallback handling
Common Errors and Solutions:
Error Code | Cause | Solution |
401 | Authentication failed | Check API credentials, regenerate tokens |
403 | Insufficient permissions | Upgrade API plan or check permission settings |
404 | Tweet not found | Verify tweet ID, check if tweet is public |
429 | Rate limit exceeded | Wait 15 minutes or upgrade API plan |
API Plan Limitations:
Free Users: Basic functionality with limitations
Basic ($100/month): Full read functionality
Pro ($5000/month): Advanced features and higher limits
๐ Detailed Diagnostic Steps
Check Authentication Status:
test api connectionVerify Configuration:
Confirm all environment variables are set
Check paths are correct
Validate API key formats
Test Specific Functions:
search for tweets containing "hello" get tweet 1234567890 contentReview Detailed Logs:
Check Claude Desktop console
Review MCP server logs
Note specific error messages
Credits
This project is based on the excellent work by Vidhu Panhavoor Vasudevan in the original x-mcp repository.
What's New in This Fork
๐ OAuth Dual Authentication System - Support for OAuth 1.0a + OAuth 2.0, automatic selection of best authentication method
๐ 401 Error Fix - Resolved authentication issues when retrieving tweets
๐ Smart Client Selection - Read operations prefer OAuth 2.0, write operations use OAuth 1.0a
๐ Enhanced Error Handling - Detailed error diagnostics and English error messages
๐ API Connection Testing Tool - Built-in connection testing and diagnostic functionality
โ Reply to tweets functionality - Create draft replies and reply directly to existing tweets
โ Retweet functionality - Simple retweets and quote tweets with comments
โ Media functionality - Upload images, videos, GIFs with alt text support
โ Tweet retrieval functionality - Get tweet content, search tweets, batch retrieve multiple tweets
โ Enhanced draft management - Improved draft preservation on publish failure, support for all draft types
Special thanks to the original author for creating the foundation of this MCP server!
Detailed Documentation
For more detailed functionality descriptions and usage guides, please refer to:
OAuth Dual Authentication Setup Guide - ๐ Detailed dual authentication setup guide
OAuthๅ้่ฎค่ฏ้ ็ฝฎๆๅ - Chinese version of the setup guide
ๆจๆ่ทๅๅ่ฝๆ ้ๆ้คๆๅ - Chinese troubleshooting guide
REPLY_FUNCTIONALITY.md - Detailed reply functionality documentation
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
Enables creating, managing, and publishing X/Twitter posts, threads, and replies directly through Claude chat. Supports draft management with the ability to create, list, publish, and delete tweet drafts.