Twitter MCP Server

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.

Integrations

  • Uses environment variables from .env files to store Twitter API credentials securely

  • Uses npm for dependency management and running build/development scripts

  • Uses TypeScript for implementation of parameter validation and error handling

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

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

  1. Setup
    1. Environment Variables
      1. Available Tools
        1. Tweet Operations
        2. Search & Analytics
        3. User Operations
        4. Engagement
        5. List Management
      2. Error Handling
        1. Response Format
          1. Development
            ID: qlfiuj6xn6