X MCP Server

An MCP server that gives AI agents full access to the X (Twitter) API.

README.md

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
  1. Go to the X Developer Portal
  2. Sign in with your X account
  3. Go to Apps in the left sidebar
  4. Click Create App (you may need to sign up for a developer account first)
  5. Give it a name (e.g., my-x-mcp)
  6. You'll immediately see your Consumer Key (API Key), Secret Key (API Secret), and Bearer Token
  7. 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.

  1. In your app's page, scroll down to User authentication settings
  2. Click Set up
  3. Set App permissions to Read and write
  4. Set Type of App to Web App, Automated App or Bot
  5. Set Callback URI / Redirect URL to https://localhost (required but won't be used)
  6. Set Website URL to any valid URL (e.g., https://x.com)
  7. 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:

  1. Go back to your app's Keys and Tokens page
  2. Under Access Token and Secret, click Regenerate
  3. 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.json in 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 X
reply_to_tweetReply to an existing tweet
quote_tweetQuote an existing tweet
delete_tweetDelete a tweet by ID
get_tweetRetrieve details of a specific tweet
search_tweetsSearch for tweets based on a query
get_timelineFetch the user's timeline
get_mentionsFetch mentions of the user
get_userLook up user profile information
get_followersGet a list of followers for a user
get_followingGet a list of users followed by a user
like_tweetLike a specific tweet
retweetRetweet a specific tweet
upload_mediaUpload media to X
get_metricsGet engagement metrics for a post

Environment Variables

X_API_KEYrequiredConsumer Key from X Developer Portal
X_API_SECRETrequiredSecret Key from X Developer Portal
X_BEARER_TOKENrequiredBearer Token from X Developer Portal
X_ACCESS_TOKENrequiredAccess Token from X Developer Portal
X_ACCESS_TOKEN_SECRETrequiredAccess Token Secret from X Developer Portal

Try it

Post 'Hello world' on X.
Search for recent tweets about the Model Context Protocol.
Show me the latest posts from @elonmusk.
Like the tweet with ID 123456789.
How many impressions did my last post get?

Frequently Asked Questions

What are the key features of X MCP?

Full access to X API for posting, searching, and reading timelines.. Support for media uploads and tweet engagement (likes, retweets).. Account analytics and metrics retrieval.. User profile lookup and follower management.. Compatible with Claude Desktop, Cursor, and other MCP clients..

What can I use X MCP for?

Automating social media updates directly from an AI coding assistant.. Monitoring industry trends by searching X for specific keywords via AI.. Managing engagement by having an AI agent reply to mentions.. Analyzing post performance metrics without leaving the IDE..

How do I install X MCP?

Install X MCP by running: git clone https://github.com/INFATOSHI/x-mcp.git && cd x-mcp && npm install && npm run build

What MCP clients work with X MCP?

X MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep X MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Open Conare