TwittrAPI

io.github.twittrapi由 GitHub 帳號 twittrapi 發布v1.2.0更新於 Nov 2, 2026

Read public Twitter/X data: tweets, profiles, followers, search. No X developer account.

已驗證Streamable HTTP可網頁執行網頁搜尋與抓取溝通與協作

概覽

AI 產生的概覽

TwittrAPI 的 MCP 伺服器,讓助理不需 X 開發者帳號就能讀取公開的 Twitter/X 資料:推文、個人檔案、追蹤者、搜尋、清單、社群與趨勢。

可以做什麼
  • 查詢帳號與關係:把帳號名稱解析為 ID、批次取得個人檔案、追蹤者、追蹤中、驗證追蹤者、關聯帳號及互相追蹤狀況
  • 讀取推文:使用者的推文、回覆與媒體,單一推文及其回覆串、轉推、引用、回覆,以及依 ID 批次取得
  • 以 X 搜尋語法檢索推文,並依 Top、Latest、People、Photos 或 Videos 篩選
  • 瀏覽清單、社群、X Space,以及依地區查詢熱門話題
  • 選用:設定 X 工作階段 Cookie 與代理後,可操作自己的帳號:發文、回覆、刪除、按讚、轉推、收藏、追蹤、傳送私訊、管理清單與草稿、處理 X Articles
適用情境
適合在聊天用戶端中讓助理調查或追蹤公開的 X 動態,例如帳號檔案、追蹤關係、推文串、關鍵字搜尋、趨勢或社群,且不必註冊 X 開發者應用程式。只有需要助理代你發文或管理自己的 X 帳號時,才值得啟用帳號工具。
執行需求
可使用遠端端點(託管伺服器,透過 OAuth 登入),或以 npx 在本機執行,需要 Node.js 20 或更新版本。需要 TwittrAPI 金鑰(TWITTRAPI_API_KEY),或已訂閱 Twitter AIO API 的 RapidAPI 金鑰(RAPIDAPI_KEY)。選用:TWITTRAPI_X_COOKIE 與 TWITTRAPI_X_PROXY 用於帳號工具,TWITTRAPI_X_CHAT_PASSCODE 用於傳送私訊。需要能連線至 TwittrAPI API 的網路。
安裝前請注意
每次工具呼叫都會在你的帳號上計費一次,批次工具則依每個帳號名稱各計一次;出現 402 表示餘額不足。帳號工具需要你已登入 x.com 的工作階段 Cookie(auth_token、ct0、twid)以及代理,屬於高敏感憑證;這些工具僅在 stdio 模式提供,HTTP 與託管模式不提供。寫入與刪除類工具會直接作用於你的真實帳號,執行前請先確認。金鑰與 Cookie 會傳送給 TwittrAPI。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 TwittrAPI,將其新增到工作區。
  2. 連接 所需的 憑證。它們會被私密儲存,絕不會在公開頁面上展示。
  3. 為需要使用其工具的對話啟用該服務。

Web executable,透過 Streamable HTTP。 遠端服務在工作區中設定後即可從網頁執行環境執行。

交給代理程式安裝

把這段提示詞貼上到 Claude Code、Codex、Cursor 等代理程式,或 SourceWeft 對話中。代理程式會讀取該伺服器的安裝指南,先向你展示發布者、端點和登入方式,經你同意後再把它新增到你的客戶端。金鑰不會寫進任何命令。

閱讀 https://sourceweft.com/mcp/io.github.twittrapi%2Ftwittrapi-mcp/install.md,並按其中說明把這個 MCP 伺服器接入我的客戶端。修改任何設定之前,先告訴我它的發布者、端點和登入方式,等我確認。不要把 API 金鑰寫進命令或我會提交的檔案;問我金鑰應從哪裡取得。

檢視代理程式所依據的安裝指南

其他 MCP 客戶端

把它新增到你客戶端的 mcpServers 設定中。 客戶端會在首次連接時完成 OAuth 登入。

{
  "mcpServers": {
    "twittrapi": {
      "type": "http",
      "url": "https://mcp.twittrapi.com/mcp"
    }
  }
}

README

[twittrapi-mcp: Twitter/X MCP server for AI agents, npx -y twittrapi-mcp]

twittrapi-mcp – Twitter/X MCP server for Claude, Cursor and other AI agents

[npm] [License: MIT]

An MCP server for TwittrAPI, a REST API for public Twitter/X data: tweets, profiles, followers, search, lists and communities. It lets Claude, Cursor and other MCP clients read that data, from $0.065 per 1,000 calls and with no X developer account.

Get an API key: twittrapi.com/start · Pricing · Docs · Status · also available on RapidAPI

SDKs and integrations: Python · Node.js · Go · n8n · Make · Apify · LangChain · LlamaIndex · Agent skill · Examples

Not affiliated with X Corp.

Hosted server (no install)

Apps that support remote MCP servers can connect by URL instead (available with the hosted release; see twittrapi.com/docs/hosted-mcp):

text
https://mcp.twittrapi.com/mcp
ClientSetup
Claude.ai / Claude DesktopSettings > Connectors > Add custom connector, paste the URL, Connect, log in to TwittrAPI and allow access (OAuth)
ChatGPTSettings > Apps & Connectors > Advanced settings > Developer mode, then Create with the URL and OAuth
Claude Codeclaude mcp add --transport http twittrapi https://mcp.twittrapi.com/mcp (OAuth), or add --header "Authorization: Bearer $TWITTRAPI_API_KEY"
Cursor{"mcpServers": {"twittrapi": {"url": "https://mcp.twittrapi.com/mcp", "headers": {"X-API-KEY": "${env:TWITTRAPI_API_KEY}"}}}} in mcp.json
VS Code{"servers": {"twittrapi": {"type": "http", "url": "https://mcp.twittrapi.com/mcp"}}} in .vscode/mcp.json (OAuth)

With OAuth the app never sees your API key; calls are billed to your balance like any other call. Connected apps are listed (and can be disconnected) in the dashboard under Connected apps.

What you need

  • Node.js 20 or newer
  • A TwittrAPI key, or a RapidAPI key subscribed to the Twitter AIO API

Every tool call is one billed API call on your account.

Install

Claude Code

sh
claude mcp add twittrapi --env TWITTRAPI_API_KEY=your-key -- npx -y twittrapi-mcp

Claude Desktop

Open Settings > Developer > Edit Config and add this to claude_desktop_config.json:

json
{  "mcpServers": {    "twittrapi": {      "command": "npx",      "args": ["-y", "twittrapi-mcp"],      "env": {        "TWITTRAPI_API_KEY": "your-key"      }    }  }}

Restart Claude Desktop afterwards.

Cursor

Add this to ~/.cursor/mcp.json (all projects) or .cursor/mcp.json (one project):

json
{  "mcpServers": {    "twittrapi": {      "command": "npx",      "args": ["-y", "twittrapi-mcp"],      "env": {        "TWITTRAPI_API_KEY": "your-key"      }    }  }}

Other clients

Any client that can start a stdio server works. The command is npx -y twittrapi-mcp.

Environment variables

VariableRequiredDescription
TWITTRAPI_API_KEYone of the two keysYour TwittrAPI key. Sent as the X-API-KEY header.
RAPIDAPI_KEYone of the two keysRapidAPI key. Used only when TWITTRAPI_API_KEY is not set.
RAPIDAPI_HOSTnoHost of your RapidAPI listing. Default twitter-aio.p.rapidapi.com.
TWITTRAPI_BASE_URLnoAPI base URL for the direct API. Default https://api.twittrapi.com.
TWITTRAPI_RESPONSE_FORMATnosimple (default) or raw. See Response format.
TWITTRAPI_X_COOKIEnoCookie of your own logged-in x.com session. Turns on the account tools together with TWITTRAPI_X_PROXY.
TWITTRAPI_X_PROXYnoYour proxy for the account tools, http://user:pass@host:port.
TWITTRAPI_X_CHAT_PASSCODEnoYour X Chat passcode. Adds send_dm and message text in list_dm_conversations.

If neither key is set, the server still starts and lists its tools, but every call returns an error explaining how to set a key.

Using RapidAPI instead

If you bought access through RapidAPI, set RAPIDAPI_KEY instead of TWITTRAPI_API_KEY:

json
"env": { "RAPIDAPI_KEY": "your-rapidapi-key" }

Requests then go to https://twitter-aio.p.rapidapi.com with the x-rapidapi-key and x-rapidapi-host headers. The tools and their output are the same.

Subscribed to another TwittrAPI listing on RapidAPI? Set its host: "RAPIDAPI_HOST": "twttr.p.rapidapi.com".

Tools

These tools read public data and are always available. The account tools are added when you configure your X session.

ToolWhat it does
get_user_by_usernameProfile by handle, including the numeric user ID
get_user_by_idProfile by numeric user ID
username_to_idResolve a handle to its user ID
users_by_idsProfiles for up to 500 user IDs at once
get_user_tweetsA user's tweets
get_user_tweets_and_repliesA user's tweets and replies
get_user_mediaA user's tweets with photos or videos
get_followersA user's followers
get_followingAccounts a user follows
get_verified_followersA user's verified followers
get_user_affiliatesAccounts affiliated with an organization
get_friendships_batchWhether one account follows up to 50 others, and back
get_user_about_batch"About this account" for up to 20 handles
search_tweetsSearch with X operators; Top, Latest, People, Photos or Videos
get_tweetA tweet and its reply thread
tweets_by_idsUp to 100 tweets by ID at once
get_tweet_retweetsUsers who retweeted a tweet
get_tweet_quotesTweets quoting a tweet
get_tweet_repliesOnly the replies to a tweet
get_tweet_threadThe author's own thread around a tweet
get_list_detailsList name, owner and counts
get_list_tweetsTweets from a list's members
get_list_membersMembers of a list
get_communityCommunity details
get_community_aboutA community's About page: rules, moderators, members
get_community_tweetsTweets in a community
search_communitiesFind communities by keyword
get_trendsTrending topics for a location (WOEID)
get_trend_locationsLocations that have trends, with their WOEIDs
get_spaceAn X Space: title, state, host and participants

The user timeline tools (get_user_tweets, get_followers and so on) accept either userId or username. The batch tools are billed one call per handle; tweets_by_ids is one call however many IDs.

Account tools

With TWITTRAPI_X_COOKIE and TWITTRAPI_X_PROXY set, the server also lists tools that act on your own X account:

ToolWhat it does
create_tweetPost a tweet; optional quote (quoteUrl), poll (pollChoices) and reply limit
reply_to_tweetReply to a tweet
delete_tweetDelete one of your tweets
like_tweet, unlike_tweetLike or unlike a tweet
retweet, unretweetRetweet or undo a retweet
bookmark_tweet, unbookmark_tweetAdd or remove a bookmark
follow_user, unfollow_userFollow or unfollow (by userId or username)
list_dm_conversationsYour DM inbox
send_dmSend a direct message (needs TWITTRAPI_X_CHAT_PASSCODE)
create_listCreate a list
add_list_member, remove_list_memberAdd or remove a list member
create_draft, list_draftsSave a draft, list your drafts
list_bookmark_folders, list_bookmark_folder_tweetsYour bookmark folders and the tweets in one (X Premium)
search_bookmarksSearch your bookmarks
list_community_membershipsCommunities you are a member of
list_articles, get_articleYour X Articles, drafts or published, and one article (X Premium)
create_article, update_articleSave a new article as a draft, change one (X Premium)
publish_article, unpublish_article, delete_articlePublish, unpublish or delete an article (X Premium)

How to get the cookie and set up a proxy: twittrapi.com/docs/x-session. The cookie needs auth_token and ct0; direct messages also need twid.

json
"env": {  "TWITTRAPI_API_KEY": "your-key",  "TWITTRAPI_X_COOKIE": "auth_token=...; ct0=...; twid=u%3D...",  "TWITTRAPI_X_PROXY": "http://user:pass@host:port"}
  • The cookie and proxy stay in the server's configuration. They are not tool arguments, so the model never sees them, and they are never logged or returned in a result.
  • Write tools are marked readOnlyHint: false (deletions and undo actions also destructiveHint: true), so clients ask before running them.
  • Each call is one billed API call, like the read tools.
  • Account tools are only available over stdio. HTTP mode and the hosted server do not offer them.

Response format

Tool results use the API's simple format by default: flat camelCase JSON with a fixed schema ({"data": [...], "nextCursor": ..., "hasNextPage": ...} for lists, {"data": {...}} for single objects). Tweets carry id, url, text, createdAt, author, counts, media, quoted, retweetOf and a few more fields; users carry username, name, description, counts and so on. That is about 60 % fewer tokens than X's raw GraphQL JSON.

To get the raw JSON instead (for cards, polls, edit history, community notes and other fields the simple format leaves out):

  • per call: the tools take an optional format argument, "simple" or "raw";
  • for the whole server: set TWITTRAPI_RESPONSE_FORMAT=raw (the format argument still wins).

A few endpoints have no simple format: get_space, get_community_about, the batch tools and the newer account tools (bookmark folders and search, communities, articles). These tools have no format argument and always return raw JSON.

Output size and pagination

Raw responses can be several hundred KB. Every tool takes an optional max_chars argument (default 50,000, range 1,000 to 1,000,000). Longer output is cut and ends with a [TRUNCATED ...] marker.

Paginated tools print the cursor above the JSON, so truncation never removes it:

next_cursor: DAABCgABGZ...Pass next_cursor as `cursor` to get the next page.
{"data":{...}}

On the last page the header reads next_cursor: none (last page, no more results). In the simple format that is when hasNextPage is false. In the raw format it happens when the response has no next cursor (empty likes timelines included), when X returns the cursor you just sent, or when a page holds only cursors and no results.

Errors

API errors come back as tool errors with a short explanation, for example:

  • 402: the account has no balance left
  • 429: rate limit hit, wait before retrying
  • 404: the user or tweet does not exist, is private or is suspended
  • 5xx: temporary upstream problem

HTTP mode (remote hosting)

sh
npx -y twittrapi-mcp --http --port 3333 --host 0.0.0.0

This serves a stateless Streamable HTTP endpoint at /mcp and a health check at /health. The default host is 127.0.0.1. Every POST gets its own server instance bound to the caller's credentials, so any number of instances can run behind a load balancer without sticky sessions. GET /mcp answers 405 (no server-initiated stream); the legacy SSE transport is not offered.

In HTTP mode the server does not use a key from its own environment. Each request carries the caller's credentials:

  • X-API-KEY: <key> or Authorization: Bearer <key> for the direct API
  • x-rapidapi-key: <key> for RapidAPI, plus x-rapidapi-host: <host> for a listing other than twitter-aio.p.rapidapi.com (must end in .p.rapidapi.com)
  • Authorization: Bearer twa_at_...: a TwittrAPI OAuth access token (hosted mode, below)

The account tools are not offered in HTTP mode; TWITTRAPI_X_COOKIE and TWITTRAPI_X_PROXY are ignored there. TWITTRAPI_BASE_URL and TWITTRAPI_RESPONSE_FORMAT are still read from the environment; callers can pick the format per call with the format argument. Put the server behind HTTPS if it is reachable from the internet.

Example client config for your own instance (Claude Code):

sh
claude mcp add --transport http twittrapi https://your-host.example.com/mcp --header "X-API-KEY: your-key"

Hosted mode with OAuth

For clients that require OAuth (Claude.ai connectors, ChatGPT), the server acts as an OAuth 2.1 resource server and the TwittrAPI dashboard as the authorization server (dynamic client registration, PKCE S256, consent screen, rotating refresh tokens). The server:

  • answers requests without credentials with 401 and WWW-Authenticate: Bearer resource_metadata="<origin>/.well-known/oauth-protected-resource/mcp", scope="mcp";
  • serves RFC 9728 metadata at /.well-known/oauth-protected-resource/mcp and /.well-known/oauth-protected-resource, and relays the dashboard's RFC 8414 metadata at /.well-known/oauth-authorization-server;
  • checks each access token with the dashboard's internal introspection endpoint (shared secret), caches valid results for up to OAUTH_CACHE_SECONDS (30) and invalid ones for 5 s, and accepts only tokens whose audience is MCP_PUBLIC_URL;
  • calls the API with the key of the account behind the token. The key never reaches the client. Invalid or revoked tokens get 401 with error="invalid_token"; if the dashboard cannot be reached the answer is 503 with Retry-After, so clients keep their tokens.

Environment (HTTP mode)

VariableDefaultDescription
PORT, HOST3333, 127.0.0.1Listen address (the Docker image uses 3000, 0.0.0.0)
TWITTRAPI_BASE_URLhttps://api.twittrapi.comGateway the tools call
TWITTRAPI_RESPONSE_FORMATsimpleDefault format of tool results
MCP_PUBLIC_URL–Public URL of /mcp, e.g. https://mcp.twittrapi.com/mcp. Token audience.
OAUTH_ISSUER–Authorization server, e.g. https://app.twittrapi.com
OAUTH_INTROSPECTION_SECRET–Shared secret with the dashboard (32+ characters). OAuth is on when these three are set.
OAUTH_INTROSPECTION_URL$OAUTH_ISSUER/api/oauth/introspectInternal URL of the introspection endpoint
OAUTH_METADATA_URL$OAUTH_ISSUER/.well-known/oauth-authorization-serverWhere the relayed metadata is fetched
OAUTH_CACHE_SECONDS30Cache for valid tokens (max 300). Revocations take effect within this time.
MAX_CONCURRENCY_PER_KEY8Requests in flight per key and instance; more get 429 with Retry-After: 1. 0 turns it off.
MAX_BODY_BYTES262144Larger request bodies get 413
REQUEST_TIMEOUT_MS90000Requests running longer get 504
ALLOWED_ORIGINS–Comma-separated Origin allowlist for browser clients (DNS rebinding protection)
TRUST_PROXY–1 to log the client IP from X-Forwarded-For
LOG_LEVELinfodebug, info, warn, error

Logs are JSON lines on stdout, one per request: request id, client IP, auth kind (api_key, rapidapi, oauth, none), a hashed key id (k_ + 12 hex characters), OAuth client and account id, JSON-RPC method, tool name, status and duration. Keys and tokens are never logged.

Docker / Coolify

sh
docker build -t twittrapi-mcp .docker run -p 3000:3000 -e MCP_PUBLIC_URL=... -e OAUTH_ISSUER=... -e OAUTH_INTROSPECTION_SECRET=... twittrapi-mcp

In Coolify: build pack Dockerfile, port 3000, health check path /health, domain mcp.twittrapi.com, and the variables above. Set OAUTH_INTROSPECTION_URL to the dashboard's internal address when both run on the same server.

Development

sh
npm installnpm run buildnpm test

npm test builds first, then runs unit tests, a protocol test that starts the server over stdio and HTTP against a local mock API, and tests of hosted mode (OAuth challenge and metadata, token introspection and caching, audience check, limits, log redaction) against a fake dashboard.

To add or change a tool, edit src/endpoints.ts. Each entry has a name, description, API path and zod parameter schemas. Every tool also gets max_chars, and format unless the entry sets rawOnly. An entry can set a simplify function to reshape the parsed JSON further; none do. Account tools live in src/actions.ts.

Try the server interactively with the MCP Inspector:

sh
npx @modelcontextprotocol/inspector -e TWITTRAPI_API_KEY=your-key node dist/index.js

Support

Questions, bugs or a higher rate limit: email [email protected] or open an issue in this repository. Service status: twittrapi.com/status. News and changes: the TwittrAPI Telegram channel (link on the website).

License

MIT

來源:README.md,提交 8431a1d

工具

0
該伺服器需要登入,因此 SourceWeft 無法在沒有帳號的情況下讀取其工具,也未收錄。已連接帳號所能看到的內容可能因帳號及其權限而異。

版本歷史

3
  1. v1.2.0最新Oct 19, 2026
  2. v0.3.1Oct 14, 2026
  3. v0.3.0Oct 12, 2026

評分

已滿足適用檢查項的 85%

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

  • 近 30 天內可連通必需25 分
  • 已宣告認證方式必需10 分
  • 已列出工具15 分

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

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