Twitter/X MCP

io.github.granitebps由 GitHub 帳號 granitebps 發布v1.1.0更新於 Oct 24, 2026

Read public X posts, replies, profiles, and search results through Rettiwt or the official API.

概覽

AI 產生的概覽

一個本機 MCP 伺服器,讓助理透過 Rettiwt 或官方 X API 讀取公開的 X 貼文、回覆與個人檔案,並搜尋 X。

可以做什麼
依數字 ID 或狀態連結取得單一貼文,在 Rettiwt 模式下還會附上供應商提供的媒體連結。取得某則貼文的回覆,可限制回傳數量並讀取分頁資訊。依使用者名稱查詢公開個人檔案,名稱前可帶 @。依關鍵字搜尋 X 貼文,可用的搜尋運算子取決於所選供應商。查看伺服器版本、目前供應商、工具、限制與能力。
適用情境
適合讓助理查詢公開的 X 內容,例如某則貼文、其回覆、某個使用者檔案或搜尋結果,而不必自行建置 API 整合。適用於唯讀的研究與監測,而非發文或帳號管理。
執行需求
以 stdio 方式在本機執行,通常透過 npx 啟動,需要 Node.js 22.21.0 或更新的 Node 22 版本;Node 24 可能產生警告,在 engine-strict 下會安裝失敗。預設的 Rettiwt 模式需要 RETTIWT_API_KEY。官方 API 模式以 TWITTER_MODE=api 選用,需要 TWITTER_BEARER_TOKEN 或完整的 OAuth 憑證。需要能連線至 X 的網路。
安裝前請注意
RETTIWT_API_KEY 包含 X 工作階段 Cookie,擁有與該帳號相同的存取權限,應像密碼一樣保管,不要寫進會提交的設定檔。Rettiwt 使用非官方端點,可能失效或使帳號面臨風險,且 X 規則禁止非 API 的自動化操作。官方 API 模式受 X 的存取層級與定價限制。此伺服器只讀取資料,不會發文。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Twitter/X MCP,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Twitter/X MCP

[CI] [npm version] [npm downloads] [MCP Registry] [License: ISC]

Twitter/X MCP lets an MCP client read public X posts, replies, and profiles, or search X. It uses Rettiwt by default, so you do not need an X developer plan. You can switch to the official X API if you have access.

Requirements

  • Node.js 22.21.0 or newer within the Node 22 release line is the declared supported runtime. Node 24 testing and installation limitations are described below.
  • A RETTIWT_API_KEY. Official X API credentials work when you select API mode.

Node 24 compatibility

The full project check and all five live MCP tool calls passed on Node.js 24.19.0. CI also runs the full project check on Node 24.

The published package and Rettiwt 7.1.4 still declare engines.node: "^22.21.0". Installing on Node 24 can therefore produce EBADENGINE warnings, and npm rejects the installation when engine-strict is enabled. Use Node 22.21.0 or a newer Node 22 release for installation within the declared supported range. Official Node 24 support remains pending a Rettiwt release that declares Node 24 compatibility and a corresponding update to this package's engine range.

Quick start

Once the package is published, your MCP client can run it without a clone:

bash
npx -y @granitebps/twitter-mcp

The server selects Rettiwt when you omit TWITTER_MODE. Pass RETTIWT_API_KEY in the client configuration.

The server uses stdio. Keep stdout reserved for MCP traffic.

Run from a cloned repository

To develop the server or use a clone directly:

bash
git clone https://github.com/granitebps/twitter-mcp.gitcd twitter-mcpnpm cinpm run build

Point your MCP client at the compiled entry point:

text
node /absolute/path/to/twitter-mcp/dist/cli.js

Run npm run build after each source change. Do not use src or npm run dev as the client's stdio command. Build logs on stdout can corrupt MCP messages.

Client configuration

Each example starts with the npm package, followed by the local equivalent. Replace /absolute/path/to/twitter-mcp with your clone's path and your_key_here with your Rettiwt key. Do not commit a configuration file that contains the key.

Claude

Add the npm package to Claude Code:

bash
claude mcp add twitter --env RETTIWT_API_KEY=your_key_here -- npx -y @granitebps/twitter-mcp

For a local build:

bash
claude mcp add twitter --env RETTIWT_API_KEY=your_key_here -- node /absolute/path/to/twitter-mcp/dist/cli.js

Claude Code uses local scope by default. Add --scope user before twitter to make the server available across projects.

Claude Desktop reads the same server from claude_desktop_config.json. Restart the app after editing the file.

json
{  "mcpServers": {    "twitter": {      "command": "npx",      "args": ["-y", "@granitebps/twitter-mcp"],      "env": {        "RETTIWT_API_KEY": "your_key_here"      }    }  }}

For a local build, replace command and args with:

json
{  "command": "node",  "args": ["/absolute/path/to/twitter-mcp/dist/cli.js"]}

Codex

Add the npm package to ~/.codex/config.toml, or to .codex/config.toml in a trusted project:

toml
[mcp_servers.twitter]command = "npx"args = ["-y", "@granitebps/twitter-mcp"]
[mcp_servers.twitter.env]RETTIWT_API_KEY = "your_key_here"

For a local build:

toml
[mcp_servers.twitter]command = "node"args = ["/absolute/path/to/twitter-mcp/dist/cli.js"]
[mcp_servers.twitter.env]RETTIWT_API_KEY = "your_key_here"

Restart Codex after editing the file. The CLI, IDE extension, and desktop app share this configuration on the same computer.

OpenCode

Add the npm package to opencode.json or opencode.jsonc:

json
{  "$schema": "https://opencode.ai/config.json",  "mcp": {    "twitter": {      "type": "local",      "command": ["npx", "-y", "@granitebps/twitter-mcp"],      "enabled": true,      "environment": {        "RETTIWT_API_KEY": "your_key_here"      }    }  }}

For a local build, replace the command array with:

json
{  "command": ["node", "/absolute/path/to/twitter-mcp/dist/cli.js"]}

Cursor

Add the npm package to .cursor/mcp.json in a project, or to ~/.cursor/mcp.json for global use:

json
{  "mcpServers": {    "twitter": {      "command": "npx",      "args": ["-y", "@granitebps/twitter-mcp"],      "env": {        "RETTIWT_API_KEY": "your_key_here"      }    }  }}

For a local build, replace command and args with:

json
{  "command": "node",  "args": ["/absolute/path/to/twitter-mcp/dist/cli.js"]}

Providers

ModeSelectionCredentialsNotes
RettiwtDefault, or TWITTER_MODE=rettiwtRETTIWT_API_KEYFree of X API charges. Uses unofficial internal endpoints and may break or put the account at risk.
Official APITWITTER_MODE=apiBearer token or complete OAuth credentialsUses the supported X API. X controls access tiers and pricing.

Rettiwt setup

Rettiwt requires authenticated user mode in this server. Guest mode is not supported.

  1. Generate an API key using the Rettiwt authentication instructions.
  2. Store it as RETTIWT_API_KEY in the MCP client's environment.
  3. Start the server without TWITTER_MODE, or set TWITTER_MODE=rettiwt explicitly.

A Rettiwt key contains X session cookies and has the same access as the account. Treat it like a password. Do not commit it, paste it into an issue, log it, or pass it as a command-line argument. Use a key only for an account you own or have permission to access.

Rettiwt is unofficial. X's automation rules prohibit non-API website automation and warn that violations may lead to account suspension. Read the X Rules before using this mode. You accept the compliance and account risk.

Official X API setup

Use a bearer token:

env
TWITTER_MODE=apiTWITTER_BEARER_TOKEN=your_bearer_token

Or provide the complete OAuth set:

env
TWITTER_MODE=apiTWITTER_API_KEY=your_api_keyTWITTER_API_SECRET=your_api_secretTWITTER_ACCESS_TOKEN=your_access_tokenTWITTER_ACCESS_SECRET=your_access_secret

Create credentials in the X Developer Portal. X controls API access and pricing, so check the current terms before choosing this mode.

Configuration

VariableRequiredMeaning
TWITTER_MODENorettiwt by default, or api. Other values fail startup.
RETTIWT_API_KEYRettiwt modeAuthenticated Rettiwt session key.
TWITTER_BEARER_TOKENAPI mode optionOfficial API bearer token.
TWITTER_API_KEYOAuth optionOAuth application key.
TWITTER_API_SECRETOAuth optionOAuth application secret.
TWITTER_ACCESS_TOKENOAuth optionOAuth access token.
TWITTER_ACCESS_SECRETOAuth optionOAuth access secret.
TWITTER_REQUEST_TIMEOUT_MSNoRequest deadline from 1,000 to 120,000 ms. Default: 30,000.

The server rejects an incomplete OAuth configuration at startup. It reads credentials from the process environment and never returns them through get_server_info.

Tools

ToolInputResult
get_tweettweet_idOne post. Accepts a numeric ID or an x.com or twitter.com status URL.
get_tweet_repliestweet_id, optional max_resultsReplies and available page metadata.
get_user_profileusernameOne public profile. A leading @ is accepted.
search_tweetsquery, optional max_resultsMatching posts and available page metadata. Search operators depend on the provider.
get_server_infoNoneVersion, active provider, tools, limits, and capabilities.

max_results defaults to 10 and accepts 1 through 100. Successful calls return structured MCP content plus JSON text for older clients. Collection tools return the items as JSON text and put cursors and warnings in structured content.

In Rettiwt mode, posts returned by get_tweet, get_tweet_replies, and search_tweets also include an optional media array when the provider supplies it. Each item contains id, type (PHOTO, VIDEO, or GIF), a direct url, and an optional thumbnail_url for video previews. The server returns media links; it does not download the files. Official API mode does not currently return attached media.

The v1 compatibility contract records the stable tool, input, output, and error behavior for the 1.x release line.

Errors

Tool failures use stable codes:

  • INVALID_INPUT
  • AUTH_REQUIRED
  • AUTH_FAILED
  • NOT_FOUND
  • RATE_LIMITED
  • UPSTREAM_UNAVAILABLE
  • TIMEOUT
  • UNSUPPORTED_OPERATION
  • INTERNAL_ERROR

Errors name the provider and tell the client whether a retry may work. They do not include credentials or raw upstream response bodies.

Architecture

text
stdio CLI  -> validated environment configuration  -> MCP server and tool handlers  -> TwitterProvider contract       -> Rettiwt adapter       -> official X API adapter

The domain schemas do not depend on either provider. Each provider adapter maps upstream data, enforces limits and deadlines, and translates errors. Importing src/index.ts does not start the server.

Development

bash
npm cinpm run check

npm run check checks formatting, lint, types, coverage, the production build, npm package contents, and a clean tarball installation. The default test suite uses fakes and does not need X credentials.

Useful focused commands:

bash
npm testnpm run typechecknpm run lintnpm run buildnpm run check:packagenpm run check:installnpx @modelcontextprotocol/inspector node dist/cli.js

Live Rettiwt smoke test

The live smoke test starts the compiled stdio server and calls get_tweet, get_tweet_replies, get_user_profile, and search_tweets. It derives the username and search query from the selected post.

bash
RETTIWT_API_KEY=your_key_here \TWITTER_LIVE_TWEET_ID=1234567890123456789 \npm run test:live

Choose a public post whose author profile is still available. If either variable is missing, the command stops before starting the live server or making a network request. It does not run as part of npm run check or normal CI.

Release verification

The automated suite covers configuration, provider adapters, MCP calls, the compiled stdio entry point, and installation from an npm tarball. The live Rettiwt smoke test is optional and does not run in normal CI. Version 1.0.0 was prepared without live upstream verification.

Maintainers can follow the release guide for the approved-tag npm, MCP Registry, and GitHub release process. Live tests must read credentials from repository secrets and must not run for untrusted pull requests.

Troubleshooting

Missing Rettiwt key

If startup reports RETTIWT_API_KEY is required in rettiwt mode, set the key in the MCP client configuration. Desktop clients do not automatically inherit a shell's .env file.

Invalid Rettiwt authentication

If you see Invalid authentication data or AUTH_FAILED, generate a new Rettiwt key and check that the X session still works. Never post the failing key in an issue.

Rate limit

For RATE_LIMITED, wait before retrying and reduce the request rate. Check retryAfterSeconds when the provider supplies it.

Official API 401 or 403

Confirm the credential set, app permissions, endpoint access, and current X API plan.

Node engine warning

Run Node.js 22.21.0 or a newer Node 22 release to satisfy the package and Rettiwt engine ranges. Node 24.19.0 passed runtime testing, but installations on Node 24 can warn or fail under engine-strict; see Node 24 compatibility.

License

ISC

來源:README.md,提交 59ce82d

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

3
  1. v1.1.0最新Oct 8, 2026
  2. v1.0.3Oct 2, 2026
  3. v1.0.1Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分