关于 Twitter MCP Server
Twitter MCP Server 是基于 twikit 的非官方 Twitter/X 交互服务,面向希望通过 MCP 操作社交账号的用户。它支持 cookie 认证,并提供推文、用户、趋势和私信相关操作。
主要功能
- 01使用 cookie 认证并缓存会话
- 02读取时间线、用户资料和推文
- 03搜索、发布、点赞和转发推文
- 04关注用户并查看趋势
- 05发送和管理私信
适用场景
- 01搜索推文并查看用户动态
- 02发布推文或互动
- 03查看趋势主题
- 04发送私信并管理对话
MCP 相关
该服务通过 MCP 工具提供 Twitter/X 的推文、用户、趋势及私信操作;调用时需提供 ct0 和 auth_token cookie。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Twitter MCP 服务
一个使用 twikit 库提供 Twitter 功能的模型上下文协议(MCP)服务。该服务支持 AI 助手通过标准化协议与 Twitter 交互,并采用基于 Cookie 的身份验证——LLM 模型会在工具调用中直接提供 ct0 和 auth_token Cookie。
功能
- Cookie 身份验证:LLM 模型会在工具调用中直接提供
ct0和auth_tokenCookie - 会话缓存:自动缓存已验证的会话,提高效率
- 时间线访问:获取时间线中的推文
- 用户信息:获取用户资料和统计数据
- 推文搜索:使用特定查询搜索推文
- 推文管理:发布、点赞和转发推文
- 用户推文:获取特定用户的推文
- 私信:发送私信、获取私信历史记录、对消息作出回应以及删除消息
- 身份验证测试:使用前测试 Cookie
- 推文操作:发布推文、点赞/取消点赞推文、转发/删除转发、收藏推文
- 推文获取:按 ID 获取推文、搜索推文、获取用户时间线、获取推文回复
- 用户操作:关注/取消关注用户、获取用户信息、搜索用户
- 热门话题:获取不同类别的热门话题(热门、新闻、体育、娱乐、为你推荐)
免责声明
本项目通过 twikit 库使用非官方 API 与 X(原 Twitter)交互。所采用的身份验证和数据获取方法未经 X/Twitter 官方认可,并且可能在不另行通知的情况下变更或停止提供。
本工具仅用于教育和实验目的。用户应了解使用非官方 API 可能带来的风险,包括但不限于账号受限或被封禁。本项目的开发者不对本工具的任何滥用行为或使用后果负责。
安装
- 克隆此仓库:
git clone <repository-url>
cd twitter-mcp
- 安装依赖项:
pip install -r requirements.txt
- 运行服务:
python server.py
身份验证
该服务要求 LLM 模型在每次工具调用中通过 ct0 和 auth_token 参数直接提供 Twitter Cookie。无需预先配置!
获取 Twitter Cookie
LLM 模型需要提供这两个 Twitter Cookie。获取方法如下:
- 打开浏览器并访问 Twitter/X
- 登录你的账号
- 打开开发者工具(F12)
- 转到 Application/Storage → Cookies → twitter.com(或 x.com)
- 找到并复制以下 Cookie 值:
ct0- CSRF 令牌 Cookieauth_token- 身份验证令牌 Cookie
所有操作都需要这两个 Cookie。
用法
可用工具
1. 身份验证
使用 Cookie 测试身份验证:
{
"tool": "authenticate",
"arguments": {
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
2. 推文
发布新推文:
{
"tool": "tweet",
"arguments": {
"text": "Hello from MCP! 🚀",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
3. 获取用户信息
获取 Twitter 用户的信息:
{
"tool": "get_user_info",
"arguments": {
"username": "elonmusk",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
4. 搜索推文
搜索推文:
{
"tool": "search_tweets",
"arguments": {
"query": "artificial intelligence",
"count": 10,
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
5. 获取时间线
获取时间线中的推文:
{
"tool": "get_timeline",
"arguments": {
"count": 20,
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
6. 点赞推文
按 ID 点赞推文:
{
"tool": "like_tweet",
"arguments": {
"tweet_id": "1234567890123456789",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
7. 转发
按 ID 转发推文:
{
"tool": "retweet",
"arguments": {
"tweet_id": "1234567890123456789",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
8. 发送私信
向用户发送私信。
参数:
recipient_username(字符串):要发送消息的用户名(不含 @;内部会自动转换为 user_id)text(字符串):消息内容ct0(字符串):Twitter ct0 Cookieauth_token(字符串):Twitter auth_token Cookie
{
"name": "send_dm",
"arguments": {
"recipient_username": "username",
"text": "Hello from MCP!",
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
9. 获取私信历史记录
获取与特定用户的私信历史记录。
参数:
recipient_username(字符串):要获取私信历史记录的用户名(不含 @;内部会自动转换为 user_id)count(整数,可选):要获取的消息数量(默认值:20,最大值:100)ct0(字符串):Twitter ct0 Cookieauth_token(字符串):Twitter auth_token Cookie
{
"name": "get_dm_history",
"arguments": {
"recipient_username": "username",
"count": 50,
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
10. 对私信添加表情回应
为一条私信添加表情回应。
参数:
message_id(string):要回应的消息 IDemoji(string):要添加的表情(例如,“👍”“❤️”“😀”)conversation_id(string):包含该消息的会话 IDct0(string):Twitter ct0 Cookieauth_token(string):Twitter auth_token Cookie
{
"name": "add_reaction_to_message",
"arguments": {
"message_id": "message_id_here",
"emoji": "👍",
"conversation_id": "conversation_id_here",
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
11. 删除私信
删除一条私信:
{
"tool": "delete_dm",
"arguments": {
"message_id": "1234567890123456789",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
get_tweet_replies
获取对特定推文的回复。
参数:
tweet_id(string):要获取回复的推文 IDcount(integer,可选):要获取的回复数量(默认值:20)ct0(string):Twitter ct0 Cookieauth_token(string):Twitter auth_token Cookie
{
"name": "get_tweet_replies",
"arguments": {
"tweet_id": "1234567890",
"count": 10,
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
get_trends
获取 Twitter 上的热门话题。
参数:
category(string,可选):要获取的热门话题类别(默认值:"trending")- 选项:"trending"、"for-you"、"news"、"sports"、"entertainment"
count(integer,可选):要获取的热门话题数量(默认值:20,最多:50)ct0(string):Twitter ct0 Cookieauth_token(string):Twitter auth_token Cookie
{
"name": "get_trends",
"arguments": {
"category": "trending",
"count": 20,
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
示例:
// Get general trending topics
{
"name": "get_trends",
"arguments": {
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
// Get sports trends
{
"name": "get_trends",
"arguments": {
"category": "sports",
"count": 10,
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
// Get personalized trends
{
"name": "get_trends",
"arguments": {
"category": "for-you",
"ct0": "your_ct0_token",
"auth_token": "your_auth_token"
}
}
可用资源
可以访问资源,但需要 TWITTER_CT0
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。