Blog

How to Control Twitter with AI Using MCP (Claude, Cursor, GPT)

What if you could tell your AI assistant "Unfollow everyone who hasn't tweeted in 6 months" and it just... did it? That's what Model Context Protocol (MCP) enables. And with XActions, you can set it up in under 5 minutes.

What is MCP?

Model Context Protocol is an open standard (created by Anthropic) that lets AI assistants connect to external tools. Think of it as "USB for AI" — a universal plug that lets any AI client (Claude, Cursor, Windsurf) talk to any tool server (XActions, GitHub, databases, etc.).

Before MCP, if you wanted Claude to interact with Twitter, you'd need to:

  1. Write custom API integration code
  2. Handle authentication yourself
  3. Parse responses into a format Claude understands
  4. Deal with errors, rate limits, pagination...

With MCP, all of that is handled by the MCP server (XActions). You just install it, add one config line, and start talking to your AI in natural language.

What Can You Do?

XActions MCP server exposes 140+ tools to your AI assistant. Here are some examples:

"Scrape the profile of @elonmusk"
→ Returns followers, following, bio, join date, tweet count, verification status
"Unfollow everyone who doesn't follow me back"
→ Checks your following list, identifies non-followers, unfollows them one by one
"Find the top 10 tweets about AI from the last week"
→ Scrapes search results, ranks by engagement, returns summaries
"Draft a tweet thread about the future of open source"
→ Generates a multi-tweet thread matching your writing voice
"Download this video: [tweet URL]"
→ Extracts highest-quality MP4 and returns a download link

Setup: 3 Steps, 5 Minutes

Step 1: Prerequisites

Make sure you have Node.js 18+ installed. Check with:

node --version

Step 2: Set Your Auth Cookie

XActions needs your X/Twitter session cookie to act on your behalf. Get it from your browser:

  1. Go to x.com and make sure you're logged in
  2. Open DevTools (F12) → Application tab → Cookies → x.com
  3. Find the cookie named auth_token and copy its value

Set it as an environment variable:

# macOS/Linux
export X_AUTH_TOKEN="your_auth_token_here"

# Windows PowerShell
$env:X_AUTH_TOKEN="your_auth_token_here"
🔒 Security: Your auth token stays local. XActions runs entirely on your machine — nothing is sent to external servers.

Step 3: Add to Your AI Client

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "xactions": {
      "command": "npx",
      "args": ["-y", "xactions", "mcp"],
      "env": {
        "X_AUTH_TOKEN": "your_auth_token_here"
      }
    }
  }
}

Config file location:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Cursor

Add to .cursor/mcp.json in your project:

{
  "mcpServers": {
    "xactions": {
      "command": "npx",
      "args": ["-y", "xactions", "mcp"],
      "env": {
        "X_AUTH_TOKEN": "your_auth_token_here"
      }
    }
  }
}

Windsurf

Add to ~/.codeium/windsurf/mcp_config.json:

{
  "mcpServers": {
    "xactions": {
      "command": "npx",
      "args": ["-y", "xactions", "mcp"],
      "env": {
        "X_AUTH_TOKEN": "your_auth_token_here"
      }
    }
  }
}
💡 Pro tip: Use the XActions CLI to auto-generate the config: npx xactions mcp-config --client claude --write

Tool Categories

The 140+ tools are organized into categories:

  • Scraping — profiles, tweets, followers, following, search, hashtags, media
  • Actions — follow, unfollow, like, unlike, repost, post, reply, DM
  • Analytics — engagement rates, best time to post, sentiment analysis
  • Content — AI tweet writer, thread composer, voice analyzer
  • Account — detect unfollowers, audit followers, check shadowban
  • Export — JSON, CSV, bookmarks, media download

How It Works Under the Hood

When you say "scrape @elonmusk's profile" to Claude:

  1. Claude recognizes the intent and calls the x_scrape_profile MCP tool
  2. XActions MCP server receives the tool call and opens a Puppeteer browser
  3. Puppeteer navigates to x.com/elonmusk and scrapes the page using data-testid selectors
  4. XActions returns structured JSON data back through MCP
  5. Claude formats the data and presents it to you in natural language

All of this happens locally on your machine. No data leaves your computer except the normal browser requests to x.com.

Tips for Best Results

  • Be specific — "Unfollow the 50 accounts I followed most recently that don't follow me back" is better than "clean up my account"
  • Start small — test with read-only operations (scraping) before write operations (posting, unfollowing)
  • Check the output — always review what the AI did before moving on, especially for destructive actions
  • Use Claude's artifacts — ask Claude to format scraped data as tables or charts

Ready to give your AI full Twitter access?

XActions MCP server — 140+ tools, free, runs locally.