x-mcp
An MCP (Model Context Protocol) server that gives AI agents full access to the X (Twitter) API. Post tweets, search, read timelines, like, retweet, upload media -- all through natural language.
Works with Claude Code, Claude Desktop, OpenAI Codex, Cursor, Windsurf, Cline, and any other MCP-compatible client.
If you're an LLM/AI agent helping a user set up this project, read `LLMs.md` for step-by-step instructions you can walk the user through.
What Can It Do?
| Category | Tools | What You Can Say |
|---|---|---|
| Post | post_tweet, reply_to_tweet, quote_tweet, delete_tweet |
"Post 'hello world' on X" / "Reply to this tweet saying thanks" |
| Read | get_tweet, search_tweets, get_timeline, get_mentions |
"Show me @elonmusk's latest posts" / "Search for tweets about MCP" |
| Users | get_user, get_followers, get_following |
"Look up @openai" / "Who does this user follow?" |
| Engage | like_tweet, retweet |
"Like that tweet" / "Retweet this" |
| Media | upload_media |
"Upload this image and post it with the caption..." |
| Analytics | get_metrics |
"How many impressions did my last post get?" |
Accepts tweet URLs or IDs interchangeably -- paste https://x.com/user/status/123 or just 123.
Setup
1. Clone and build
git clone https://github.com/INFATOSHI/x-mcp.git
cd x-mcp
npm install
npm run build
2. Get your X API credentials
You need 5 credentials from the X Developer Portal. Here's exactly how to get them:
a) Create an app
- Go to the X Developer Portal
- Sign in with your X account
- Go to Apps in the left sidebar
- Click Create App (you may need to sign up for a developer account first)
- Give it a name (e.g.,
my-x-mcp) - You'll immediately see your Consumer Key (API Key), Secret Key (API Secret), and Bearer Token
- Save all three now -- the secret won't be shown again
b) Enable write permissions
By default, new apps only have Read permissions. You need Read and Write to post tweets, like, retweet, etc.
- In your app's page, scroll down to User authentication settings
- Click Set up
- Set App permissions to Read and write
- Set Type of App to Web App, Automated App or Bot
- Set Callback URI / Redirect URL to
https://localhost(required but won't be used) - Set Website URL to any valid URL (e.g.,
https://x.com) - Click Save
c) Generate access tokens (with write permissions)
After enabling write permissions, you need to generate (or regenerate) your Access Token and Secret so they carry the new permissions:
- Go back to your app's Keys and Tokens page
- Under Access Token and Secret, click Regenerate
- Save both the Access Token and Access Token Secret
If you skip step (b) before generating tokens, your tokens will be Read-only and posting will fail with a 403 error.
3. Configure credentials
Copy the example env file and fill in your 5 credentials:
cp .env.example .env
Edit .env:
X_API_KEY=your_consumer_key
X_API_SECRET=your_secret_key
X_BEARER_TOKEN=your_bearer_token
X_ACCESS_TOKEN=your_access_token
X_ACCESS_TOKEN_SECRET=your_access_token_secret
Connect to Your Client
Pick your client below. You only need to follow one section.
Claude Code
claude mcp add --scope user x-twitter -- node /ABSOLUTE/PATH/TO/x-mcp/dist/index.js
Replace /ABSOLUTE/PATH/TO/x-mcp with the actual path where you cloned the repo. Then restart Claude Code.
Claude Desktop
Add to your claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"x-twitter": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/x-mcp/dist/index.js"],
"env": {
"X_API_KEY": "your_consumer_key",
"X_API_SECRET": "your_secret_key",
"X_ACCESS_TOKEN": "your_access_token",
"X_ACCESS_TOKEN_SECRET": "your_access_token_secret",
"X_BEARER_TOKEN": "your_bearer_token"
}
}
}
}
Cursor
Add to your Cursor MCP config:
- Global (all projects):
~/.cursor/mcp.json - Project-scoped:
.cursor/mcp.jsonin your project root
{
"mcpServers": {
"x-twitter": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/x-mcp/dist/index.js"],
"env": {
"X_API_KEY": "your_consumer_key",
"X_API_SECRET": "your_secret_key",
"X_ACCESS_TOKEN": "your_access_token",
"X_ACCESS_TOKEN_SECRET": "your_access_token_secret",
"X_BEARER_TOKEN": "your_bearer_token"
}
}
}
}
You can also verify the connection in Cursor Settings > MCP Servers.
Ope
Tools 15
post_tweetPost a new tweet to Xreply_to_tweetReply to an existing tweetquote_tweetQuote an existing tweetdelete_tweetDelete a tweet by IDget_tweetRetrieve details of a specific tweetsearch_tweetsSearch for tweets based on a queryget_timelineFetch the user's timelineget_mentionsFetch mentions of the userget_userLook up user profile informationget_followersGet a list of followers for a userget_followingGet a list of users followed by a userlike_tweetLike a specific tweetretweetRetweet a specific tweetupload_mediaUpload media to Xget_metricsGet engagement metrics for a postEnvironment Variables
X_API_KEYrequiredConsumer Key from X Developer PortalX_API_SECRETrequiredSecret Key from X Developer PortalX_BEARER_TOKENrequiredBearer Token from X Developer PortalX_ACCESS_TOKENrequiredAccess Token from X Developer PortalX_ACCESS_TOKEN_SECRETrequiredAccess Token Secret from X Developer Portal