Package Exports
- @promptordie/xmcpx
- @promptordie/xmcpx/build/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@promptordie/xmcpx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Enhanced Twitter MCP Server ๐
A fully consolidated Model Context Protocol (MCP) server that provides comprehensive Twitter integration with smart cookie management and persistent authentication for ElizaOS and other MCP-compatible clients.
๐ Key Features
๐ Smart Authentication System
- Persistent Cookie Management: Automatically captures, validates, and reuses authentication cookies
- Self-Healing Authentication: Falls back to credentials when cookies expire, then saves new cookies
- Rate Limit Prevention: Avoids repeated logins by intelligently managing session persistence
- Multi-Method Support: Cookie-based, credential-based, and hybrid authentication modes
๐ฆ Complete Twitter Operations
- โ Tweet Management: Post, search, like, retweet, quote tweet
- โ User Operations: Follow, unfollow, get profiles, search users
- โ Timeline Access: Home timeline, user timelines, search results
- โ Advanced Features: Thread posting, media uploads, DMs
- โ Grok Integration: Chat with Twitter's Grok AI
- โ Health Monitoring: Built-in health checks and status monitoring
๐ก๏ธ Rate Limiting & Reliability
- Smart Session Management: Maintains long-lived authenticated sessions
- Automatic Recovery: Handles session expiration gracefully
- Request Optimization: Minimizes authentication overhead
- Error Resilience: Robust error handling and retry mechanisms
๐ Quick Start
1. Installation
# Clone the repository
cd /root/twitter-mcp-consolidated
# Install dependencies
npm install
# Build the TypeScript project
npm run build2. Configuration
Copy the example environment file:
cp .env.example .envEdit .env with your Twitter credentials:
# For first-time setup (credentials will be used once to get cookies)
AUTH_METHOD=credentials
TWITTER_USERNAME=your_twitter_username
TWITTER_PASSWORD=your_twitter_password
TWITTER_EMAIL=your_email@example.com
# Or use existing cookies directly
AUTH_METHOD=cookies
TWITTER_COOKIES=["auth_token=your_token; Domain=.twitter.com", "ct0=your_ct0; Domain=.twitter.com", "twid=your_twid; Domain=.twitter.com"]3. Run the Server
Choose your preferred mode:
# Standard MCP server
npm start
# Enhanced server with smart authentication
npm run start:enhanced
# Development mode with hot reload
npm run dev๐ Authentication Flow
Smart Authentication Process
- Cookie Check: First attempts to use saved cookies from previous sessions
- Cookie Validation: Verifies cookies are still valid and functional
- Credential Fallback: If cookies fail, uses username/password to authenticate
- Cookie Capture: Automatically extracts and saves new session cookies
- Future Sessions: Subsequent runs use the saved cookies for instant authentication
Benefits
- Zero Rate Limits: After first login, no repeated authentication requests
- Instant Startup: Cached sessions allow immediate Twitter operations
- Automatic Maintenance: Handles cookie expiration and renewal seamlessly
- Production Ready: Designed for long-running agent deployments
๐ ๏ธ Usage with ElizaOS
Add to your ElizaOS configuration:
{
"mcpServers": {
"twitter-enhanced": {
"command": "node",
"args": ["/root/twitter-mcp-consolidated/build/index.js"],
"env": {
"AUTH_METHOD": "credentials",
"TWITTER_USERNAME": "your_username",
"TWITTER_PASSWORD": "your_password",
"TWITTER_EMAIL": "your_email@example.com"
}
}
}
}Or use the enhanced server:
{
"mcpServers": {
"twitter-enhanced": {
"command": "node",
"args": ["/root/twitter-mcp-consolidated/enhanced-server.js"]
}
}
}๐ Available Tools
Core Twitter Operations
tweet- Post a tweetsearch_tweets- Search for tweetsget_user_timeline- Get user's timelinelike_tweet- Like a tweetretweet- Retweet a tweetfollow_user- Follow a userunfollow_user- Unfollow a userget_user_profile- Get user profile informationsearch_users- Search for users
Advanced Features
post_thread- Post a Twitter threadquote_tweet- Quote tweet with commentget_home_timeline- Get home timelinesend_direct_message- Send DM (if available)chat_with_grok- Chat with Grok AIupload_media- Upload media files
System Tools
health_check- Check server health and authentication statusget_auth_status- Get detailed authentication informationclear_auth_data- Clear saved authentication datare_authenticate- Force re-authentication
๐ง Configuration Options
Environment Variables
# Authentication
AUTH_METHOD=cookies|credentials
TWITTER_USERNAME=your_username
TWITTER_PASSWORD=your_password
TWITTER_EMAIL=your_email
TWITTER_COOKIES=JSON_array_of_cookies
# Server Settings
LOG_LEVEL=info|debug|warn|error
PORT=3001
DISABLE_HTTP_SERVER=false
# Smart Authentication Features
ENABLE_SMART_AUTHENTICATION=true
AUTO_SAVE_COOKIES=true
COOKIE_VALIDATION_ENABLED=true
# Rate Limiting
MAX_REQUESTS_PER_MINUTE=30
REQUEST_RETRY_DELAY=2000
# Security
SESSION_TIMEOUT=3600000
AUTO_LOGOUT_ON_ERROR=false๐งช Testing
# Run all tests
npm test
# Test MCP interface
npm run test:interface
# Test cookie functionality
npm run test:cookies
# Lint code
npm run lint๐ Monitoring & Health
The server includes comprehensive health monitoring:
# Check server status
curl http://localhost:3001/health
# Get authentication status
curl http://localhost:3001/auth-statusExample health response:
{
"status": "healthy",
"authentication": {
"authenticated": true,
"method": "cookies",
"hasSavedCookies": true,
"cookiesValid": true
},
"uptime": 3600,
"version": "1.0.0"
}๐จ Troubleshooting
Common Issues
Authentication Failed
# Clear saved data and re-authenticate
npm run clear-auth
# Update credentials in .env and restartCookies Expired
- The system automatically handles this
- Check logs for re-authentication messages
- Verify credentials are still correct
Rate Limiting
- Check if cookies are being used properly
- Verify
ENABLE_SMART_AUTHENTICATION=true - Review authentication logs
Debug Mode
Enable detailed logging:
DEBUG_AUTHENTICATION=true
DEBUG_COOKIES=true
VERBOSE_LOGGING=true
LOG_LEVEL=debug๐ Security
- Credential Protection: Store credentials securely using environment variables
- Cookie Encryption: Cookies are stored securely in environment
- Session Management: Automatic session timeout and cleanup
- Rate Limiting: Built-in protection against API abuse
- Error Handling: Secure error messages without credential exposure
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
๐ License
MIT License - see LICENSE file for details
๐โโ๏ธ Support
- Issues: Report bugs and request features via GitHub Issues
- Discussions: Join community discussions
- Documentation: Full API documentation in
/docs
Enhanced Twitter MCP Server - The most comprehensive and reliable Twitter MCP implementation with smart authentication and persistent sessions.