Labsco
crazyrabbitLTC logo

X (Twitter)

β˜… 25

from crazyrabbitLTC

Integrate with the X (Twitter) API for workflow automation, enhanced error handling, and real-time documentation.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedPaid serviceAdvanced setup

ChatGPT Image May 30, 2025, 03_20_40 PM

X (Twitter) MCP Server

A comprehensive Model Context Protocol server implementation for X (Twitter) API integration with professional workflow automation, enhanced error handling, and real-time documentation.

πŸš€ Features

  • 53 Total Tools - 33 Twitter API + 20 enhanced SocialData.tools research capabilities
  • Advanced Analytics - Thread analysis, network mapping, sentiment analysis, viral tracking
  • Bypasses API Restrictions - Enhanced research tools work without Pro tier requirements
  • Professional Error Handling - Clear upgrade guidance and graceful API key handling
  • 5 Workflow Prompts - Pre-built automation templates
  • 6 Dynamic Resources - Real-time API documentation and status
  • Full MCP Compliance - Tools, prompts, and resources support

πŸ› οΈ Available Tools (53 Total)

🐦 Twitter API Tools (33 tools)

βœ… Tweet Operations (All Working)

  • postTweet - Post new tweets
  • getTweetById - Retrieve specific tweets
  • replyToTweet - Reply to tweets
  • deleteTweet - Delete your tweets

βœ… Engagement (All Working)

  • likeTweet / unlikeTweet - Like/unlike tweets
  • retweet / undoRetweet - Retweet/undo retweets
  • getRetweets - Get retweet users

βœ… User Management (Most Working)

  • getUserInfo - Get user profiles βœ…
  • getUserTimeline - Get user tweets βœ…
  • followUser / unfollowUser - Follow/unfollow users βœ…
  • getFollowers - Get followers ⚠️ (403 - requires special permissions)
  • getFollowing - Get following ⚠️ (403 - requires special permissions)

βœ… List Management (All Working)

  • createList - Create X (Twitter) lists
  • getUserLists - Get user's lists
  • addUserToList / removeUserFromList - Manage list members
  • getListMembers - Get list members

⚠️ Search & Analytics (Limited)

  • searchTweets - Search tweets (requires Pro tier - $5,000/month)
  • getHashtagAnalytics - Hashtag analytics (requires Pro tier)
  • getLikedTweets - Get liked tweets (API access issue)

πŸ” SocialData.tools Enhanced Research (20 tools)

Note: These tools gracefully handle missing API keys with helpful setup instructions

πŸ”Ž Advanced Search (6 tools)

  • advancedTweetSearch - Complex queries with operators, bypasses API tier restrictions
  • historicalTweetSearch - Access historical tweets beyond standard API limits
  • trendingTopicsSearch - Real-time trend analysis and popular content discovery
  • bulkUserProfiles - Multi-user profile analysis in single requests
  • userGrowthAnalytics - User growth pattern analysis over time
  • userInfluenceMetrics - Engagement scoring and influence calculations

🧡 Thread & Conversation Analysis (3 tools)

  • getFullThread - Reconstruct complete Twitter threads with engagement metrics
  • getConversationTree - Map conversation structure including replies and quotes
  • getThreadMetrics - Thread performance analysis and engagement distribution

🌐 Network Analysis (3 tools)

  • findMutualConnections - Discover mutual connections via interactions
  • analyzeFollowerDemographics - Follower patterns and demographic analysis
  • mapInfluenceNetwork - Influence mapping and connection strength analysis

πŸ“ˆ Advanced Analytics (3 tools)

  • getHashtagTrends - Hashtag performance tracking over time with trend analysis
  • analyzeSentiment - Sentiment analysis with keyword frequency tracking
  • trackVirality - Viral spread patterns and engagement velocity analysis

πŸ“± Direct Messages & Moderation (5 tools)

  • Various DM and user moderation tools

πŸ§ͺ Testing SocialData.tools Integration

Test Enhanced Research Tools

Copy & paste β€” that's it
# Test advanced tweet search (bypasses Twitter API Pro tier requirement)
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

# Test user influence metrics
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "userInfluenceMetrics", "arguments": {"username": "openai"}}}' | node dist/index.js

# Test thread analysis
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "getFullThread", "arguments": {"tweetId": "1234567890123456789"}}}' | node dist/index.js

Test Without API Key

Copy & paste β€” that's it
# These will show helpful setup instructions instead of errors
SOCIALDATA_API_KEY="" echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "advancedTweetSearch", "arguments": {"query": "test"}}}' | node dist/index.js

πŸ†š When to Use Which Tools

Twitter API vs SocialData.tools Comparison

Use CaseTwitter API ToolSocialData.tools AlternativeAdvantage
Basic SearchsearchTweets ⚠️ (Pro tier $5k/month)advancedTweetSearch βœ…Bypasses API restrictions
User AnalysisgetUserInfo βœ…userInfluenceMetrics βœ…Enhanced analytics
Historical DataLimited by API tierhistoricalTweetSearch βœ…Access older tweets
Sentiment AnalysisNot availableanalyzeSentiment βœ…Built-in sentiment scoring
Thread AnalysisManual reconstructiongetFullThread βœ…Automated thread mapping
Network MappingNot availablemapInfluenceNetwork βœ…Connection analysis
Hashtag TrendsgetHashtagAnalytics ⚠️ (Pro tier)getHashtagTrends βœ…No tier restrictions

Recommended Workflow

  1. Start with Twitter API tools for posting, engagement, and basic operations
  2. Use SocialData.tools for research, analytics, and advanced insights
  3. Combine both for comprehensive Twitter automation and analysis

🎯 MCP Workflow Prompts

Our server includes 5 professional workflow templates:

1. Tweet Composition (compose-tweet)

Interactive guidance for creating engaging tweets with hashtags, mentions, and media.

2. Analytics Reporting (analytics-report)

Comprehensive X (Twitter) analytics workflow for business insights.

3. Content Strategy (content-strategy)

Strategic content planning and audience engagement workflows.

4. Community Management (community-management)

Customer service and community engagement best practices.

5. Hashtag Research (hashtag-research)

Industry-specific hashtag research and trend analysis.

πŸ“Š Dynamic Resources

Real-time information accessible via MCP:

  • API Rate Limits - Live usage monitoring
  • Access Level Status - Current tier capabilities
  • Tool Status Report - Working vs limited tools
  • Quick Start Guide - Getting started documentation
  • Workflow Templates - Pre-built automation examples
  • User Profile Data - Dynamic user information (live API calls)

πŸ§ͺ Testing

Manual Testing

Copy & paste β€” that's it
# Test working tools
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "postTweet", "arguments": {"text": "Hello from MCP!"}}}' | node dist/index.js

# Test user info
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "getUserInfo", "arguments": {"username": "elonmusk"}}}' | node dist/index.js

# Test limited tools (will show upgrade guidance)
source .env && echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "searchTweets", "arguments": {"query": "MCP"}}}' | node dist/index.js

Test Results Summary

  • 18 Tools Working on Basic tier
  • 4 Tools Limited by API tier/permissions
  • Professional error messages with upgrade guidance
  • All core functionality operational

πŸ”§ Integration Examples

MCP Client (Cursor/Claude)

Copy & paste β€” that's it
{
  "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"
      }
    }
  }
}

Direct JSON-RPC

Copy & paste β€” that's it
# Always source environment first
source .env

# List all tools
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' | node dist/index.js

# Call specific tool
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "toolName", "arguments": {"param": "value"}}}' | node dist/index.js

πŸ“ API Documentation

Tweet Operations

postTweet

Copy & paste β€” that's it
{
  "text": "Your tweet content (up to 280 characters)"
}

getTweetById

Copy & paste β€” that's it
{
  "tweetId": "1234567890123456789",
  "tweetFields": ["created_at", "public_metrics", "author_id"]
}

replyToTweet

Copy & paste β€” that's it
{
  "tweetId": "1234567890123456789", 
  "text": "Your reply content"
}

User Operations

getUserInfo

Copy & paste β€” that's it
{
  "username": "elonmusk",
  "fields": ["description", "public_metrics", "profile_image_url"]
}

followUser

Copy & paste β€” that's it
{
  "username": "target_username"
}

Engagement

likeTweet

Copy & paste β€” that's it
{
  "tweetId": "1234567890123456789"
}

retweet

Copy & paste β€” that's it
{
  "tweetId": "1234567890123456789"
}

🚨 Error Handling

Professional Error Messages

Our enhanced error handling provides:

  • Clear API tier explanations for limited tools
  • Upgrade pricing information ($5,000/month Pro tier)
  • Direct upgrade links to Twitter Developer Portal
  • Alternative solution suggestions

Example error response:

Copy & paste β€” that's it
{
  "error": "This endpoint requires X (Twitter) API Pro tier access ($5,000/month). Visit https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve to upgrade your access level."
}

πŸ“ Project Structure

Copy & paste β€” that's it
twitter-server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ handlers/          # API endpoint handlers
β”‚   β”œβ”€β”€ prompts.ts        # MCP workflow prompts  
β”‚   β”œβ”€β”€ resources.ts      # Dynamic MCP resources
β”‚   └── index.ts          # Main MCP server
β”œβ”€β”€ dist/                 # Compiled JavaScript
β”œβ”€β”€ scripts/              # Documentation & PRD
└── package.json

πŸ”„ Development

Build & Run

Copy & paste β€” that's it
npm run build    # Compile TypeScript
npm start        # Start production server
npm run dev      # Development mode with watch

Adding New Tools

  1. Add handler function in appropriate src/handlers/ file
  2. Register tool in src/index.ts
  3. Add documentation to this README
  4. Test with JSON-RPC calls

Contributing

  1. Follow existing code patterns
  2. Add proper error handling with professional messages
  3. Test with both working and failing scenarios
  4. Update documentation

πŸ“Š Current Status

  • 53 Total Tools: 33 Twitter API + 20 SocialData.tools enhanced research
  • Advanced Analytics: Thread analysis, network mapping, sentiment analysis, viral tracking
  • Graceful API Key Handling: Enhanced tools show helpful setup instructions when API key missing
  • Bypasses API Restrictions: Research tools work without Twitter Pro tier requirements
  • Professional Error Handling: Clear upgrade guidance and user-friendly messages
  • Full MCP Compliance: Tools, prompts, resources
  • Production Ready: Enhanced reliability, comprehensive analytics, and excellent UX

Built with ❀️ using the Model Context Protocol and SocialData.tools integration