Twitter数据检索服务器

一个使用twikit的只读Twitter MCP服务器,可从Claude Code或Claude Desktop检索Twitter数据。

  • by somakai-sumasi
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 somakai-sumasi/twitter_mcp

使用说明

推特MCP服务器

日语版在这里

使用twikit的只读Twitter MCP服务器。从克劳德代码或克劳德桌面检索推特数据。

设置

cd <project-root>
uv sync
python scripts/patch_twikit.py

注: PyPI的twikit自2025-02年以来一直未发布,而X一直在更改其响应。补丁脚本应用上游修复程序(仍未合并 d60/twikit)需要保持此MCP工作: itemContent 防御性通道(#375),新 ondemand.s webpack格式 X-Client-Transaction-Id (#408/#409), User legacy.* 现场警卫和转换 SearchTimeline 从GET到POST(#412/#419).每次之后重新运行 uv sync 直到上游发布修复程序。

身份验证(cookies.json)

twikit登录API被Cloudflare阻止,因此使用浏览器cookie。

在浏览器中登录x.com,将Cookie导出为JSON,并另存为 cookies.json 在项目根中。支持浏览器导出格式(数组)和twikit格式(dict)。

使用克劳德代码注册

claude mcp add twitter-mcp -- uv run --directory <project-root> python -m twitter_mcp.server

在Claude Desktop注册

添加 mcpServers 在 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "twitter-mcp": {
    "command": "uv",
    "args": ["run", "--directory", "<project-root>", "python", "-m", "twitter_mcp.server"]
  }
}

重新启动Claude Desktop以应用。

可用工具

工具 说明 参数
search_tweets 按关键字搜索推文 query, product(热门/最新/媒体), count
get_user_info 获取用户资料 screen_name
get_user_tweets 获取用户的推文 user_id, tweet_type(推特/回复/媒体/点赞), count
get_tweet 获取一条推文 tweet_id
get_tweet_replies 获取推文的回复 tweet_id, count
get_timeline 回家时间表 count
get_latest_timeline 获取最新时间线 count
get_trends 获取趋势 category(趋势/为您/新闻/体育/娱乐)

测试

uv run python test_login.py