X Mcp Ai

io.github.IvanBBaev由 GitHub 帳號 IvanBBaev 發布v0.8.0更新於 Oct 24, 2026

Safety-first X (Twitter) API v2 MCP server: 41 typed tools across 12 packages, policy-gated.

概覽

AI 產生的概覽

一個本機 MCP 伺服器,為助理提供 X(Twitter)API v2 的型別化工具,讀取與寫入皆受策略控管並追蹤費用。

可以做什麼
讀取貼文、使用者、時間軸、追蹤者與追蹤中名單,搜尋近 7 天貼文或回溯至 2006 年的完整封存,並取得數量統計、計費週期用量與速率限制資訊。建立、刪除與審核貼文,上傳媒體以便附帶發布。按讚、轉推、收藏、追蹤、靜音、封鎖,以及管理清單(成員、時間軸、追蹤與置頂)。讀取與傳送私訊,需明確開啟後才可用。每個結果都會回報本次費用與工作階段累計費用。
適用情境
適合讓助理透過官方 API 而非爬取來研究、監測或發布 X 內容,也適合在代理接觸真實帳號前,以營運者設定的策略與預算限制寫入與花費。
執行需求
需要 Node.js 22 或更新版本,透過 npx 或本機建置產物在本機執行。需要 X 開發者帳號與應用程式:OAuth 2.0 用戶端 ID(機密用戶端另需 X_MCP_CLIENT_SECRET)並執行一次授權流程,或使用 X_MCP_BEARER_TOKEN 進入僅應用程式、唯讀模式。需要預付的 X API 額度,因為 API 依讀取與寫入計費。
安裝前請注意
伺服器持有 X 憑證與 OAuth 權杖,可發文、刪除、追蹤、封鎖和傳送私訊;預設唯讀策略可限制這些操作,私訊權限從不包含在任何預設中。API 依次計費,含連結的貼文費用高得多,建議設定 X_MCP_CREDIT_BUDGET 並搭配 X_MCP_BUDGET_MODE=hard;預算僅屬提示性質且重新啟動後重設。從 X 取得的內容會回傳給你的模型供應商。請固定精確的套件版本,未固定版本的 npx 會在持有權杖的行程中執行最新發布。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

x-mcp-ai — X (Twitter) MCP Server

An MCP server that exposes the X (Twitter) API v2 to MCP clients — Claude Code, Claude Desktop, VS Code, Cursor, or any MCP-compatible agent — as a curated set of typed tools, gated by a two-axis policy model and aware of the 2026 pay-per-use pricing so an agent can never quietly overspend.

Status: pre-1.0, under active development, published on npm as x-mcp-ai (currently 0.8.0, published from CI with npm provenance). Pin an exact version while the project is on 0.x (Setup). 41 tools across 12 packages are registered today; the full designed surface lives in docs/03-tool-catalog.md and has landed in full. The public API is unstable until 1.0.0.

Contents: Quick demo · Features · Requirements · Setup · Configure credentials · Cost · Run / debug · Develop · Tools · Resources · Prompts · Project structure · Security notes · Data handling · Documentation · Support · Trademark

Quick demo

Once the server is wired into your MCP client, you drive it in natural language and the model picks the tool. Three representative asks:

jsonc
// 1. Read (default read-only preset — no writes possible)// "What are people saying about the Model Context Protocol this week?"{  "tool": "x_search_recent",  "arguments": { "query": "\"model context protocol\" -is:retweet lang:en", "max_results": 25 }}
jsonc
// 2. Engage (requires the `engage` preset or an explicit write:engagement allow)// "Like that launch post for me."{  "tool": "x_like_set",  "arguments": { "post_id": "1899…", "action": "like" }}
jsonc
// 3. Publish (requires the `publish` preset or write:content)// "Post: 'Shipping x-mcp-ai today.' — mind the cost."// Every result carries cost_usd + session_total_usd; a URL in the text raises the price 13×.{  "tool": "x_post_create",  "arguments": { "text": "Shipping x-mcp-ai today." }}

Features

  • 41 tools across 12 packages over the X API v2 — read posts, users and timelines, search (recent and full-archive), engage, publish, manage lists, upload media, walk the social graph, and read/send DMs behind an explicit opt-in.
  • Two-axis policy model (operation:domain) with five presets — read-only (default), engage, publish, manage, full. Writes are opt-in; deny beats allow beats preset, per cell. Direct-message cells are double-locked: read:dm/write:dm are in no preset, not even full.
  • Cost awareness built in. Since 2026-02-06 the X API v2 is pay-per-use. Every result reports its own cost_usd and the running session_total_usd; an operator-set X_MCP_CREDIT_BUDGET with X_MCP_BUDGET_MODE=hard refuses calls that would exceed it, and the model cannot raise the cap.
  • Two auth modes — OAuth 2.0 PKCE user context (primary, rotating refresh tokens, single-flight refresh) and app-only bearer for read-only deployments.
  • Security-first defaults — host-scoped Authorization header, redirects never followed on token-bearing requests, 0600 token file written with O_NOFOLLOW/O_EXCL, untrusted-content marking on returned text, and media upload default-deny outside a realpath-contained X_MCP_MEDIA_DIR.
  • Typed failures. Eleven error classes, each carrying retryable and fix: "agent" | "operator", so the model retries what is retryable and escalates what is not.
  • Structured output. Every tool advertises a JSON-Schema outputSchema and returns structuredContent alongside the text block.
  • Availability class-gating, live per-endpoint rate-limit tracking (including the 24-hour app cap on post creation), cursor pagination, and compact result rendering.

Requirements

  • Node.js >= 22 (see .nvmrc).
  • An X developer account and app with an OAuth 2.0 client (Client ID; Client Secret only for confidential clients). App-only mode needs a bearer token instead.
  • Prepaid X API credits — the API bills per read and per write (see Cost).

Setup

The recommended install is the published package, pinned to an exact version while the project is on 0.x — nothing to clone or build:

bash
npx -y [email protected] doctor   # sanity check; makes no billable calls

Then point your MCP client at it:

jsonc
// claude_desktop_config.json (Claude Desktop) / .mcp.json (Claude Code) / .cursor/mcp.json{  "mcpServers": {    "x": {      "command": "npx",      "args": ["-y", "[email protected]"],      "env": {        "X_MCP_AUTH_MODE": "oauth2",        "X_MCP_CLIENT_ID": "your-oauth2-client-id",        "X_MCP_POLICY": "read-only",        "X_MCP_CREDIT_BUDGET": "5.00",        "X_MCP_BUDGET_MODE": "hard"      }    }  }}

Running from a local checkout instead? Use "command": "node" with "args": ["/abs/path/to/x-mcp/build/src/index.js"] and the same env map.

Claude Code from the CLI:

bash
claude mcp add x --env X_MCP_POLICY=read-only -- npx -y [email protected]

Per-client instructions — Claude Desktop, Claude Code, VS Code (.vscode/mcp.json), Cursor and MCP Inspector — are in docs/10-operator-guide.md §4, together with the authorize flow and ready-made env recipes.

From source (development)

Still fully supported — build the entry point and spawn it with node instead of npx:

bash
git clone https://github.com/IvanBBaev/x-mcp.gitcd x-mcpnpm cinpm run build          # tsc → build/src/index.jsnode build/src/index.js doctor   # sanity check; makes no billable calls

Configure credentials

The server never prompts interactively; all configuration comes from environment variables (canonical table: docs/02-architecture.md §4; a starting point: .env.example).

Auth modes (X_MCP_AUTH_MODE):

  • oauth2 (default) — OAuth 2.0 with PKCE. Run the one-time authorization flow with the authorize subcommand; tokens land in X_MCP_TOKEN_FILE and are refreshed automatically.
  • app-only — application-only bearer token (X_MCP_BEARER_TOKEN); read endpoints only, no user context.
bash
X_MCP_AUTH_MODE=oauth2 X_MCP_CLIENT_ID=… node build/src/index.js authorize

Environment variables

VariableDefaultSecretPurpose
X_MCP_AUTH_MODEoauth2oauth2 | app-only.
X_MCP_CLIENT_IDOAuth 2.0 client ID (required for authorize and refresh).
X_MCP_CLIENT_SECRET✅OAuth 2.0 client secret (confidential clients only).
X_MCP_BEARER_TOKEN✅App-only bearer token; valid only with app-only.
X_MCP_TOKEN_FILEOS-resolvedPath to the rotating OAuth 2.0 token store (~ expanded).
X_MCP_TOKEN_KEYCHAIN01 → store tokens in the OS keychain (macOS security, Linux secret-tool). Mutually exclusive with X_MCP_TOKEN_FILE.
X_MCP_POLICYread-onlyPreset: read-only | engage | publish | manage | full.
X_MCP_POLICY_ALLOWComma-separated operation:domain cells to add.
X_MCP_POLICY_DENYComma-separated cells to remove (wins over allow and preset).
X_MCP_HIDE_DENIED01 → drop denied tools from registration entirely.
X_MCP_CREDIT_BUDGETSession spend cap, USD (e.g. 5.00). Unset = no cap.
X_MCP_BUDGET_MODEwarnwarn | hard.
X_MCP_AVAILABILITYComma-separated availability classes to enable (pilot, premium-user, enterprise).
X_MCP_MEDIA_DIRDirectory uploads must realpath inside (media default-deny).
X_MCP_PROFILES_FILEMulti-account profiles file.
X_MCP_PROFILEActive profile name (required with a profiles file).
X_MCP_BASE_URLhttps://api.x.comAPI base URL; must be https:// and *.x.com.
X_MCP_ALLOW_INSECURE_BASE_URL01 → permit a non-x.com base URL (testing only).
X_MCP_TIMEOUT_MS30000Per-request timeout, milliseconds.
X_MCP_LOG_LEVELinfosilent | error | info | debug.

Any other X_MCP_* variable is ignored with a startup warning — that is the typo detector. Every fatal configuration error names the variable at fault.

Two-axis access policy

Every tool maps to one policy cell — an operation:domain pair. Operations escalate read → write → destructive; domains are content, user, account, engagement, social-graph, moderation, dm. A preset unlocks a set of the 12 valid cells; X_MCP_POLICY_ALLOW adds cells, X_MCP_POLICY_DENY removes them, and deny > allow > preset.

PresetGrantsCallable tools
read-only (default)all read:* cells except read:dm21
engageread-only + write:engagement26
publishengage + write:content, write:moderation32
managepublish + destructive:content34
fullevery non-DM cell — adds write:social-graph, destructive:social-graph37

DM cells are never in a preset — not even full. read:dm and write:dm must be granted explicitly via X_MCP_POLICY_ALLOW (all 41 tools callable). Their unlock hint is deliberately withheld from policy errors, as it is for every other sensitive cell. Denied tools stay registered but annotated (disabled by policy <preset>) unless X_MCP_HIDE_DENIED=1.

Note that manage grants destructive content operations only — follow/mute/block need full or an explicit write:social-graph / destructive:social-graph allow.

Cost

Pay-per-use is the only pricing model. X retired the Free/Basic/Pro subscription tiers for new developers on 2026-02-06; every read and write draws down prepaid credits. Since 2026-04-16, a post whose text contains a URL costs $0.20 instead of $0.015 — 13×. Set X_MCP_CREDIT_BUDGET before pointing an agent at a real account.

Indicative rates (verified 2026-07-22): post reads ~$0.005 each, user lookups and follower/following reads ~$0.010, own-data reads ~$0.001, DM events ~$0.010, post create $0.015 (or $0.20 with a URL), DM send $0.015, list create $0.010, engagement writes currently $0. X also caps post reads at 2,000,000 per month. The authoritative table is docs/01-api-landscape.md §3; the operator's view is docs/10-operator-guide.md §5.

The budget is per process, advisory, resets on restart, and is model-immutable — there is no per-call override and no tool that raises it.

Run / debug

MCP clients spawn the server for you. To run it by hand:

bash
X_MCP_POLICY=read-only node build/src/index.js serve

Command-line interface

CommandWhat it does
serve (default)Start the MCP server over stdio. Running with no subcommand also serves.
authorize [--manual] [--port <port>]Run the one-time OAuth 2.0 PKCE authorization flow and persist the token file.
doctor [--connect]Print resolved config, path/permission checks and the policy matrix; no billable calls. --connect adds one unauthenticated reachability GET.

stdout carries JSON-RPC only; diagnostics, warnings and the single x-mcp-ai: fatal: <reason> startup line go to stderr. Symptom-driven fixes are in docs/11-troubleshooting.md.

Develop

bash
git clone https://github.com/IvanBBaev/x-mcp.gitcd x-mcpnpm cinpm run build         # tsc → build/npm run check         # typecheck + lint + format:check + test

Other scripts: npm run typecheck, npm run lint, npm run format / format:check, npm test, npm run coverage (c8), and npm run verify (clean build + coverage + lint + format check). See CONTRIBUTING.md for conventions and the full quality gate.

Tools

The 41 tools registered today. "Read-only" marks tools in a read:* policy cell — those callable under the default preset (DM reads excepted: they need an explicit allow). "User" marks user-only tools, which require OAuth 2.0 user context and are unreachable with an app-only bearer token. The designed surface is docs/03-tool-catalog.md; the full per-tool reference — schemas, scopes, cost class, availability — is docs/reference/tools.md.

The table below is generated from the tool registry by npm run docs:gen. Do not edit it by hand: npm run check regenerates and diffs it, so an edit fails CI rather than shipping. Same for docs/reference/tools.md.

PackageToolCellRead-onlyUserDescription
authx_auth_statusread:account✅Report the active auth mode, the authenticated user (in user mode), granted OAuth scopes, the credential backend, detected availability, and the resolved policy matrix.
authx_rate_limit_statusread:account✅Dump the in-process rate-limit table — per bucket (endpoint-class × auth-context), each tracked window's limit, remaining, reset time, and whether it is currently exhausted.
postsx_post_getread:content✅Batch-fetch one or more X (Twitter) posts by numeric id or status URL (1-100 per call).
postsx_post_createwrite:content✅Create a post — text, optional reply_to_id, quote_id, media_ids[], poll {options[], duration_minutes}, reply_settings.
postsx_post_deletedestructive:content✅Delete own post by id.
postsx_post_hide_replywrite:moderation✅Hide or unhide a reply to one of your own posts.
usersx_user_getread:user✅Batch fetch of X (Twitter) user profiles by numeric id, @handle, bare handle, or the sentinel me (the authenticated user).
searchx_search_recentread:content✅Search X (Twitter) posts from the last 7 days using the full v2 query syntax (from:, to:, conversation_id:, boolean operators).
searchx_post_counts_recentread:content✅Return a volume histogram (post counts per time bucket) for an X (Twitter) v2 query over the last 7 days, at minute/hour/day granularity.
engagementx_like_setwrite:engagement✅Like or unlike a post as the authenticated user.
engagementx_repost_setwrite:engagement✅Repost (retweet) a post as the authenticated user, or undo that repost.
engagementx_bookmark_setwrite:engagement✅Add a post to the authenticated user's bookmarks or remove it.
engagementx_bookmarks_listread:content✅✅The authenticated user's own bookmarks, newest first — the read half of x_bookmark_set.
timelinesx_timeline_homeread:content✅✅Read the authenticated X (Twitter) user's home timeline in reverse-chronological order (the accounts they follow, newest first).
timelinesx_timeline_mentionsread:content✅Read posts mentioning an X (Twitter) user (defaults to the authenticated user).
timelinesx_timeline_userread:content✅Read an X (Twitter) user's own posts, newest first, optionally excluding replies and/or reposts, within optional time bounds.
graphx_follow_setwrite:social-graph✅Follow or unfollow a user as the authenticated user.
graphx_mute_setwrite:social-graph✅Mute or unmute a user as the authenticated user.
graphx_block_setdestructive:social-graph✅Block or unblock a user as the authenticated user.
graphx_followers_listread:social-graph✅List the accounts following an X (Twitter) user.
graphx_following_listread:social-graph✅List the accounts an X (Twitter) user follows.
graphx_user_searchread:user✅Keyword search over X (Twitter) user profiles (names, handles, bios).
listsx_list_createwrite:content✅Create a list owned by the authenticated user.
listsx_list_updatewrite:content✅Update the authenticated user's own list metadata — name, description, and/or private.
listsx_list_deletedestructive:content✅Permanently delete the authenticated user's own list.
listsx_list_getread:content✅Read one list's metadata — name, description, privacy, member and follower counts, and owner handle.
listsx_lists_ownedread:content✅The lists a user owns (defaults to the authenticated user).
listsx_list_member_setwrite:content✅Add a user to the authenticated user's own list or remove one — a single user per call.
listsx_list_membersread:content✅The members of a list.
listsx_list_timelineread:content✅Posts from a list's timeline (recent posts by its members).
listsx_list_follow_setwrite:engagement✅Follow a list as the authenticated user, or unfollow it.
listsx_list_pin_setwrite:engagement✅Pin a list in the authenticated user's list view, or unpin it.
mediax_media_uploadwrite:content✅Upload a local image, GIF, or video via the chunked v2 flow and return a media_id to attach with x_post_create.
mediax_media_statusread:content✅✅Check the async processing state of an uploaded media by media_id.
dmx_dm_events_listread:dm✅✅List all recent direct-message events across the authenticated X (Twitter) user's conversations, newest first.
dmx_dm_conversation_events_listread:dm✅✅List the direct-message events of one X (Twitter) DM conversation, newest first.
dmx_dm_participant_events_listread:dm✅✅List the direct-message events of the 1:1 X (Twitter) DM conversation with one participant, newest first.
dmx_dm_sendwrite:dm✅Send an X (Twitter) direct message to exactly one target: an existing conversation (conversation_id) or a user (participant), creating the 1:1 conversation if needed.
archivex_search_archiveread:content✅Search the complete X (Twitter) archive back to 2006 using the full v2 query syntax (from:, to:, conversation_id:, boolean operators).
archivex_post_counts_archiveread:content✅Return a volume histogram (post counts per time bucket) for an X (Twitter) v2 query over the complete archive back to 2006, at minute/hour/day granularity.
usagex_usage_getread:account✅Report the post-read consumption of the current billing cycle against the monthly project cap (with an optional per-day and per-app breakdown), alongside the local credit-spend estimate for this session.

DM reads return ids, timestamps and participants only; message bodies require an explicit include_text: true on the call.

Tool packages

PackageCovers
authAuth context and rate-limit windows.
usagePlatform read-cap consumption and the local session-spend estimate.
postsCreate, read and delete posts.
searchRecent post search and volume counts.
archiveFull-archive search and counts.
timelinesHome, mentions and user timelines.
engagementLikes, reposts and bookmarks.
usersUser lookup.
graphProfile search, follow/mute/block, follower and following lists.
listsFull list lifecycle, membership, timeline, follow and pin.
mediaChunked media upload and status.
dmDirect-message reads and sends (double-locked).

Resources

MCP resources are planned — a read-only exposure of the resolved auth context and live rate-limit table as addressable resources. Not shipped.

Prompts

MCP prompts are planned — guided templates for common workflows (e.g. cost-aware posting, audience research). Not shipped.

Project structure

Ports & adapters; the module layout is fixed in docs/02-architecture.md §3:

src/├── index.ts            # composition root + stdio wiring├── core/               # config, policy, budget, errors, ports, tooldef,│                       #   registry, render, resolve, paginate, sanitize├── api/                # http, ratelimit, errors, oauth2/, endpoints/├── tools/              # one module per package (posts, search, graph, …)├── mcp/                # compose, server, schema, structured, gates, session└── cli/                # dispatch, authorize, doctor

Dependency rule: tools → core + api/endpoints, api → core, mcp → tools + core, cli → core + api. Nothing in core reaches outward or does I/O.

Security notes

A summary; the full threat model and operator checklist live in SECURITY.md and docs/04-security.md.

  • Host-scoped auth. The Authorization header is attached only for the configured API origin; redirects are never followed on token-bearing requests (confused-deputy defense). Proxy environment variables are ignored.
  • Token file hardening. Written 0600 with O_NOFOLLOW/O_EXCL; refresh is single-flight with reload-under-lock and fails closed rather than racing.
  • Untrusted content. Post/user/DM text returned to the model is marked as untrusted. Marking is not a semantic filter — the policy model is the real control against prompt injection.
  • No escalation recipes. A denial on a sensitive cell (*:dm, destructive:*, *:social-graph) names the blocked cell but never the variable that would unlock it, so the model cannot relay an escalation recipe to you.
  • Media default-deny. Uploads are refused unless the file realpaths inside X_MCP_MEDIA_DIR.
  • Cost is model-immutable. The session credit budget is operator-set; the model cannot raise or disable it.
  • Supply chain: pin the exact version. An unpinned npx -y x-mcp-ai executes the newest publish on every client cold-start — in a process holding your tokens. Releases are published from CI with npm provenance. The npm package name is x-mcp-ai; x-mcp is only the repository name.

Data handling

Full statement: docs/12-privacy.md.

  • Nothing phones home. No telemetry, no analytics, no update check. The project runs no server; the only outbound destination is the X API at your configured base URL.
  • Credentials stay local. Client id/secret and bearer tokens live in the process environment; OAuth tokens live in a 0600 file on your machine. No tool ever returns a credential, and doctor masks them.
  • Cost telemetry is local-only. The spend counter is in memory, per process, reported to the calling model and nowhere else.
  • Content you read leaves X for your model. Posts, profiles and DM events fetched by a tool are returned to your MCP client and therefore reach its model provider. Nothing is cached or persisted by this server.

Documentation

PageFor
10 — Operator guideInstall, authorize, per-client config, env recipes, cost control.
11 — TroubleshootingStartup errors, doctor, auth/refresh, rate limits, missing tools.
12 — Privacy & data handlingWhat is sent where, what is stored, how to delete it.
01 — API landscapePay-per-use pricing, availability classes, platform caps.
02 — ArchitectureModule layout and the canonical env-var table.
03 — Tool catalogThe designed tool surface and its classifications.
04 — SecurityThreat model, policy model, token lifecycle.

Support

If this project saves you time, support is welcome:

[Sponsor] [Ko-fi] [Donatree]

Trademark

x-mcp-ai is an independent, unofficial project. It is not affiliated with, endorsed by, or sponsored by X Corp. It talks to the official, publicly documented X API v2 and does not use any private, undocumented or scraping-based access.

"X", "Twitter", and related names, logos and marks are trademarks of X Corp. They are used here nominatively, only to describe what this software interoperates with. This project is released under the MIT License; trademark rights are not licensed.

來源:README.md,提交 b0f04b4

工具

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

版本歷史

1
  1. v0.8.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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