Logo X (Twitter) MCP Server

X (Twitter) MCP Server

Cộng đồng
crazyrabbitLTC

Model Context Protocol Server for Accessing twitter

Nhà phát hànhcrazyrabbitLTC
Kho mãmcp-twitter-server
Ngôn ngữTypeScript
Bản fork
9
Sao
25
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    X (Twitter) MCP Server cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    25 sao và 9 bản fork từ kho mã được liên kết.

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

📋 Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • X (Twitter) API credentials (Basic tier minimum - $200/month)

Local Installation

  1. Clone and Install

    bash
    git clone <repository-url>
    cd twitter-server
    npm install
  2. Environment Setup

    bash
    cp .env.example .env
    # Edit .env with your credentials

    Required Environment Variables:

    env
    # 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  # Optional, uses default if not set
  3. Build and Run

    bash
    npm run build
    npm start
  4. Test the Server

    bash
    # 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

🔑 X (Twitter) API Setup

Required Credentials

Add these to your .env file:

env
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

API Access Levels

TierCostWorking ToolsLimited Tools
Basic$200/month18/22 toolssearchTweets, getHashtagAnalytics
Pro$5,000/monthAll 22 toolsNone

🛠️ 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

🔑 API Keys Setup

Twitter API (Required)

Get these from Twitter Developer Portal:

env
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 (Optional)

Enables 20 enhanced research tools that bypass Twitter API limitations:

  1. Sign up at SocialData.tools
  2. Get your API key from the dashboard
  3. Add to .env file:
    env
    SOCIALDATA_API_KEY=your_socialdata_api_key_here

Without SocialData API key: Enhanced research tools will show helpful setup instructions instead of errors.

🧪 Testing SocialData.tools Integration

Test Enhanced Research Tools

bash
# 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

bash
# 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

bash
# 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)

json
{
  "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

bash
# 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

json
{
  "text": "Your tweet content (up to 280 characters)"
}

getTweetById

json
{
  "tweetId": "1234567890123456789",
  "tweetFields": ["created_at", "public_metrics", "author_id"]
}

replyToTweet

json
{
  "tweetId": "1234567890123456789", 
  "text": "Your reply content"
}

User Operations

getUserInfo

json
{
  "username": "elonmusk",
  "fields": ["description", "public_metrics", "profile_image_url"]
}

followUser

json
{
  "username": "target_username"
}

Engagement

likeTweet

json
{
  "tweetId": "1234567890123456789"
}

retweet

json
{
  "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:

json
{
  "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

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

bash
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

📋 Known Limitations

API Tier Restrictions

  • searchTweets: Requires Pro tier ($5,000/month)
  • getHashtagAnalytics: Requires Pro tier
  • getFollowers/getFollowing: Requires special permissions (403 errors)
  • getLikedTweets: Parameter validation issues

Recommendations

  • Current Setup: Excellent for basic X (Twitter) automation
  • For Advanced Analytics: Consider Pro tier upgrade
  • For Followers/Following: Request elevated permissions

🆘 Troubleshooting

Common Issues

Error: "fetch is not defined"

bash
# Ensure Node.js 18+ 
node --version

403 Permission Errors

  • Check API credentials are correct
  • Verify account has required permissions
  • Some endpoints need special approval

400 Bad Request Errors

  • Review parameter formats
  • Check our enhanced error messages for guidance
  • Verify API tier supports the endpoint

Getting Help

  1. Check error messages - Our enhanced error handling provides clear guidance
  2. Review API documentation - X (Twitter) Developer Portal
  3. Test with working tools first - Verify basic setup
  4. Check environment variables - Ensure all credentials are set

📊 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

Cài đặt

TypingMind
{
  "mcpServers": {
    "mcp-twitter-server": {
      "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>"
      }
    }
  }
}

Dùng MCP X (Twitter) MCP Server với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối X (Twitter) MCP Server, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm X (Twitter) MCP Server làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của X (Twitter) MCP Server.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "mcp-twitter-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-twitter-server"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của X (Twitter) MCP Server, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của X (Twitter) MCP Server.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng X (Twitter) MCP Server giúp tôi làm việc này không?
X (Twitter) MCP Server
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng X (Twitter) MCP Server.

Câu hỏi thường gặp

Máy chủ MCP X (Twitter) MCP Server dùng để làm gì?

X (Twitter) MCP Server là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP X (Twitter) MCP Server với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng X (Twitter) MCP Server với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP X (Twitter) MCP Server với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối X (Twitter) MCP Server, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP X (Twitter) MCP Server với TypingMind?

X (Twitter) MCP Server hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP X (Twitter) MCP Server cung cấp những công cụ nào trong TypingMind?

X (Twitter) MCP Server cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP X (Twitter) MCP Server không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu X (Twitter) MCP Server yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇