Puck
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Puck
X/Twitter MCP Connector
"Lord, what fools these mortals be!"
Puck is an MCP server that exposes the X (Twitter) API v2 as tools. It handles OAuth 2.0 PKCE with automatic token rotation, rate limit tracking, image uploads, and thread construction so consuming applications don't have to.
Named for the mischievous sprite from Shakespeare's A Midsummer Night's Dream — quick, everywhere at once, short utterances that cause outsized reactions.
Quick Start
1. X Developer Setup
Create a project at developer.x.com
Select Basic tier ($200/mo) or higher — Free tier is insufficient for meaningful use
Create an OAuth 2.0 App with Type: "Web App" (for PKCE flow)
Add
http://localhost:3000/oauth/callbackas a redirect URINote your Client ID (public) — no client secret needed for PKCE
2. MCP Configuration
Add Puck to your MCP client configuration:
{
"mcpServers": {
"puck": {
"command": "npx",
"args": ["@ticktockbent/puck"],
"env": {
"PUCK_CLIENT_ID": "your_oauth2_client_id"
}
}
}
}3. First Run
On first connection, Puck opens your browser for X OAuth consent. Once authorized, tokens are encrypted and stored locally at ~/.puck/tokens.json. Access tokens refresh automatically (2-hour expiry with rotating refresh tokens). Subsequent runs authenticate silently.
Related MCP server: X API FastMCP Server
Environment Variables
Variable | Required | Description |
| Yes | X OAuth 2.0 Client ID |
| No | OAuth callback URI (default: |
| No | Token storage location (default: |
| No | API tier: |
| No | Logging level (default: |
Tools
Authentication
Tool | Description |
| Check authentication state, username, scopes, token expiry, and API tier |
| Revoke tokens and clear stored credentials |
| Show current rate limit state across all tracked endpoint groups |
Posts
Tool | Description |
| Create a post (supports text, polls, reply settings, quote tweets, media) |
| Edit a post within the 30-minute / 5-edit window |
| Delete a post |
| Get a post by ID with full field expansion |
| Batch lookup posts by IDs (up to 100) |
Threads
Tool | Description |
| Create a thread from an array of post objects (handles chained reply IDs automatically) |
| Get all posts in a thread by conversation ID |
Media
Tool | Description |
| Upload images (JPG, PNG, WebP, up to 4 files, max 5MB each) with optional alt text |
| Check processing status of an uploaded media item |
Timelines
Tool | Description |
| Get a user's posts by user ID or @username |
| Get the authenticated user's mentions |
Architecture
src/
├── index.ts # MCP server entry point (stdio transport)
├── types.ts # TypeScript interfaces and X API types
├── auth/
│ ├── oauth2-pkce.ts # OAuth 2.0 PKCE flow, browser consent, token exchange
│ ├── token-manager.ts # Proactive refresh, rotation handling, deduplication
│ └── storage.ts # Encrypted token storage (~/.puck/)
├── client/
│ ├── x-api.ts # X API v2 client wrapper (all calls route through here)
│ ├── rate-limiter.ts # Per-endpoint rate limit tracking from response headers
│ ├── media.ts # Image upload pipeline
│ └── fields.ts # Field/expansion constants for v2 response shaping
├── tools/
│ ├── auth.ts # Auth status, logout, rate status tools
│ ├── posts.ts # Post CRUD and thread construction
│ ├── media.ts # Media upload tools
│ └── timelines.ts # Timeline and mentions tools
└── util/
├── character-count.ts # Accurate post length calculation (URLs=23, emoji=2)
├── pagination.ts # Pagination helper
└── errors.ts # Typed error classes and normalizerKey Design Decisions
Stateless — No caching of API responses. Each tool call hits the X API directly. Rate limit state is the sole exception.
Single account — One X account per server instance. Run multiple instances for multiple accounts.
V2 only — No v1.1 endpoints. The entire API surface uses
api.x.com/2/.Response-header rate limiting — Rate limits are tracked from
x-rate-limit-*response headers. No pre-seeding, no guessing. Only blocks when headers confirm the window is exhausted.Proactive token refresh — Access tokens expire every 2 hours. Puck refreshes when <15 minutes remain rather than waiting for a 401.
Atomic token persistence — Refresh tokens are single-use with rotation. Puck writes to a temp file then
fs.renameSync()to prevent the "lost refresh token" failure mode.Thread partial failure recovery — If a thread fails mid-creation, the successfully posted portion is returned with failure metadata.
Encrypted storage — Tokens at rest are AES-256-CBC encrypted using a machine-specific derived key.
Error Handling
All tools return consistent error shapes:
{
"error": "rate_limited",
"message": "POST /2/tweets rate limit reached (100/window). Resets at 2026-02-25T15:30:00Z.",
"retryAfter": 340,
"endpoint": "POST /2/tweets"
}Error Code | Meaning |
| Post or user doesn't exist |
| Endpoint rate limit hit (includes |
| Token expired/revoked and refresh failed |
| Not authenticated |
| Insufficient permissions or tier |
| Bad parameters |
| Post exceeds 280 characters |
| Media upload or processing failed |
| X API error (details included) |
OAuth Scopes (Phase 1)
Scope | Purpose |
| Read posts and timelines |
| Create and delete posts |
| User profiles (required by most endpoints) |
| Upload media |
| Receive refresh tokens |
Future phases will request additional scopes as features are added.
Testing Without API Access
X does not offer a sandbox environment for the core API. Here are your options for testing:
Unit tests (no API needed):
npm testAll 57 unit tests run against mocked data with zero API calls.
Mock server (no API needed):
Mockoon provides a pre-built X API v2 mock that runs locally. Point twitter-api-v2 at http://localhost:your-port for integration testing without credentials.
Free tier (limited, may be discontinued):
The Free tier ($0) allows OAuth authentication, POST /2/tweets (create), and DELETE /2/tweets/:id (delete) — but no read endpoints. You can verify the OAuth flow works and that posts are created/deleted. As of February 2026, X is transitioning to pay-per-use and the free tier may no longer be available.
VCR/cassette recording (one-time API access): Record real API responses once, replay them in tests forever. This is the approach used by Tweepy and other major Twitter libraries. If you have even temporary API access, this is the gold standard.
Recommended approach: Use unit tests + Mockoon for development. Do a single manual smoke test with real credentials before shipping.
Development
# Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run dev
# Run tests
npm test
# Manual smoke test (requires real X API credentials)
PUCK_CLIENT_ID=your_id node dist/index.jsDevelopment Phases
Phase | Status | Scope |
1 | Done | OAuth, post CRUD, threads, image upload, timelines, rate limiting |
2 | Planned | Video/GIF upload, engagement (likes, retweets, bookmarks), search |
3 | Planned | Home timeline, DMs, user lookup, follow/mute |
4 | Planned | Filtered streaming, trends, full-archive search |
License
MIT
References
A Midsummer Night's Dream — The source of the name
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
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 twitterapi.io hosted MCP: Twitter/X tweets, users, followers, trends. OAuth or API key.
Official MCP server for twitterapis.com. Twitter/X search, users, DMs, Grok, monitoring and writes.
Hosted X (Twitter) MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceAn MCP server for interacting with the Twitter/X API v2, enabling AI assistants to retrieve tweets, post content, reply, quote, and more programmatically.13MIT

X API FastMCP Serverofficial
FlicenseNot gradedqualityDmaintenanceA local MCP server that exposes the X API (formerly Twitter API) as tools, enabling operations like posting, searching, user management, and more via natural language commands.871-- FlicenseAqualityDmaintenanceAn MCP server for interacting with X/Twitter, enabling posting tweets, searching, user info, timeline, liking, retweeting, and deleting tweets.71-
- AlicenseAqualityDmaintenanceA minimal MCP server for posting tweets to X (Twitter) via API v2, supporting tweet creation, replies, and quote tweets.1MIT