Skip to main content
Glama

Twitter MCP Server

Twitter MCP 服务器

用于 Twitter API 集成的模型上下文协议服务器实现。

设置

  1. 克隆存储库
  2. 安装依赖项: npm install
  3. .env.example复制到.env并填写您的 Twitter API 凭据
  4. 构建项目: npm run build
  5. 启动服务器: npm start

环境变量

.env中所需的 Twitter API 凭据:

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

可用工具

推文操作

  • postTweet :发布新推文
    { "text": "Your tweet text here" }
  • postTweetWithMedia :发布带有媒体附件的推文
    { "text": "Your tweet text", "mediaPath": "path/to/media/file", "mediaType": "image/jpeg|image/png|image/gif|video/mp4", "altText": "Optional alt text for accessibility" }
  • getTweetById :通过 ID 获取特定推文
    { "tweetId": "tweet_id", "tweetFields": ["created_at", "public_metrics"] }
  • replyToTweet :回复现有推文
    { "tweetId": "tweet_id", "text": "Your reply text" }
  • deleteTweet :删除推文
    { "tweetId": "tweet_id" }

搜索与分析

  • searchTweets :搜索推文
    { "query": "search query", "maxResults": 10, "tweetFields": ["created_at", "public_metrics"] }
  • getHashtagAnalytics :获取主题标签的分析数据
    { "hashtag": "hashtag", "startTime": "ISO-8601 date", "endTime": "ISO-8601 date" }

用户操作

  • getUserInfo :获取用户信息
    { "username": "twitter_username", "fields": ["description", "public_metrics"] }
  • getUserTimeline :获取用户的推文
    { "username": "twitter_username", "maxResults": 10, "tweetFields": ["created_at", "public_metrics"] }
  • getFollowers :获取用户的关注者
    { "username": "twitter_username", "maxResults": 100, "userFields": ["description", "public_metrics"] }
  • getFollowing :获取用户关注的帐户
    { "username": "twitter_username", "maxResults": 100, "userFields": ["description", "public_metrics"] }

订婚

  • likeTweet :喜欢一条推文
    { "tweetId": "tweet_id" }
  • unlikeTweet :与推文不同
    { "tweetId": "tweet_id" }
  • retweet :转发一条推文
    { "tweetId": "tweet_id" }
  • undoRetweet :撤消转发
    { "tweetId": "tweet_id" }
  • getRetweets :获取转发推文的用户
    { "tweetId": "tweet_id", "maxResults": 100, "userFields": ["description", "public_metrics"] }
  • getLikedTweets :获取用户喜欢的推文
    { "userId": "user_id", "maxResults": 100, "tweetFields": ["created_at", "public_metrics"] }

列表管理

  • createList :创建新列表
    { "name": "List name", "description": "List description", "isPrivate": false }
  • addUserToList :将用户添加到列表
    { "listId": "list_id", "username": "twitter_username" }
  • removeUserFromList :从列表中删除用户
    { "listId": "list_id", "username": "twitter_username" }
  • getListMembers :获取列表成员
    { "listId": "list_id", "maxResults": 100, "userFields": ["description", "public_metrics"] }

错误处理

所有工具都返回标准化的错误响应:

  • 缺少参数: Missing required parameter: parameter_name
  • API 错误:来自 Twitter API 的错误消息
  • 未找到错误:针对资源的适当“未找到”消息

响应格式

所有成功的响应都遵循以下格式:

{ "content": [ { "type": "text", "text": "Operation result message" } ] }

发展

  • 构建: npm run build
  • 开始: npm start
  • 观察模式: npm run dev
Here's a comprehensive status report of all Twitter tools: ## Working Tools (✓) 1. postTweet

状态:运行正常 响应:返回推文ID 最新测试:成功

2. getTweetById

状态:运行正常响应:返回完整的推文数据最新测试:成功

3. likeTweet & unlikeTweet

状态:运行正常响应:确认操作最新测试:成功

4. retweet & undoRetweet

状态:运行正常响应:确认操作最新测试:成功

5. replyToTweet

状态:运行正常 响应:返回回复推文ID 最新测试:成功

6. getUserInfo

状态:运行正常 响应:完成用户资料数据 最新测试:成功

7. followUser & unfollowUser

状态:运行正常响应:确认操作最新测试:成功

8. createList

状态:运行正常响应:确认列表创建最新测试:成功

9. getUserLists

状态:运行正常响应:返回拥有者和成员列表最新测试:成功

## Tools with Issues (⚠️) 1. getUserTimeline

状态:错误 400 错误:请求参数无效 需要修复:参数验证

2. searchTweets

状态:错误 400 错误:请求参数无效 需要修复:查询参数格式

3. getLikedTweets

状态:错误 400 错误:请求参数无效 需要修复:参数验证

## Missing Tools (❌) - getHomeTimeline (not found in available tools) - getFollowers (not available) - getFollowing (not available) - getHashtagAnalytics (not available) ## Priority Fixes Needed 1. Parameter Validation: ```typescript // Implement for getUserTimeline, searchTweets, getLikedTweets interface TwitterParamValidator { validateTimelineParams(params: any): boolean; validateSearchParams(params: any): boolean; validateLikedTweetsParams(params: any): boolean; }
  1. 错误处理:
// Enhance error handling for 400 errors interface TwitterErrorHandler { handle400Error(endpoint: string, params: any): void; logErrorDetails(error: any): void; suggestParameterFixes(params: any): string[]; }
-
security - not tested
A
license - permissive license
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

通过模型上下文协议实现与 Twitter 的交互,允许大型语言模型发布推文、搜索推文和回复推文。

  1. 设置
    1. 环境变量
      1. 可用工具
        1. 推文操作
        2. 搜索与分析
        3. 用户操作
        4. 订婚
        5. 列表管理
      2. 错误处理
        1. 响应格式
          1. 发展

            Related MCP Servers

            • -
              security
              F
              license
              -
              quality
              Provides AI agents with comprehensive Twitter functionality through the Model Context Protocol standard, enabling reading tweets, posting content, managing interactions, and accessing timeline data with robust error handling.
              Last updated -
              4
              1
              JavaScript
              • Apple
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol server that enables AI to interact with Twitter, allowing functions like searching tweets, comparing sentiments across accounts, and retrieving timeline content.
              Last updated -
              MIT License
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol server that enables AI models and applications to interact directly with Twitter/X, providing capabilities to create posts, reply to tweets, retrieve user data, and manage account actions.
              Last updated -
              87
              4
              TypeScript
              MIT License
            • -
              security
              A
              license
              -
              quality
              A Model Context Protocol server that enables AI agents to interact with Twitter without direct API access, supporting tweet operations, user interactions, and Grok AI integration.
              Last updated -
              5
              2
              TypeScript
              MIT License
              • Apple

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/crazyrabbitLTC/mcp-twitter-server'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server