x-mcp-server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@x-mcp-server post a tweet saying hello from MCP"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
x-mcp-server
A Model Context Protocol server for the X API v2.
175 of X's 190 published operations are reachable. The 15 that are not are the streaming endpoints, excluded for a reason no access tier changes.
MIT licensed.
Install
npm install -g @nasdigitaluk/x-mcpRelated MCP server: SocialDataX X Twitter MCP
Authentication
Two ways. Pick one.
App-only — simplest, cannot post:
{ "env": { "X_BEARER_TOKEN": "your-bearer-token" } }User context — can post, and refreshes itself:
{
"env": {
"X_CLIENT_ID": "your-client-id",
"X_CLIENT_SECRET": "your-client-secret",
"X_CREDENTIALS_FILE": "~/.x-mcp-credentials"
}
}Seed the credentials file once from your authorisation flow:
X_ACCESS_TOKEN=...
X_REFRESH_TOKEN=...
X_TOKEN_EXPIRES_AT=1757260800000⚠️ X's refresh tokens are single use
This is the part worth reading before you trust any X integration, including this one.
X access tokens last about two hours, and the refresh token is single use — every refresh returns a new one and invalidates the old. Persist the new one incorrectly and the chain breaks permanently; the only fix is re-authorising in a browser.
Running two MCP clients at once is completely normal. Both refresh, both spend the same token, and whichever writes second saves one X has already invalidated. The server this replaces did the write with a plain writeFileSync — no lock, no atomic write.
Here:
the refresh happens inside an exclusive lock, so only one process spends the token;
it re-reads under the lock before refreshing, because another process may have already done the work while this one waited;
the write is atomic (temp file,
fsync, rename), so a crash cannot truncate it;the file is chmod'd on every write, not only when created — a pre-existing
0644credentials file used to stay world-readable while the code read as though it had secured it;a stale lock from a killed process is broken after 30s rather than wedging everything after it.
There is a test asserting that three concurrent callers cause exactly one refresh.
What is excluded, and why
The 15 streaming endpoints: /2/tweets/search/stream, the firehose and sample streams, and the compliance streams.
These are not request/response endpoints. They hold the connection open and emit posts indefinitely — a stream that returns has ended, which is a failure rather than a result. An MCP tool call has to return, so pointing one at a stream means it hangs until the client's timeout and then reports a timeout, which reads as a broken server rather than a category error.
No access tier changes this. Consuming a stream needs a long-running process, not a tool call.
The /stream/rules endpoints are NOT excluded. They configure what a stream would deliver and are ordinary calls, so you can manage your rules here and consume the stream elsewhere.
On paid tiers
Most of X's API needs a paid access tier. Those endpoints are covered anyway, because a tier is something you can buy — unlike an admin key you simply cannot obtain. Excluding them would deny the API to people who have paid for it. X reports clearly when your tier is insufficient, and that error passes through.
Tools
Seven tools for 175 operations.
Tool | |
| Browse the catalogue. Start here. |
| Call any operation by id. |
| The authenticated user. Needs user context. |
| Post. Immediately public. |
| Delete one of yours. Destructive. |
| Search recent posts. Needs Basic or above. |
| One post by id. |
Posting is classified a write, not destructive, because a post can be deleted — but everyone who saw it still saw it, and the tool description says so.
Of 190 operations: 104 read, 57 write, 29 destructive.
Refreshing the catalogue
curl -o vendor/x-openapi.json https://api.twitter.com/2/openapi.json
npm run generate && npm testTesting
npm test # 15 tests, including the refresh-concurrency one
X_BEARER_TOKEN=x npm run smoke # real MCP over stdioBuilt on
@nasdigitaluk/mcp-server-core.
Licence
MIT.
Available Tools
7 toolsx_callC
Call any X API v2 operation by id.
Inputs: operation_id (required), body, params.
x_create_postA
Post to X. This is immediately public. It can be deleted afterwards, which is why it is classified a write rather than destructive — but everyone who saw it still saw it.
Inputs: text (required), media_ids, quote_post_id, reply_settings, +1 more.
x_delete_postA
Delete one of your own posts. Cannot be undone.
Inputs: post_id (required).
x_get_meA
The authenticated user. Needs a user-context token, not app-only.
Inputs: user.fields.
x_get_postC
One post by id, with whichever fields you ask for.
Inputs: post_id (required), expansions, tweet.fields.
x_list_operationsA
Browse the X API v2 — 175 of 190 operations are reachable here. Use this to find an operation id for x_call. Many endpoints need a paid access tier on your X account; that is a fact about the account rather than this server, and X reports it clearly if you lack one.
Inputs: search, include_excluded.
x_search_postsB
Search recent posts. Needs at least Basic access; the free tier cannot read.
Inputs: query (required), next_token, max_results, tweet.fields.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Each dedicated tool targets a clear action (create/delete/search/get/user), but x_call can execute the same operations generically, so an agent could occasionally choose between x_call and a wrapper. The descriptions are specific enough that this overlap is manageable.
All tools share an x_ prefix and use snake_case, with imperative verb-first names like list_operations, create_post, and search_posts. x_call is a slight deviation from the verb_noun pattern, but it still reads consistently as the generic dispatch verb.
Seven tools is a well-scoped set: five focused wrappers plus a discovery/generic-call pair cover common and long-tail X operations without bloating the server.
The server explicitly reaches 175 of 190 X API v2 operations via x_list_operations plus x_call, and dedicated wrappers cover the most common post/user workflows. The tiny uncovered remainder is not an obvious gap for practical use.
Maintenance
Related MCP Connectors
Official twitterapi.io hosted MCP: Twitter/X tweets, users, followers, trends. OAuth or API key.
Hosted MCP server from TwitterAPI.io that gives AI agents read-only access to Twitter/X data. 12 tools: tweet search with X operators, user profiles, a user's latest tweets, followers and followings, replies, quotes, retweeters, mentions and trends. Connect at https://mcp.twitterapi.io/mcp with a TwitterAPI.io API key or account sign-in; usage is paid per result returned. Separately, TwitterAPI.io also offers x402 pay-per-call HTTP endpoints (tweet search, user info, a user's latest tweets) paid in USDC on Base or Solana with no account or API key; see https://docs.twitterapi.io/x402-pay-per-call. The MCP server itself uses an API key or sign-in.
Official MCP server for twitterapis.com. Twitter/X search, users, DMs, Grok, monitoring and writes.
Real-time Twitter (X) advanced search, user timelines, profiles & followers MCP ($0.03/1K tweets).
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables MCP-based interaction with the X (Twitter) API v2, supporting reads like timeline, mentions, and search, and writes through a two-step draft-and-confirm process that ensures human-visible previews before any public post.-
- AlicenseNot gradedqualityCmaintenanceX and Twitter MCP by SocialDataX for public post search and details, comments and replies, user profiles, and user post lists with pagination.MIT
- AlicenseAqualityBmaintenanceEnables MCP clients to interact with the X (Twitter) API v2 through 41 typed tools for reading, searching, engaging, publishing, and managing content, with policy-based access control and session credit budgets to prevent overspending.4151 npm1MIT
- AlicenseAqualityCmaintenanceExposes the Twitter/X API as native MCP tools, letting agents search tweets and users, pull profiles, timelines, followers, lists, communities, and trends, and read account-scoped data like bookmarks, DMs, and home timeline. It also performs write actions such as posting, liking, retweeting, following, and their reversals, using an API key with optional linked or per-call X account credentials.991,079 npmMIT