Twitter MCP 服务器
用于 Twitter API 集成的模型上下文协议服务器实现。
设置
克隆存储库
安装依赖项:
npm install将
.env.example复制到.env并填写您的 Twitter API 凭据构建项目:
npm run build启动服务器:
npm start
环境变量
.env中所需的 Twitter API 凭据:
可用工具
推文操作
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_nameAPI 错误:来自 Twitter API 的错误消息
未找到错误:针对资源的适当“未找到”消息
响应格式
所有成功的响应都遵循以下格式:
发展
构建:
npm run build开始:
npm start观察模式:
npm run dev
状态:运行正常 响应:返回推文ID 最新测试:成功
状态:运行正常响应:返回完整的推文数据最新测试:成功
状态:运行正常响应:确认操作最新测试:成功
状态:运行正常响应:确认操作最新测试:成功
状态:运行正常 响应:返回回复推文ID 最新测试:成功
状态:运行正常 响应:完成用户资料数据 最新测试:成功
状态:运行正常响应:确认操作最新测试:成功
状态:运行正常响应:确认列表创建最新测试:成功
状态:运行正常响应:返回拥有者和成员列表最新测试:成功
状态:错误 400 错误:请求参数无效 需要修复:参数验证
状态:错误 400 错误:请求参数无效 需要修复:查询参数格式
状态:错误 400 错误:请求参数无效 需要修复:参数验证
错误处理:
Related MCP Servers
- -securityFlicense-qualityProvides 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 -219
- -security-license-qualityA 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-license-qualityA 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 -210MIT License
- -security-license-qualityA 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 -1117MIT License