twscrape Twitter/X (read-only)

io.github.jsilets由 GitHub 账号 jsilets 发布v0.1.6更新于 Nov 8, 2026

Read-only X/Twitter MCP: posts, threads, replies, search via twscrape. No API key.

概览

AI 生成的概览

只读的 X/Twitter MCP 服务器,让助手用你自己的已登录会话读取帖子、长推串、回复、引用、时间线和搜索结果。

可以做什么
  • 以整洁的 Markdown 读取单条帖子,含图片、视频和外链
  • 读取某条帖子的长推串、回复和引用推文
  • 列出某用户最近的帖子,可选择包含其回复
  • 使用 from:、has:media、min_faves: 等运算符搜索 X
  • 查看用户资料,包括简介、位置、关注与粉丝数及注册时间
适用场景
适合让助手调研或总结公开的 X 讨论、跟踪某个账号的最新帖子,或在不购买 X API、不申请开发者账号的情况下获取某条帖子的回复与引用。
运行要求
以 Python 包形式通过 uv tool install 或 pipx 本地安装并以 stdio 运行(也列出 uvx)。需要一次性认证:启动专用 Chrome/Brave 配置登录 X、附加到带调试端口的独立 Chromium 配置,或通过隐藏提示输入 auth_token 与 ct0 cookie。可选环境变量用于数据目录、账号数据库、代理、CDP 地址、默认结果数量和 HTTP bearer 令牌。
安装前请注意
它复用你自己的 X 会话,任何能访问已暴露 HTTP 端点的人都能借此使用该会话;对外提供 HTTP 前务必设置 TWSCRAPE_TWITTER_MCP_AUTH_TOKEN。会话 cookie 会保存在磁盘上,托管部署时需传输该文件。以此方式读取 X 可能违反 X 的服务条款,账号可能被限流或封禁,建议使用小号。浏览器调试端口会暴露浏览器数据。引用推文覆盖不完整,搜索结果也随会话而异。

安装

在 SourceWeft 中

  1. 打开 控制台中的 twscrape Twitter/X (read-only),将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

twscrape-twitter-mcp

[PyPI] [CI] [Python] [License: MIT] [MCP]

An MCP server that reads X (Twitter): posts, threads, replies, quotes, and search. It wraps twscrape and uses your own logged-in session, so there's no paid X API and no developer account. Tools return clean markdown shaped for an agent to read, including image, video, and GIF URLs and any external links in a post.

Works with any MCP client over the two standard transports — local stdio and hosted Streamable HTTP.

Tools

ToolReturns
read_tweet(url_or_id)One post as markdown.
read_thread(url_or_id, max_replies=50)Root post + the author's self-thread + top replies.
read_replies(url_or_id, limit=50)Replies to a post.
read_quotes(url_or_id, limit=30)Quote-tweets (best-effort, search-based).
user_timeline(username, limit=40, include_replies=False)A user's recent posts, newest first. Set include_replies=True to include replies.
search(query, limit=20, product="Latest")Search results. Supports from:, has:media, min_faves:, etc.
user_profile(username)A user's profile as markdown: bio, location, follower/following/tweet counts, join date.

Install

bash
uv tool install twscrape-twitter-mcp     # or: pipx install twscrape-twitter-mcp

Then authenticate once (next section) and verify:

bash
twscrape-twitter-mcp smoke               # reads one public tweet end-to-end

Authenticate

Reads run against your own X session. Pick one path:

1. Launch a dedicated browser (recommended). Opens a separate Chrome/Brave profile with a DevTools port, you sign in to X once, and the session is captured. It does not touch your daily browser or automate X's login flow.

bash
twscrape-twitter-mcp login --launch-browser chrome   # or: brave

2. Attach to a dedicated browser profile. Only use this when you already run an isolated Chromium profile with a debug port. Browser debugging exposes browser data, and recent Chrome versions do not enable it for the default profile.

bash
# macOS"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222 --user-data-dir=/tmp/x-mcp-browser# Linux:   google-chrome --remote-debugging-port=9222 --user-data-dir=/tmp/x-mcp-browser# Windows: "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir=%TEMP%\x-mcp-browser
twscrape-twitter-mcp login --attach                  # add --cdp-url for a non-default port

3. Headless / CI (raw cookies). A server can't open your desktop browser, so add a session from auth_token + ct0 cookies. Run this without cookie flags to enter values through hidden prompts, rather than leaving secrets in shell history:

bash
twscrape-twitter-mcp init

The captured session is reused across restarts. Run login --launch-browser chrome again when it expires, or to add burner sessions for rate-limit rotation. twscrape-twitter-mcp accounts lists the pool.

Use burner accounts, not your main — see Legal.

Connect your client

The server runs locally over stdio. Most MCP clients take a JSON block like this:

json
{  "mcpServers": {    "x": {      "command": "twscrape-twitter-mcp",      "args": ["serve", "--transport", "stdio"]    }  }}

Client-specific equivalents:

Claude Code
bash
claude mcp add x --scope user -- twscrape-twitter-mcp serve --transport stdio
Claude Desktop

Add the JSON block above to claude_desktop_config.json (Settings → Developer → Edit Config).

Codex — ~/.codex/config.toml
toml
[mcp_servers.x]command = "twscrape-twitter-mcp"args = ["serve", "--transport", "stdio"]
Cursor — ~/.cursor/mcp.json
json
{  "mcpServers": {    "x": {      "command": "twscrape-twitter-mcp",      "args": ["serve", "--transport", "stdio"]    }  }}
VS Code — .vscode/mcp.json
json
{  "servers": {    "x": {      "command": "twscrape-twitter-mcp",      "args": ["serve", "--transport", "stdio"]    }  }}
Remote (Streamable HTTP)

For a hosted private instance (see Deploy), point a preconfigured client at the HTTP endpoint with a bearer token. This is static bearer auth, not an OAuth sign-in flow.

json
{  "mcpServers": {    "x": {      "url": "https://YOUR-APP.example.com/mcp",      "headers": { "Authorization": "Bearer YOUR_TOKEN" }    }  }}

Then ask, e.g. "read this thread: <url>".

Deploy

Run the server always-on and reachable over HTTP (POST /mcp). It ships as a container; Cloudflare Workers won't work because twscrape is Python with native deps.

A headless container can't open your desktop browser, so authenticate locally first (login --attach writes storage_state.json under TWSCRAPE_TWITTER_MCP_HOME), then ship that session to the host — copy the file to the mounted volume, or run the cookie-based init over SSH. The server reloads a persisted session on boot.

Always set a token when exposing HTTP — anyone who can reach the endpoint can use your X session:

bash
export TWSCRAPE_TWITTER_MCP_AUTH_TOKEN=$(openssl rand -hex 32)
Fly.io
bash
fly launch --no-deployfly volumes create twscrape_twitter_mcp_data --size 1fly secrets set TWSCRAPE_TWITTER_MCP_AUTH_TOKEN=$(openssl rand -hex 32)fly deploy# seed a session onto the volume through hidden prompts:fly ssh console -C "twscrape-twitter-mcp init"
Railway

Point Railway at this repo (it reads railway.json + Dockerfile), add a volume mounted at /data, set TWSCRAPE_TWITTER_MCP_AUTH_TOKEN, and seed a session via the Railway shell with twscrape-twitter-mcp init.

Clients send Authorization: Bearer <token>.

Configuration

Env varDefaultPurpose
TWSCRAPE_TWITTER_MCP_HOME~/.config/twscrape-twitter-mcpWhere the sqlite account pool lives. Point at a volume in prod.
TWSCRAPE_TWITTER_MCP_DB$TWSCRAPE_TWITTER_MCP_HOME/accounts.dbOverride the pool path directly.
TWSCRAPE_TWITTER_MCP_AUTH_TOKEN(unset)Required bearer token for HTTP transport.
TWSCRAPE_TWITTER_MCP_PROXY(unset)Global proxy for every account.
TWSCRAPE_TWITTER_MCP_CDP_URLhttp://127.0.0.1:9222Browser DevTools endpoint for login --attach.
TWSCRAPE_TWITTER_MCP_DEFAULT_LIMIT40Default timeline and search result count (1–100).
PORT8080HTTP port (Railway injects this).

How it works

The hard part of reading X — GraphQL signing, the x-client-transaction-id header, TLS fingerprinting — lives entirely in twscrape, which is pinned. This package is a read-only MCP layer on top and never touches that machinery. When X changes something and reads break, the fix is a version bump, not reverse-engineering.

Limits

  • X can expire, rate-limit, or suspend the account behind your session.
  • Protected, deleted, geo-blocked, or otherwise restricted posts may not be readable.
  • Quote-tweet coverage is search-based and incomplete.
  • Search results depend on X's current search behavior and can vary by session.
  • It does not decrypt browser cookie stores — use browser attach or cookie init.

Legal

Reading X with your own logged-in session may violate X's Terms of Service, and accounts used for scraping can be rate-limited or suspended. Use burner accounts, not your main. Provided as-is for research and personal use; you are responsible for how you use it.

License

MIT.

Credits

The hard scraping work is twscrape by vladkens. This is a read-only MCP layer on top — go star it.

来源:README.md,提交 dabefb8

工具

8

auth_status

Auth Status

Check whether this server has an active X session, without exposing cookies.

无需输入参数。

read_tweet

Read Tweet

Read a single X post by URL or numeric id. Returns clean markdown.

输入参数url_or_id必填

user_profile

User Profile

Read an X user's profile by handle. Returns clean markdown. Pass the handle with or without a leading @.

输入参数username必填

read_thread

Read Thread

Read a full X thread as markdown: the root post, the author's self-thread, and top replies. Pass any tweet in the thread.

输入参数url_or_id必填max_repliesinclude_replies

read_replies

Read Replies

Read the replies to an X post as markdown.

输入参数limiturl_or_id必填

read_quotes

Read Quotes

Read quote-tweets of an X post (best-effort, via search:quoted_tweet_id). Coverage is partial, X does not expose a complete quotes endpoint.

输入参数limiturl_or_id必填

user_timeline

User Timeline

Read a user's recent posts as markdown, newest first. Pass the handle with or without a leading @. Set include_replies=True to include the user's replies alongside their standalone posts.

输入参数limitusername必填include_replies

版本历史

1
  1. v0.1.2Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分