Purpose
x-mcp-server is a Model Context Protocol (MCP) server that connects X (formerly Twitter) operations such as posting, searching, and deleting to AI clients that support MCP. It is an enhanced fork of @enescinar/twitter-mcp, adding OAuth 2.0 support, v2 API media uploads, and rate limit protection for the free tier.
Key capabilities
- Post tweets: create text tweets, optionally with media (images, GIFs), and also support replying to a specified tweet.
- Search tweets: search X by keyword, with a customizable number of results (10–100).
- Delete tweets: programmatically delete your own tweets by tweet ID.
- Dual authentication: supports both OAuth 1.0a and OAuth 2.0.
- Media upload: upload images using the corresponding API version based on the authentication method.
- Rate limiting: built-in protection against X API limits.
- Type safety: full TypeScript implementation with Zod validation.
API version handling
The server intelligently selects the X API version based on the authentication method and operation type:
- OAuth 1.0a: tweet operations use v2 endpoints; media uploads use the v1.1 endpoint (upload.twitter.com); deletion automatically falls back to v1.1 when v2 fails.
- OAuth 2.0: all operations use only v2 endpoints; media uploads use the v2 endpoint (api.x.com/2/media/upload); fallback to v1.1 is not possible due to authentication limitations.
Usage
Prerequisites: an X developer account (developer.x.com), an app created in the developer portal with API credentials obtained, and Node.js 18+.
App configuration: create a project and app in the developer portal, enable OAuth 1.0a and/or OAuth 2.0 under "User authentication settings", set permissions to "Read and write", and set the callback URL to http://localhost:3000/callback,并设置网站 URL.
OAuth 1.0a credentials: API_KEY, API_SECRET_KEY, ACCESS_TOKEN, ACCESS_TOKEN_SECRET; the access token must have read and write permissions.
OAuth 2.0 credentials: OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET, OAUTH2_ACCESS_TOKEN, OAUTH2_REFRESH_TOKEN, and set AUTH_TYPE=oauth2. A user token can be generated using the script included in the repository:
git clone https://github.com/mbelinky/x-mcp-server.git
cd x-mcp-server/twitter-mcp
npm install
node scripts/oauth2-setup.js
The manual approach requires the OAuth 2.0 flow with PKCE, and the required scopes are tweet.read, tweet.write, users.read, media.write, offline.access.
Claude Desktop installation (NPM recommended): edit the configuration file (Windows: %APPDATA%\Claude\claude_desktop_config.json; macOS: ~/Library/Application Support/Claude/claude_desktop_config.json) and add:
{
"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 configuration, replace env with AUTH_TYPE, OAUTH2_CLIENT_ID, OAUTH2_CLIENT_SECRET, OAUTH2_ACCESS_TOKEN, OAUTH2_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 change command in the configuration to node, with args pointing to the local build/index.js path. Restart Claude Desktop after making the changes. Claude Code (CLI) can install this server globally and then add it to Claude.
Use cases
Suitable for users who want to directly manage X account content through MCP clients such as Claude, for example having the AI post tweets on their behalf, publish with images, search tweets by keyword, delete specified tweets, etc.
Limitations and known issues
- Media upload: Claude cannot extract base64 from pasted images; it is recommended to save the image to disk and provide the file path; the base64 method remains available for programmatic use and other MCP clients.
- Deleting tweets: X's v2 delete endpoint currently has an issue of returning a 500 error; OAuth 1.0a automatically falls back to v1.1, while OAuth 2.0 cannot fall back and will display an error message.
- Rate limits: X's free tier has strict limits; when exceeded, you need to wait about 15 minutes or upgrade the access level.
- Media limits: images up to 5MB, only JPEG, PNG, GIF supported; OAuth 2.0 requires the media.write scope.
- Privacy: credentials are stored only locally, no sensitive information is logged, and communication occurs only with X.