{
  "markdown": "# Twitter/X MCP\n\n[![CI](https://github.com/granitebps/twitter-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/granitebps/twitter-mcp/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/%40granitebps%2Ftwitter-mcp.svg)](https://www.npmjs.com/package/@granitebps/twitter-mcp)\n[![npm downloads](https://img.shields.io/npm/dm/%40granitebps%2Ftwitter-mcp.svg)](https://www.npmjs.com/package/@granitebps/twitter-mcp)\n[![MCP Registry](https://img.shields.io/badge/MCP-Registry-5A67D8.svg)](https://registry.modelcontextprotocol.io/v0.1/servers?search=io.github.granitebps%2Ftwitter-mcp)\n[![License: ISC](https://img.shields.io/badge/License-ISC-yellow.svg)](LICENSE)\n\nTwitter/X MCP lets an MCP client read public X posts, replies, and profiles, or search X. It uses Rettiwt by default, so you do not need an X developer plan. You can switch to the official X API if you have access.\n\n## Requirements\n\n- Node.js 22.21.0 or newer within the Node 22 release line. The current Rettiwt release does not support Node 23 or later.\n- A `RETTIWT_API_KEY`. Official X API credentials work when you select API mode.\n\n## Quick start\n\nOnce the package is published, your MCP client can run it without a clone:\n\n```bash\nnpx -y @granitebps/twitter-mcp\n```\n\nThe server selects Rettiwt when you omit `TWITTER_MODE`. Pass `RETTIWT_API_KEY` in the client configuration.\n\nThe server uses stdio. Keep stdout reserved for MCP traffic.\n\n## Run from a cloned repository\n\nTo develop the server or use a clone directly:\n\n```bash\ngit clone https://github.com/granitebps/twitter-mcp.git\ncd twitter-mcp\nnpm ci\nnpm run build\n```\n\nPoint your MCP client at the compiled entry point:\n\n```text\nnode /absolute/path/to/twitter-mcp/dist/cli.js\n```\n\nRun `npm run build` after each source change. Do not use `src` or `npm run dev` as the client's stdio command. Build logs on stdout can corrupt MCP messages.\n\n## Client configuration\n\nEach example starts with the npm package, followed by the local equivalent. Replace `/absolute/path/to/twitter-mcp` with your clone's path and `your_key_here` with your Rettiwt key. Do not commit a configuration file that contains the key.\n\n### Claude\n\nAdd the npm package to Claude Code:\n\n```bash\nclaude mcp add twitter --env RETTIWT_API_KEY=your_key_here -- npx -y @granitebps/twitter-mcp\n```\n\nFor a local build:\n\n```bash\nclaude mcp add twitter --env RETTIWT_API_KEY=your_key_here -- node /absolute/path/to/twitter-mcp/dist/cli.js\n```\n\nClaude Code uses local scope by default. Add `--scope user` before `twitter` to make the server available across projects.\n\nClaude Desktop reads the same server from `claude_desktop_config.json`. Restart the app after editing the file.\n\n```json\n{\n  \"mcpServers\": {\n    \"twitter\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@granitebps/twitter-mcp\"],\n      \"env\": {\n        \"RETTIWT_API_KEY\": \"your_key_here\"\n      }\n    }\n  }\n}\n```\n\nFor a local build, replace `command` and `args` with:\n\n```json\n{\n  \"command\": \"node\",\n  \"args\": [\"/absolute/path/to/twitter-mcp/dist/cli.js\"]\n}\n```\n\n### Codex\n\nAdd the npm package to `~/.codex/config.toml`, or to `.codex/config.toml` in a trusted project:\n\n```toml\n[mcp_servers.twitter]\ncommand = \"npx\"\nargs = [\"-y\", \"@granitebps/twitter-mcp\"]\n\n[mcp_servers.twitter.env]\nRETTIWT_API_KEY = \"your_key_here\"\n```\n\nFor a local build:\n\n```toml\n[mcp_servers.twitter]\ncommand = \"node\"\nargs = [\"/absolute/path/to/twitter-mcp/dist/cli.js\"]\n\n[mcp_servers.twitter.env]\nRETTIWT_API_KEY = \"your_key_here\"\n```\n\nRestart Codex after editing the file. The CLI, IDE extension, and desktop app share this configuration on the same computer.\n\n### OpenCode\n\nAdd the npm package to `opencode.json` or `opencode.jsonc`:\n\n```json\n{\n  \"$schema\": \"https://opencode.ai/config.json\",\n  \"mcp\": {\n    \"twitter\": {\n      \"type\": \"local\",\n      \"command\": [\"npx\", \"-y\", \"@granitebps/twitter-mcp\"],\n      \"enabled\": true,\n      \"environment\": {\n        \"RETTIWT_API_KEY\": \"your_key_here\"\n      }\n    }\n  }\n}\n```\n\nFor a local build, replace the `command` array with:\n\n```json\n{\n  \"command\": [\"node\", \"/absolute/path/to/twitter-mcp/dist/cli.js\"]\n}\n```\n\n### Cursor\n\nAdd the npm package to `.cursor/mcp.json` in a project, or to `~/.cursor/mcp.json` for global use:\n\n```json\n{\n  \"mcpServers\": {\n    \"twitter\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@granitebps/twitter-mcp\"],\n      \"env\": {\n        \"RETTIWT_API_KEY\": \"your_key_here\"\n      }\n    }\n  }\n}\n```\n\nFor a local build, replace `command` and `args` with:\n\n```json\n{\n  \"command\": \"node\",\n  \"args\": [\"/absolute/path/to/twitter-mcp/dist/cli.js\"]\n}\n```\n\n## Providers\n\n| Mode         | Selection                          | Credentials                                | Notes                                                                                               |\n| ------------ | ---------------------------------- | ------------------------------------------ | --------------------------------------------------------------------------------------------------- |\n| Rettiwt      | Default, or `TWITTER_MODE=rettiwt` | `RETTIWT_API_KEY`                          | Free of X API charges. Uses unofficial internal endpoints and may break or put the account at risk. |\n| Official API | `TWITTER_MODE=api`                 | Bearer token or complete OAuth credentials | Uses the supported X API. X controls access tiers and pricing.                                      |\n\n### Rettiwt setup\n\nRettiwt requires authenticated user mode in this server. Guest mode is not supported.\n\n1. Generate an API key using the [Rettiwt authentication instructions](https://github.com/Rishikant181/Rettiwt-API#authentication).\n2. Store it as `RETTIWT_API_KEY` in the MCP client's environment.\n3. Start the server without `TWITTER_MODE`, or set `TWITTER_MODE=rettiwt` explicitly.\n\nA Rettiwt key contains X session cookies and has the same access as the account. Treat it like a password. Do not commit it, paste it into an issue, log it, or pass it as a command-line argument. Use a key only for an account you own or have permission to access.\n\nRettiwt is unofficial. X's [automation rules](https://help.x.com/en/rules-and-policies/x-automation) prohibit non-API website automation and warn that violations may lead to account suspension. Read the [X Rules](https://help.x.com/en/rules-and-policies/x-rules) before using this mode. You accept the compliance and account risk.\n\n### Official X API setup\n\nUse a bearer token:\n\n```env\nTWITTER_MODE=api\nTWITTER_BEARER_TOKEN=your_bearer_token\n```\n\nOr provide the complete OAuth set:\n\n```env\nTWITTER_MODE=api\nTWITTER_API_KEY=your_api_key\nTWITTER_API_SECRET=your_api_secret\nTWITTER_ACCESS_TOKEN=your_access_token\nTWITTER_ACCESS_SECRET=your_access_secret\n```\n\nCreate credentials in the [X Developer Portal](https://developer.x.com/en/portal/dashboard). X controls API access and pricing, so check the current terms before choosing this mode.\n\n## Configuration\n\n| Variable                     | Required        | Meaning                                                     |\n| ---------------------------- | --------------- | ----------------------------------------------------------- |\n| `TWITTER_MODE`               | No              | `rettiwt` by default, or `api`. Other values fail startup.  |\n| `RETTIWT_API_KEY`            | Rettiwt mode    | Authenticated Rettiwt session key.                          |\n| `TWITTER_BEARER_TOKEN`       | API mode option | Official API bearer token.                                  |\n| `TWITTER_API_KEY`            | OAuth option    | OAuth application key.                                      |\n| `TWITTER_API_SECRET`         | OAuth option    | OAuth application secret.                                   |\n| `TWITTER_ACCESS_TOKEN`       | OAuth option    | OAuth access token.                                         |\n| `TWITTER_ACCESS_SECRET`      | OAuth option    | OAuth access secret.                                        |\n| `TWITTER_REQUEST_TIMEOUT_MS` | No              | Request deadline from 1,000 to 120,000 ms. Default: 30,000. |\n\nThe server rejects an incomplete OAuth configuration at startup. It reads credentials from the process environment and never returns them through `get_server_info`.\n\n## Tools\n\n| Tool                | Input                              | Result                                                                               |\n| ------------------- | ---------------------------------- | ------------------------------------------------------------------------------------ |\n| `get_tweet`         | `tweet_id`                         | One post. Accepts a numeric ID or an `x.com` or `twitter.com` status URL.            |\n| `get_tweet_replies` | `tweet_id`, optional `max_results` | Replies and available page metadata.                                                 |\n| `get_user_profile`  | `username`                         | One public profile. A leading `@` is accepted.                                       |\n| `search_tweets`     | `query`, optional `max_results`    | Matching posts and available page metadata. Search operators depend on the provider. |\n| `get_server_info`   | None                               | Version, active provider, tools, limits, and capabilities.                           |\n\n`max_results` defaults to 10 and accepts 1 through 100. Successful calls return structured MCP content plus JSON text for older clients. Collection tools return the items as JSON text and put cursors and warnings in structured content.\n\nThe [v1 compatibility contract](https://github.com/granitebps/twitter-mcp/blob/main/docs/v1-compatibility.md)\nrecords the stable tool, input, output, and error behavior for the 1.x release\nline.\n\n## Errors\n\nTool failures use stable codes:\n\n- `INVALID_INPUT`\n- `AUTH_REQUIRED`\n- `AUTH_FAILED`\n- `NOT_FOUND`\n- `RATE_LIMITED`\n- `UPSTREAM_UNAVAILABLE`\n- `TIMEOUT`\n- `UNSUPPORTED_OPERATION`\n- `INTERNAL_ERROR`\n\nErrors name the provider and tell the client whether a retry may work. They do not include credentials or raw upstream response bodies.\n\n## Architecture\n\n```text\nstdio CLI\n  -> validated environment configuration\n  -> MCP server and tool handlers\n  -> TwitterProvider contract\n       -> Rettiwt adapter\n       -> official X API adapter\n```\n\nThe domain schemas do not depend on either provider. Each provider adapter maps upstream data, enforces limits and deadlines, and translates errors. Importing `src/index.ts` does not start the server.\n\n## Development\n\n```bash\nnpm ci\nnpm run check\n```\n\n`npm run check` checks formatting, lint, types, coverage, the production build, npm package contents, and a clean tarball installation. The default test suite uses fakes and does not need X credentials.\n\nUseful focused commands:\n\n```bash\nnpm test\nnpm run typecheck\nnpm run lint\nnpm run build\nnpm run check:package\nnpm run check:install\nnpx @modelcontextprotocol/inspector node dist/cli.js\n```\n\n### Live Rettiwt smoke test\n\nThe live smoke test starts the compiled stdio server and calls `get_tweet`, `get_tweet_replies`, `get_user_profile`, and `search_tweets`. It derives the username and search query from the selected post.\n\n```bash\nRETTIWT_API_KEY=your_key_here \\\nTWITTER_LIVE_TWEET_ID=1234567890123456789 \\\nnpm run test:live\n```\n\nChoose a public post whose author profile is still available. If either variable is missing, the command stops before starting the live server or making a network request. It does not run as part of `npm run check` or normal CI.\n\n## Release verification\n\nThe automated suite covers configuration, provider adapters, MCP calls, the compiled stdio entry point, and installation from an npm tarball. The live Rettiwt smoke test is optional and does not run in normal CI. Version 1.0.0 was prepared without live upstream verification.\n\nMaintainers can follow the [release guide](https://github.com/granitebps/twitter-mcp/blob/main/RELEASE.md)\nfor the approved-tag npm, MCP Registry, and GitHub release process. Live tests\nmust read credentials from repository secrets and must not run for untrusted\npull requests.\n\n## Troubleshooting\n\n### Missing Rettiwt key\n\nIf startup reports `RETTIWT_API_KEY is required in rettiwt mode`, set the key in the MCP client configuration. Desktop clients do not automatically inherit a shell's `.env` file.\n\n### Invalid Rettiwt authentication\n\nIf you see `Invalid authentication data` or `AUTH_FAILED`, generate a new Rettiwt key and check that the X session still works. Never post the failing key in an issue.\n\n### Rate limit\n\nFor `RATE_LIMITED`, wait before retrying and reduce the request rate. Check `retryAfterSeconds` when the provider supplies it.\n\n### Official API 401 or 403\n\nConfirm the credential set, app permissions, endpoint access, and current X API plan.\n\n### Node engine warning\n\nRun Node.js 22.21.0 or a newer Node 22 release. Do not use Node 23 or later with the current Rettiwt dependency.\n\n## License\n\n[ISC](LICENSE)\n",
  "bytes": 12888,
  "sha": "47ed7045cc97f0f54b8aef2b7a76bec557fc57e69db7bbca7e746606fce89671",
  "repo_slug": "granitebps/twitter-mcp",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_granitebps_twitter_mcp_f48f110e/readme"
}