Enhanced MCP server for Twitter/X with OAuth 2.0 support, v2 API media uploads, smart v1.1 fallbacks, and comprehensive rate limiting. Post tweets with text/media, search, and delete tweets programmatically.
An enhanced Model Context Protocol (MCP) server for X that adds OAuth 2.0 support, v2 API media uploads, and comprehensive rate limiting to the original implementation.
This server intelligently uses different X API versions based on authentication method and operation:
upload.twitter.com
)api.x.com/2/media/upload
)Before you begin, you'll need:
This server supports two authentication methods. Choose based on your needs:
Create a Developer Account:
Create a New App:
Configure App Permissions:
http://localhost:3000/callback
http://localhost:3000/callback
Get Your Credentials:
Required Credentials:
API_KEY=your_api_key_here
API_SECRET_KEY=your_api_secret_key_here
ACCESS_TOKEN=your_access_token_here
ACCESS_TOKEN_SECRET=your_access_token_secret_here
Get Your Client Credentials:
Generate User Tokens:
Option A - Use our helper script:
# Clone this repository first
git clone https://github.com/mbelinky/x-mcp-server.git
cd x-mcp-server/twitter-mcp
npm install
# Run the OAuth2 setup script
node scripts/oauth2-setup.js
Option B - Manual setup:
tweet.read
, tweet.write
, users.read
, media.write
, offline.access
Required Credentials:
AUTH_TYPE=oauth2
OAUTH2_CLIENT_ID=your_client_id_here
OAUTH2_CLIENT_SECRET=your_client_secret_here
OAUTH2_ACCESS_TOKEN=your_access_token_here
OAUTH2_REFRESH_TOKEN=your_refresh_token_here
Install via NPM (Recommended):
Edit your Claude Desktop configuration file:
%APPDATA%\Claude\claude_desktop_config.json
~/Library/Application Support/Claude/claude_desktop_config.json
Add this configuration:
{
"mcpServers": {
"twitter-mcp": {
"command": "npx",
"args": ["-y", "@mbelinky/x-mcp-server"],
"env": {
"API_KEY": "your_api_key_here",
"API_SECRET_KEY": "your_api_secret_key_here",
"ACCESS_TOKEN": "your_access_token_here",
"ACCESS_TOKEN_SECRET": "your_access_token_secret_here"
}
}
}
}
For OAuth 2.0:
{
"mcpServers": {
"twitter-mcp": {
"command": "npx",
"args": ["-y", "@mbelinky/x-mcp-server"],
"env": {
"AUTH_TYPE": "oauth2",
"OAUTH2_CLIENT_ID": "your_client_id",
"OAUTH2_CLIENT_SECRET": "your_client_secret",
"OAUTH2_ACCESS_TOKEN": "your_access_token",
"OAUTH2_REFRESH_TOKEN": "your_refresh_token"
}
}
}
}
Install from Source:
git clone https://github.com/mbelinky/x-mcp-server.git
cd x-mcp-server/twitter-mcp
npm install
npm run build
Then update your config to point to the local installation:
{
"mcpServers": {
"twitter-mcp": {
"command": "node",
"args": ["/path/to/twitter-mcp/build/index.js"],
"env": {
// ... your credentials
}
}
}
}
Restart Claude Desktop
Install the server globally and add it to Claude:
# For OAuth 1.0a
claude mcp add twitter-mcp "npx" "-y" "@mbelinky/x-mcp-server" --scope user \
--env "API_KEY=your_api_key" \
--env "API_SECRET_KEY=your_secret_key" \
--env "ACCESS_TOKEN=your_access_token" \
--env "ACCESS_TOKEN_SECRET=your_access_token_secret"
# For OAuth 2.0
claude mcp add twitter-mcp "npx" "-y" "@mbelinky/x-mcp-server" --scope user \
--env "AUTH_TYPE=oauth2" \
--env "OAUTH2_CLIENT_ID=your_client_id" \
--env "OAUTH2_CLIENT_SECRET=your_client_secret" \
--env "OAUTH2_ACCESS_TOKEN=your_access_token" \
--env "OAUTH2_REFRESH_TOKEN=your_refresh_token"
Once installed, Claude can use these tools:
post_tweet
Post a new tweet with optional media attachments and replies.
Example prompts:
search_tweets
Search for tweets with customizable result count (10-100).
Example prompts:
delete_tweet
Delete a tweet by its ID.
Example prompts:
Note: Due to temporary Twitter API issues, OAuth 1.0a uses v1.1 fallback for deletion.
When using Claude to post tweets with images:
Example usage:
# โ
Recommended for Claude
"Post tweet with image at /Users/me/photos/sunset.png"
# โ Not currently supported in Claude
"Post this image: [pasting an image directly]"
# โ
Works programmatically
// In code, you can still use base64
{
"text": "Hello world!",
"media": [{
"data": "iVBORw0KGgoAAAANS...",
"media_type": "image/png"
}]
}
The project includes comprehensive tests:
# Run all tests
npm test
# Run specific test suites
npm test -- --testNamePattern="OAuth"
npm test -- --testPathPattern="unit"
git clone https://github.com/mbelinky/x-mcp-server.git
cd x-mcp-server/twitter-mcp
npm install
npm run build # Build TypeScript
npm run dev # Run in development mode
npm test # Run tests
npm run lint # Lint code
npm run format # Format code
Create a .env
file for local development:
# OAuth 1.0a
API_KEY=your_api_key
API_SECRET_KEY=your_api_secret_key
ACCESS_TOKEN=your_access_token
ACCESS_TOKEN_SECRET=your_access_token_secret
# OAuth 2.0 (if using)
AUTH_TYPE=oauth2
OAUTH2_CLIENT_ID=your_client_id
OAUTH2_CLIENT_SECRET=your_client_secret
OAUTH2_ACCESS_TOKEN=your_access_token
OAUTH2_REFRESH_TOKEN=your_refresh_token
# Optional
DEBUG=true # Enable debug logging
Media uploads now work with both OAuth 1.0a and OAuth 2.0!
Note: OAuth 2.0 requires the media.write
scope for media uploads.
Twitter's v2 delete endpoint is currently experiencing issues (returning 500 errors). The MCP server handles this gracefully:
This is a temporary Twitter API issue. Once resolved, both auth methods will use v2 deletion.
"Could not authenticate you"
"Rate limit exceeded"
"Media upload failed"
media.write
scope is included"403 Forbidden"
Enable detailed logging by setting the DEBUG
environment variable:
{
"env": {
"DEBUG": "true",
// ... other credentials
}
}
%APPDATA%\Claude\logs\mcp-server-twitter.log
~/Library/Logs/Claude/mcp-server-twitter.log
Contributions are welcome! Please:
This MCP server:
Your tweets, searches, and media remain private between you and Twitter/X.
For security vulnerabilities, please email directly instead of creating a public issue.
MIT
This is an enhanced fork of @enescinar/twitter-mcp that adds:
Original implementation by @enescinar
A text-to-speech server using the Kokoro TTS model, configurable via environment variables.
Integrates with Mailtrap Email API.
Send SMS messages using the Aligo SMS API.
Interact with Slack workspaces to read and send messages directly through your AI assistant.
Interact with LinkedIn using an unofficial API, requiring email and password for authentication.
A news feed server for aggregating news from various sources.
Enables communication between an LLM and a user through an interactive Electron interface.
Send iMessage and SMS messages using the Sendblue API.
A Discord relay server to send messages and prompts to a channel and receive responses.
Fetch and interact with Hacker News content, including top stories, comments, and search functionality.