
X Mcp Ai
io.github.IvanBBaevPublished by GitHub account IvanBBaevv0.8.0Updated Oct 24, 2026
Safety-first X (Twitter) API v2 MCP server: 41 typed tools across 12 packages, policy-gated.
Overview
A local MCP server that gives an assistant typed tools for the X (Twitter) API v2, with policy-gated reads, writes and cost tracking.
- What you can do
- Read posts, users, timelines, followers and following, and search recent posts or the full archive back to 2006, including volume counts and usage reports for the billing cycle and rate limits. Create, delete and moderate posts, and upload media for attachment. Like, repost, bookmark, follow, mute, block, and manage lists including membership, timelines, follow and pin. Read and send direct messages, which are locked behind an explicit opt-in. Every result reports its own cost and the running session total.
- When to use it
- Useful when an assistant should research, monitor or publish on X through the official API rather than scraping, and when you want writes and spending bounded by an operator-set policy and budget before an agent touches a real account.
- Requirements
- Node.js 22 or newer, run locally via npx or a built checkout. An X developer account and app: OAuth 2.0 client ID (plus X_MCP_CLIENT_SECRET for confidential clients) with a one-time authorize step, or X_MCP_BEARER_TOKEN for app-only read-only mode. Prepaid X API credits, since the API bills per read and per write.
Installation
In SourceWeft
- Open X Mcp Ai in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
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(currently0.8.0, published from CI with npm provenance). Pin an exact version while the project is on0.x(Setup). 41 tools across 12 packages are registered today; the full designed surface lives indocs/03-tool-catalog.mdand has landed in full. The public API is unstable until1.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:
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:dmare in no preset, not evenfull. - Cost awareness built in. Since 2026-02-06 the X API v2 is pay-per-use. Every result
reports its own
cost_usdand the runningsession_total_usd; an operator-setX_MCP_CREDIT_BUDGETwithX_MCP_BUDGET_MODE=hardrefuses 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
Authorizationheader, redirects never followed on token-bearing requests,0600token file written withO_NOFOLLOW/O_EXCL, untrusted-content marking on returned text, and media upload default-deny outside a realpath-containedX_MCP_MEDIA_DIR. - Typed failures. Eleven error classes, each carrying
retryableandfix: "agent" | "operator", so the model retries what is retryable and escalates what is not. - Structured output. Every tool advertises a JSON-Schema
outputSchemaand returnsstructuredContentalongside 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:
Then point your MCP client at it:
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:
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:
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 theauthorizesubcommand; tokens land inX_MCP_TOKEN_FILEand are refreshed automatically.app-only— application-only bearer token (X_MCP_BEARER_TOKEN); read endpoints only, no user context.
Environment variables
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.
DM cells are never in a preset — not even
full.read:dmandwrite:dmmust be granted explicitly viaX_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>)unlessX_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_BUDGETbefore 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:
Command-line interface
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
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 checkregenerates and diffs it, so an edit fails CI rather than shipping. Same fordocs/reference/tools.md.
DM reads return ids, timestamps and participants only; message bodies require an explicit
include_text: true on the call.
Tool packages
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:
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
Authorizationheader 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
0600withO_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 insideX_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-aiexecutes 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 isx-mcp-ai;x-mcpis 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
0600file on your machine. No tool ever returns a credential, anddoctormasks 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
Support
If this project saves you time, support is welcome:
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.
Source: README.md at commit b0f04b4
Tools
0Version history
1- v0.8.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts