This MCP server provides a comprehensive integration with X (Twitter) API, offering 53 tools for social media automation, analytics, and research. It combines standard Twitter API capabilities with enhanced research tools from SocialData.tools to bypass typical API restrictions.
Clone and Install
git clone <repository-url>
cd twitter-server
npm install
Environment Setup
cp .env.example .env
# Edit .env with your credentials
Required environment variables:
# Twitter API credentials (Required)
X_API_KEY=your_api_key_here
X_API_SECRET=your_api_secret_here
X_ACCESS_TOKEN=your_access_token_here
X_ACCESS_TOKEN_SECRET=your_access_token_secret_here
# SocialData.tools API key (Optional - enables enhanced research tools)
SOCIALDATA_API_KEY=your_socialdata_api_key_here
SOCIALDATA_BASE_URL=https://api.socialdata.tools
Build and Run
npm run build
npm start
Test the Server
# Test with JSON-RPC calls
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | node dist/index.js
# Test specific tool
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "getUserInfo", "arguments": {"username": "elonmusk"}}}' | node dist/index.js
Get these from Twitter Developer Portal:
X_API_KEY=your_api_key_here
X_API_SECRET=your_api_secret_here
X_ACCESS_TOKEN=your_access_token_here
X_ACCESS_TOKEN_SECRET=your_access_token_secret_here
Enables 20 enhanced research tools that bypass Twitter API limitations:
SOCIALDATA_API_KEY=your_socialdata_api_key_here
Without SocialData API key, enhanced research tools will show helpful setup instructions instead of errors.
postTweet
- Post new tweetsgetTweetById
- Retrieve specific tweetsreplyToTweet
- Reply to tweetsdeleteTweet
- Delete your tweetslikeTweet
/ unlikeTweet
- Like/unlike tweetsretweet
/ undoRetweet
- Retweet/undo retweetsgetRetweets
- Get retweet usersgetUserInfo
- Get user profilesgetUserTimeline
- Get user tweetsfollowUser
/ unfollowUser
- Follow/unfollow usersgetFollowers
- Get followers (requires special permissions)getFollowing
- Get following (requires special permissions)createList
- Create X (Twitter) listsgetUserLists
- Get user's listsaddUserToList
/ removeUserFromList
- Manage list membersgetListMembers
- Get list memberssearchTweets
- Search tweets (requires Pro tier - $5,000/month)getHashtagAnalytics
- Hashtag analytics (requires Pro tier)getLikedTweets
- Get liked tweets (API access issue)advancedTweetSearch
- Complex queries with operatorshistoricalTweetSearch
- Access historical tweetstrendingTopicsSearch
- Real-time trend analysisbulkUserProfiles
- Multi-user profile analysisuserGrowthAnalytics
- User growth pattern analysisuserInfluenceMetrics
- Engagement scoring and influence calculationsgetFullThread
- Reconstruct complete Twitter threadsgetConversationTree
- Map conversation structuregetThreadMetrics
- Thread performance analysisfindMutualConnections
- Discover mutual connectionsanalyzeFollowerDemographics
- Follower patterns analysismapInfluenceNetwork
- Influence mappinggetHashtagTrends
- Hashtag performance trackinganalyzeSentiment
- Sentiment analysistrackVirality
- Viral spread patterns analysis# Test user info
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "getUserInfo", "arguments": {"username": "elonmusk"}}}' | node dist/index.js
# Post a tweet
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "postTweet", "arguments": {"text": "Hello from MCP!"}}}' | node dist/index.js
# Test advanced tweet search
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "advancedTweetSearch", "arguments": {"query": "AI OR machine learning", "maxResults": 5}}}' | node dist/index.js
# Test sentiment analysis
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "analyzeSentiment", "arguments": {"query": "ChatGPT", "sampleSize": 20}}}' | node dist/index.js
{
"mcpServers": {
"x-twitter": {
"command": "node",
"args": ["/path/to/twitter-server/dist/index.js"],
"env": {
"X_API_KEY": "your_api_key",
"X_API_SECRET": "your_api_secret",
"X_ACCESS_TOKEN": "your_access_token",
"X_ACCESS_TOKEN_SECRET": "your_access_token_secret"
}
}
}
}
Error: "fetch is not defined"
node --version
403 Permission Errors
400 Bad Request Errors
Tier | Cost | Working Tools | Limited Tools |
---|---|---|---|
Basic | $200/month | 18/22 tools | searchTweets, getHashtagAnalytics |
Pro | $5,000/month | All 22 tools | None |
The SocialData.tools integration provides alternatives to many restricted features without requiring the Pro tier.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "x-twitter" '{"command":"node","args":["dist/index.js"],"env":{"X_API_KEY":"${X_API_KEY}","X_API_SECRET":"${X_API_SECRET}","X_ACCESS_TOKEN":"${X_ACCESS_TOKEN}","X_ACCESS_TOKEN_SECRET":"${X_ACCESS_TOKEN_SECRET}","SOCIALDATA_API_KEY":"${SOCIALDATA_API_KEY}"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"x-twitter": {
"command": "node",
"args": [
"dist/index.js"
],
"env": {
"X_API_KEY": "${X_API_KEY}",
"X_API_SECRET": "${X_API_SECRET}",
"X_ACCESS_TOKEN": "${X_ACCESS_TOKEN}",
"X_ACCESS_TOKEN_SECRET": "${X_ACCESS_TOKEN_SECRET}",
"SOCIALDATA_API_KEY": "${SOCIALDATA_API_KEY}"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"x-twitter": {
"command": "node",
"args": [
"dist/index.js"
],
"env": {
"X_API_KEY": "${X_API_KEY}",
"X_API_SECRET": "${X_API_SECRET}",
"X_ACCESS_TOKEN": "${X_ACCESS_TOKEN}",
"X_ACCESS_TOKEN_SECRET": "${X_ACCESS_TOKEN_SECRET}",
"SOCIALDATA_API_KEY": "${SOCIALDATA_API_KEY}"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect