The Twitter MCP server provides a bridge for AI models to interact with Twitter without direct API access. It supports multiple authentication methods and offers various Twitter operations including tweet management, user interactions, and integration with Grok.
npm install -g agent-twitter-client-mcp
npm install agent-twitter-client-mcp
Start the MCP server after installation:
# If installed globally
agent-twitter-client-mcp
# If installed locally
npx agent-twitter-client-mcp
By default, the server runs on port 3000. You can change this:
Using environment variables:
PORT=3001 npx agent-twitter-client-mcp
Using Docker Compose:
Add to your .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
{
"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]",
"TWITTER_2FA_SECRET": "your_2fa_secret"
}
Note: Email and 2FA secret are optional, but 2FA secret is 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"
}
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\"]"
}
}
}
}
The MCP server provides several tools:
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 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 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
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.
Grok integration requires agent-twitter-client v0.0.19 or higher.
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:
Continue the Grok conversation and ask it to elaborate on quantum entanglement.
Grok on Twitter can provide:
Example queries:
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 reports on:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "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\"]"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"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\"]"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"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\"]"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect