Twitter/X MCP Server
Connects AI assistants to Twitter/X using cookie-based authentication to read timelines, search tweets, and perform actions like posting and liking. It leverages Twitter's internal GraphQL API to provide full functionality without requiring a developer account.
README
Twitter/X MCP Server
A Model Context Protocol server that gives AI assistants full read/write access to Twitter/X through cookie-based authentication. No Developer account or OAuth app required.
Features
- 12 tools covering timelines, search, profiles, trends, posting, likes, retweets, and replies
- Cookie-based auth -- uses your browser session cookies, no Twitter API keys needed
- Dual-engine architecture -- fast HTTP via undici for reads, headless Puppeteer with stealth plugin for writes
- Anti-bot bypass -- puppeteer-extra-plugin-stealth avoids Twitter automation detection (error 226)
- Auto CSRF refresh -- ct0 tokens refreshed transparently when Twitter rotates them
- Clean JSON output -- nested GraphQL responses parsed into simple, structured objects
- Type-safe -- strict TypeScript with Zod schema validation on every tool input
- MCP standard -- works with Claude Desktop, Claude Code, and any MCP-compatible client
Prerequisites
- Node.js >= 18.0.0
- npm >= 8.0.0
- A Twitter/X account with an active browser session
Installation
git clone https://github.com/aditya-ai-architect/twitter-mcp.git
cd twitter-mcp
npm install
npm run build
Getting Your Twitter Cookies
- Open x.com and log in
- Open Developer Tools (F12)
- Go to Application > Cookies >
https://x.com - Copy these two values:
| Cookie | Description |
|---|---|
auth_token |
Session authentication token |
ct0 |
CSRF protection token |
Both cookies must come from the same active session.
Configuration
Environment Variables
| Variable | Required | Description |
|---|---|---|
TWITTER_AUTH_TOKEN |
Yes | The auth_token cookie value |
TWITTER_CT0 |
Yes | The ct0 cookie value |
Create a .env file in the project root:
TWITTER_AUTH_TOKEN=your_auth_token_here
TWITTER_CT0=your_ct0_here
Claude Desktop
Add to your Claude Desktop config:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"twitter": {
"command": "node",
"args": ["/absolute/path/to/twitter-mcp/build/index.js"],
"env": {
"TWITTER_AUTH_TOKEN": "your_auth_token_here",
"TWITTER_CT0": "your_ct0_here"
}
}
}
}
Claude Code
claude mcp add twitter -- node /absolute/path/to/twitter-mcp/build/index.js
Tools
Read Operations
| Tool | Description |
|---|---|
get_home_timeline |
Fetch tweets from the authenticated user's home timeline |
get_user_profile |
Get a user profile by username |
get_user_tweets |
Get recent tweets from a specific user |
get_tweet |
Get a single tweet by ID |
search_tweets |
Search tweets with full operator support |
get_trends |
Get current trending topics |
Write Operations
| Tool | Description |
|---|---|
post_tweet |
Post a new tweet |
like_tweet |
Like a tweet |
unlike_tweet |
Remove a like |
retweet |
Retweet a tweet |
unretweet |
Remove a retweet |
reply_to_tweet |
Reply to a specific tweet |
Architecture
MCP Client (Claude) <--stdio--> twitter-mcp Server
|
+---------------+---------------+
| |
undici HTTP Puppeteer + Stealth
(Read ops) (Write ops)
| |
+---------------+---------------+
|
x.com GraphQL API
Read operations use direct HTTP for speed. Write operations use a headless browser with stealth to bypass automation detection.
Development
npm run dev # Watch mode
npm run build # Build once
npm start # Run the server
Project Structure
twitter-mcp/
src/
index.ts # MCP server setup and tool registration
twitter-client.ts # Twitter API client (HTTP + Puppeteer)
types.ts # TypeScript interfaces
build/ # Compiled output
package.json
tsconfig.json
Troubleshooting
| Issue | Solution |
|---|---|
| HTTP 401/403 | Cookies expired -- extract fresh ones from browser |
| HTTP 429 | Rate limited -- wait a few minutes |
| Error 226 | Stealth browser handles this; if persistent, post manually once then retry |
| Empty responses | Twitter may have rotated GraphQL query IDs |
Tech Stack
- Runtime: Node.js (ES2022)
- Language: TypeScript 5.x (strict mode)
- MCP SDK: @modelcontextprotocol/sdk
- HTTP Client: undici
- Browser: Puppeteer + puppeteer-extra-plugin-stealth
- Validation: Zod
License
ISC
Built by Aditya Gaurav
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.