Twitter Client
STDIOTwitter integration MCP server for AI models to interact with Twitter without direct API access.
Twitter integration MCP server for AI models to interact with Twitter without direct API access.
A Model Context Protocol (MCP) server that integrates with Twitter using the agent-twitter-client package, allowing AI models to interact with Twitter without direct API access.
Authentication Options:
Tweet Operations:
User Operations:
Grok Integration:
# Install globally npm install -g agent-twitter-client-mcp # Or install locally npm install agent-twitter-client-mcp
.env file with your Twitter credentials (see Authentication Methods)# If installed globally agent-twitter-client-mcp # If installed locally npx agent-twitter-client-mcp
The package includes a demo directory with example scripts that demonstrate various features:
# Clone the repository to access the demo scripts git clone https://github.com/ryanmac/agent-twitter-client-mcp.git cd agent-twitter-client-mcp/demo # Run the interactive demo menu ./run-demo.sh # Run a specific demo script ./run-demo.sh --script tweet-search.js # Run Grok AI examples (requires agent-twitter-client v0.0.19) ./run-demo.sh --script simple-grok.js --use-local-agent-twitter-client ./run-demo.sh --script grok-chat.js --use-local-agent-twitter-client
See the Demo README for more details.
By default, the MCP server runs on port 3000. If you need to change this (for example, if you already have an application running on port 3000), you have several options:
Set the PORT environment variable:
PORT=3001 npx agent-twitter-client-mcp
If using Docker Compose, you can configure both the host and container ports in your .env file:
# .env file
MCP_HOST_PORT=3001    # The port on your host machine
MCP_CONTAINER_PORT=3000  # The port inside the container
Then run:
docker-compose up -d
This will map port 3001 on your host to port 3000 in the container, allowing you to access the MCP at http://localhost:3001 while your other application continues to use port 3000.
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{ "mcpServers": { "agent-twitter-client-mcp": { "command": "npx", "args": ["-y", "agent-twitter-client-mcp"], "env": { "AUTH_METHOD": "cookies", "TWITTER_COOKIES": "[\"auth_token=YOUR_AUTH_TOKEN; Domain=.twitter.com\", \"ct0=YOUR_CT0_VALUE; Domain=.twitter.com\", \"twid=u%3DYOUR_USER_ID; Domain=.twitter.com\"]" } } } }
{ "AUTH_METHOD": "cookies", "TWITTER_COOKIES": "[\"auth_token=YOUR_AUTH_TOKEN; Domain=.twitter.com\", \"ct0=YOUR_CT0_VALUE; Domain=.twitter.com\", \"twid=u%3DYOUR_USER_ID; Domain=.twitter.com\"]" }
To obtain cookies:
auth_token, ct0, and twid cookiesDomain=.twitter.com part for each cookie{ "AUTH_METHOD": "credentials", "TWITTER_USERNAME": "your_username", "TWITTER_PASSWORD": "your_password", "TWITTER_EMAIL": "[email protected]", // Optional "TWITTER_2FA_SECRET": "your_2fa_secret" // Optional, required if 2FA is enabled }
{ "AUTH_METHOD": "api", "TWITTER_API_KEY": "your_api_key", "TWITTER_API_SECRET_KEY": "your_api_secret_key", "TWITTER_ACCESS_TOKEN": "your_access_token", "TWITTER_ACCESS_TOKEN_SECRET": "your_access_token_secret" }
get_user_tweets: Fetch tweets from a specific userget_tweet_by_id: Fetch a specific tweet by IDsearch_tweets: Search for tweetssend_tweet: Post a new tweetsend_tweet_with_poll: Post a tweet with a polllike_tweet: Like a tweetretweet: Retweet a tweetquote_tweet: Quote a tweetget_user_profile: Get a user's profilefollow_user: Follow a userget_followers: Get a user's followersget_following: Get users a user is followinggrok_chat: Chat with Grok via Twitterhealth_check: Check the health of the Twitter MCP serverThe MCP includes an interactive command-line interface for testing:
npx agent-twitter-client-mcp-test # or if installed locally npm run test:interface
This launches a REPL where you can test various MCP functions:
agent-twitter-client-mcp> help
Available commands:
  health                     Run a health check
  profile <username>         Get a user profile
  tweets <username> [count]  Get tweets from a user
  tweet <id>                 Get a specific tweet by ID
  search <query> [count]     Search for tweets
  post <text>                Post a new tweet
  like <id>                  Like a tweet
  retweet <id>               Retweet a tweet
  quote <id> <text>          Quote a tweet
  follow <username>          Follow a user
  followers <userId> [count] Get a user's followers
  following <userId> [count] Get users a user is following
  grok <message>             Chat with Grok
  help                       Show available commands
  exit                       Exit the test interface
# Run a health check
agent-twitter-client-mcp> health
# Search for tweets
agent-twitter-client-mcp> search mcp 2
# Get a user's profile
agent-twitter-client-mcp> profile elonmusk
# Get tweets from a user
agent-twitter-client-mcp> tweets openai 5
# Chat with Grok
agent-twitter-client-mcp> grok Explain quantum computing in simple terms
Ask Claude to:
To post a tweet with an image:
I want to post a tweet with an image. The tweet should say "Beautiful sunset today!" and include this image.
To post a tweet with a video:
I want to post a tweet with a video. The tweet should say "Check out this amazing video!" and include the video file.
To create a poll:
Create a Twitter poll asking "What's your favorite programming language?" with options: Python, JavaScript, Rust, and Go. The poll should run for 24 hours.
To have a conversation with Grok:
Use Grok to explain quantum computing to me. Ask it to include some real-world applications.
To continue a conversation with Grok:
Continue the Grok conversation and ask it to elaborate on quantum entanglement.
Grok on Twitter has access to real-time Twitter data that even the standalone Grok API doesn't have. This means you can ask Grok about:
Example queries:
Grok functionality requires proper authentication. The MCP supports two methods:
Cookie Authentication (Recommended):
TWITTER_COOKIES=["auth_token=YOUR_AUTH_TOKEN; Domain=.twitter.com", "ct0=YOUR_CT0_VALUE; Domain=.twitter.com", "twid=u%3DYOUR_USER_ID; Domain=.twitter.com"]auth_token, ct0, and twidUsername/Password Authentication:
TWITTER_USERNAME and TWITTER_PASSWORD in your environmentGrok has rate limits that may affect usage:
The MCP will return rate limit information in the response when limits are reached.
For more details on using Grok, see the Grok Examples documentation.
If you're experiencing issues with cookie authentication:
auth_token, ct0, and twid.Example of properly formatted cookies:
"TWITTER_COOKIES": "[\"auth_token=1234567890abcdef; Domain=.twitter.com\", \"ct0=abcdef1234567890; Domain=.twitter.com\", \"twid=u%3D1234567890; Domain=.twitter.com\"]"
If you're having trouble with username/password authentication:
TWITTER_2FA_SECRET.For API authentication issues:
If you can't post tweets:
If search isn't working:
If Grok functionality isn't working:
Version Requirement:
--use-local-agent-twitter-client flag to temporarily install v0.0.19Authentication Issues:
Rate Limits:
Environment File Location:
demo/.env, not in the root .env file--debug-env flag to check which environment variables are being loadedFor detailed troubleshooting of Grok issues, see the Grok Examples documentation.
Use the health_check tool to diagnose server issues:
Run a health check on the agent-twitter-client-mcp server to diagnose any issues.
The health check will report on:
The server logs to both console and files:
error.log: Contains error-level messagescombined.log: Contains all log messagesCheck these logs for detailed error information.
git clone https://github.com/ryanmac/agent-twitter-client-mcp.git cd agent-twitter-client-mcp
npm install
.env file with configuration:AUTH_METHOD=cookies
TWITTER_COOKIES=["cookie1=value1", "cookie2=value2"]
npm run build
npm start
In addition to the authentication variables, you can set:
LOG_LEVEL: Set logging level (error, warn, info, debug)NODE_ENV: Set environment (development, production)You can also run the server using Docker:
# Build the Docker image docker build -t agent-twitter-client-mcp . # Run the container with environment variables docker run -p 3000:3000 \ -e AUTH_METHOD=cookies \ -e TWITTER_COOKIES='["auth_token=YOUR_AUTH_TOKEN; Domain=.twitter.com", "ct0=YOUR_CT0_VALUE; Domain=.twitter.com"]' \ agent-twitter-client-mcp
.env file with your Twitter credentials# Start the service docker-compose up -d # View logs docker-compose logs -f # Stop the service docker-compose down
You can pass environment variables to the Docker container in several ways:
The docker-compose configuration includes a volume mount for logs:
volumes: - ./logs:/app/logs
This will store logs in a logs directory in your project folder.
MIT