x-mcp
An MCP server that provides AI agents with full access to the X (Twitter) API for posting, searching, and managing engagement through natural language. It supports comprehensive tools for tweet management, media uploads, and account analytics across multiple MCP-compatible clients.
README
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.
OpenAI Codex
Option A: CLI
codex mcp add x-twitter --env X_API_KEY=your_consumer_key --env X_API_SECRET=your_secret_key --env X_ACCESS_TOKEN=your_access_token --env X_ACCESS_TOKEN_SECRET=your_access_token_secret --env X_BEARER_TOKEN=your_bearer_token -- node /ABSOLUTE/PATH/TO/x-mcp/dist/index.js
Option B: config.toml
Add to ~/.codex/config.toml (global) or .codex/config.toml (project-scoped):
[mcp_servers.x-twitter]
command = "node"
args = ["/ABSOLUTE/PATH/TO/x-mcp/dist/index.js"]
[mcp_servers.x-twitter.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"
Windsurf
Add to ~/.codeium/windsurf/mcp_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"
}
}
}
}
You can also add it from Windsurf Settings > Cascade > MCP Servers.
Cline (VS Code)
Open Cline's MCP settings (click the MCP Servers icon in Cline's top nav > Configure), then add to cline_mcp_settings.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"
},
"alwaysAllow": [],
"disabled": false
}
}
}
Other MCP Clients
This is a standard stdio MCP server. For any MCP-compatible client, point it at:
node /ABSOLUTE/PATH/TO/x-mcp/dist/index.js
With these environment variables: X_API_KEY, X_API_SECRET, X_ACCESS_TOKEN, X_ACCESS_TOKEN_SECRET, X_BEARER_TOKEN.
Troubleshooting
403 "oauth1-permissions" error when posting
Your Access Token was generated before you enabled write permissions. Go to the X Developer Portal, ensure App permissions are set to "Read and write", then Regenerate your Access Token and Secret.
401 Unauthorized
Double-check that all 5 credentials in your .env are correct and that there are no extra spaces or line breaks.
429 Rate Limited
The error message includes exactly when the rate limit resets. Wait until then, or reduce request frequency.
Server shows "Connected" but tools aren't used
Make sure you added the server with the correct scope (user/global, not project-scoped if you want it everywhere), then restart your client.
Rate Limiting
Every response includes rate limit info: remaining requests, total limit, and reset time. When a limit is hit, you get a clear error with the exact reset timestamp.
Pagination
List endpoints return a next_token in the response. Pass it back to get the next page of results. Works on: search_tweets, get_timeline, get_mentions, get_followers, get_following.
Search Query Syntax
The search_tweets tool supports X's full query language:
from:username-- posts by a specific userto:username-- replies to a specific user#hashtag-- posts containing a hashtag"exact phrase"-- exact text matchhas:media/has:links/has:images-- filter by content typeis:reply/-is:retweet-- filter by post typelang:en-- filter by language- Combine with spaces (AND) or
OR
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。