
Twitter MCP Server
A Model Context Protocol server that enables AI assistants to interact with Twitter functionality using cookie-based authentication, allowing for timeline access, tweet management, user information retrieval, and search capabilities.
README
Twitter MCP Server
A Model Context Protocol (MCP) server that provides Twitter functionality using the twikit
library. This server allows AI assistants to interact with Twitter through a standardized protocol with cookie-based authentication - the LLM model provides ct0
and auth_token
cookies directly in tool calls.
Features
- Cookie Authentication: LLM model provides
ct0
andauth_token
cookies directly in tool calls - Session Caching: Automatically caches authenticated sessions for efficiency
- Timeline Access: Get tweets from your timeline
- User Information: Retrieve user profiles and statistics
- Tweet Search: Search for tweets with specific queries
- Tweet Management: Post, like, and retweet tweets
- User Tweets: Get tweets from specific users
- Authentication Testing: Test cookies before use
Disclaimer
This project utilizes an unofficial API to interact with X (formerly Twitter) through the twikit
library. The methods employed for authentication and data retrieval are not officially endorsed by X/Twitter and may be subject to change or discontinuation without notice.
This tool is intended for educational and experimental purposes only. Users should be aware of the potential risks associated with using unofficial APIs, including but not limited to account restrictions or suspension. The developers of this project are not responsible for any misuse or consequences arising from the use of this tool.
Installation
- Clone this repository:
git clone <repository-url>
cd twitter-mcp
- Install dependencies:
pip install -r requirements.txt
- Run the server:
python server.py
Authentication
The server expects the LLM model to provide Twitter cookies directly in each tool call via the ct0
and auth_token
parameters. No pre-configuration is required!
Getting Twitter Cookies
The LLM model will need to provide both Twitter cookies. Here's how to obtain them:
- Open your browser and go to Twitter/X
- Log in to your account
- Open Developer Tools (F12)
- Go to Application/Storage → Cookies → twitter.com (or x.com)
- Find and copy these cookie values:
ct0
- CSRF token cookieauth_token
- Authentication token cookie
Both cookies are required for all operations.
Usage
Available Tools
1. Authenticate
Test authentication with cookies:
{
"tool": "authenticate",
"arguments": {
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
2. Tweet
Post a new tweet:
{
"tool": "tweet",
"arguments": {
"text": "Hello from MCP! 🚀",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
3. Get User Info
Get information about a Twitter user:
{
"tool": "get_user_info",
"arguments": {
"username": "elonmusk",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
4. Search Tweets
Search for tweets:
{
"tool": "search_tweets",
"arguments": {
"query": "artificial intelligence",
"count": 10,
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
5. Get Timeline
Get tweets from your timeline:
{
"tool": "get_timeline",
"arguments": {
"count": 20,
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
6. Like Tweet
Like a tweet by ID:
{
"tool": "like_tweet",
"arguments": {
"tweet_id": "1234567890123456789",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
7. Retweet
Retweet a tweet by ID:
{
"tool": "retweet",
"arguments": {
"tweet_id": "1234567890123456789",
"ct0": "your_ct0_cookie_here",
"auth_token": "your_auth_token_cookie_here"
}
}
Available Resources
Resources can be accessed but require the TWITTER_CT0
and TWITTER_AUTH_TOKEN
environment variables as a fallback:
1. Timeline
twitter://timeline
2. User Tweets
twitter://user-tweets#username
3. Search
twitter://search#query
Configuration
Environment Variables (Optional)
TWITTER_CT0
: Default Twitter ct0 cookie (optional, used for resources only)TWITTER_AUTH_TOKEN
: Default Twitter auth_token cookie (optional, used for resources only)
Session Management
The server automatically caches authenticated sessions per ct0
cookie to avoid repeated authentication and improve performance.
Security Features
- Cookie Caching: Sessions are cached using ct0 as the key
- Session Isolation: Each set of cookies gets its own session cache
- Direct Cookie Usage: Cookies are used directly without modification
- Automatic Validation: Cookies are tested on first use
Error Handling
The server includes comprehensive error handling for:
- Authentication failures
- Invalid cookies
- Rate limiting
- Network errors
- Invalid requests
Rate Limiting
Twitter has rate limits for API requests. The server will handle rate limiting gracefully, but be mindful of:
- Search: 300 requests per 15 minutes
- Timeline: 300 requests per 15 minutes
- User lookup: 300 requests per 15 minutes
- Tweet posting: 300 tweets per 3 hours
Security Notes
- Cookie Security: Cookies are cached temporarily for performance but not persisted to disk
- Session Caching: Sessions are cached with ct0 as the key
- Automatic Testing: Cookies are validated on first use
- Per-session Isolation: Each ct0 maintains its own session
Troubleshooting
Authentication Issues
- Use the
authenticate
tool to test cookies before other operations - Ensure both
ct0
andauth_token
cookies are valid and not expired - Check that the cookies are from the correct Twitter/X domain
- Make sure you're logged into Twitter in the browser where you copied the cookies
Rate Limiting
- Reduce the frequency of requests
- The server respects Twitter's rate limits automatically
- Monitor usage across different cookie sets
Network Issues
- Check your internet connection
- Verify Twitter's service status
- Ensure no firewall is blocking the requests
Dependencies
mcp
: Model Context Protocol implementationtwikit
: Twitter API client librarypydantic
: Data validation librarypython-dotenv
: Environment variable managementasyncio
: Asynchronous programming support
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues and questions:
- Check the troubleshooting section
- Search existing issues
- Create a new issue with detailed information
推荐服务器

Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。