twitter-mcp
Twitter/X MCP server for the API v2, enabling users to manage profiles, posts, likes, retweets, and follows through natural language using a stateless Streamable HTTP transport with OAuth user access token authentication.
README
Twitter MCP Server
TypeScript Model Context Protocol server for the Twitter/X API v2.
- Transport: Streamable HTTP (stateless)
- Auth: OAuth user access token via the
access-tokenheader — required only for tool calls, not for list/initialize - Runtime: Node.js 20+, Express,
@modelcontextprotocol/sdk - Docker: multi-stage production image included
This server does not run the OAuth dance itself. Obtain a user access token from your OAuth 2.0 (or OAuth 1.0a user-context) flow and send it when invoking tools.
Endpoints
| Method | Path | Description |
|---|---|---|
POST |
/mcp |
MCP Streamable HTTP endpoint (tools) |
GET |
/health |
Liveness probe |
GET |
/mcp |
405 — not used in stateless mode |
DELETE |
/mcp |
405 — no sessions to delete |
Authentication
access-token is not required for protocol/list methods (initialize, tools/list, ping, etc.). It is required when calling a tool that hits the Twitter API.
POST /mcp HTTP/1.1
Host: localhost:3000
Content-Type: application/json
Accept: application/json, text/event-stream
access-token: <OAUTH_USER_ACCESS_TOKEN>
Fallback (also accepted):
Authorization: Bearer <OAUTH_USER_ACCESS_TOKEN>
If a tool is called without a token, the tool returns an error:
Missing access token. Tool calls require an OAuth user access token via the `access-token` header …
Suggested OAuth 2.0 scopes for full tool coverage:
tweet.read tweet.write users.read follows.read follows.write media.write offline.access
Media / video posting requires
media.writein addition totweet.write. Re-authorize users after adding the scope so tokens include it.
Tools
| Tool | Description |
|---|---|
get_me |
Authenticated user profile |
get_user_by_username |
User lookup by handle |
get_user_by_id |
User lookup by ID |
get_tweet |
Single tweet by ID |
get_user_timeline |
User's recent posts |
get_user_mentions |
Mentions timeline |
search_recent_tweets |
Recent search (last 7 days) |
upload_media |
Upload image / GIF / video (returns media_id) |
post_tweet |
Create a post (optional reply / quote / media) |
delete_tweet |
Delete own post |
like_tweet / unlike_tweet |
Like management |
retweet / undo_retweet |
Retweet management |
follow_user / unfollow_user |
Follow management |
Posting video
- Call
upload_mediawith one of:media_url— HTTP(S) URL (preferred for large files)media_path— path on the server hostmedia_base64— base64 payload (JSON body limit 64 MB; prefer URL for big videos)
- Optionally set
media_typetovideo/mp4orvideo/quicktimeif it cannot be inferred. - Wait for the tool to return
{ "media_id": "..." }(videos are processed server-side before return). - Call
post_tweetwithmedia_ids: ["<media_id>"]and optionaltext.
Limits: 1 video or 1 GIF, or up to 4 images per post. Max file size loaded in-process: 512 MB.
Local development
npm install
npm run dev
# → http://0.0.0.0:3000/mcp
Build & run production:
npm run build
npm start
Environment variables:
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
HTTP port |
HOST |
0.0.0.0 |
Bind address |
Docker
# Build
docker build -t twitter-mcp .
# Run
docker run --rm -p 3000:3000 twitter-mcp
# Health check
curl http://localhost:3000/health
Example MCP initialize (curl)
No token needed for initialize / tools/list:
curl -sS http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": { "name": "curl", "version": "1.0.0" }
}
}'
Tool calls need the token:
curl -sS http://localhost:3000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'access-token: YOUR_TOKEN' \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": { "name": "get_me", "arguments": {} }
}'
Architecture notes
- Stateless Streamable HTTP — each
POST /mcpcreates a newMcpServer+StreamableHTTPServerTransportwithsessionIdGenerator: undefined, then tears them down when the response finishes. Safe for horizontal scaling and containers. - Per-request token isolation —
AsyncLocalStorageholds the optional access token for the duration of the request so concurrent calls never mix credentials. Missing tokens only fail when tools callgetAccessToken(). - Twitter client —
twitter-api-v2is constructed with the user access token and used as OAuth 2.0 user-context (Bearer).
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.