Used for loading environment variables for Twitter API credentials and server configuration
Provides code linting with TypeScript rules for the project
Required for cloning the repository during installation
Used for comprehensive testing of the Twitter MCP server functionality
Required runtime environment for the Twitter MCP server, version 18+
Used for package management and running development scripts
Used for code formatting in the development workflow
Provides type checking and strict typing for the Twitter MCP server implementation
Twitter MCP Server
A Model Context Protocol (MCP) server for Twitter API with posting, searching, and timeline features.
Features
- Post Tweets: Post new tweets with optional reply functionality
- Search Tweets: Search for tweets using query strings
- Get Timelines: Retrieve user timelines
- Rate Limiting: Basic rate limiting for Twitter API calls
- TypeScript: Full TypeScript support with strict type checking
- Testing: Comprehensive test suite with Jest
Prerequisites
- Node.js 18+
- Twitter API credentials (API Key, API Secret, Access Token, Access Token Secret, Bearer Token)
Installation
- Clone the repository:
- Install dependencies:
- Set up environment variables:
Edit .env
with your Twitter API credentials:
Usage
Build and Run
Development
MCP Tools
The server provides the following MCP tools:
post_tweet
Post a new tweet with optional reply functionality.
Parameters:
text
(string, required): The text content of the tweetreply_to_tweet_id
(string, optional): Tweet ID to reply to
Example:
search_tweets (Requires Basic/Pro plan)
Search for tweets using a query string.
Parameters:
query
(string, required): Search query for tweetsmax_results
(number, optional): Maximum number of results (default: 10)
Example:
get_timeline
Get tweets from a user's timeline.
Parameters:
username
(string, required): Username to get timeline formax_results
(number, optional): Maximum number of results (default: 10)
Example:
get_rate_limit_info
Get current rate limit information.
Parameters: None
Example:
Configuration
Environment Variables
Variable | Description | Default |
---|---|---|
TWITTER_API_KEY | Twitter API Key | Required |
TWITTER_API_SECRET | Twitter API Secret | Required |
TWITTER_ACCESS_TOKEN | Twitter Access Token | Required |
TWITTER_ACCESS_TOKEN_SECRET | Twitter Access Token Secret | Required |
TWITTER_BEARER_TOKEN | Twitter Bearer Token | Required |
NODE_ENV | Environment | production |
LOG_LEVEL | Log level | info |
RATE_LIMIT_WINDOW_MS | Rate limit window | 900000 (15 min) |
RATE_LIMIT_MAX_REQUESTS | Max requests per window | 300 |
Rate Limiting
The server implements basic rate limiting:
- Respects Twitter's API rate limits
- Provides rate limit information via
get_rate_limit_info
tool - Graceful error handling for rate limit exceeded scenarios
Project Structure
Testing
The project includes comprehensive tests:
Tests cover:
- Twitter service functionality
- Rate limiting
- Error handling
- Tool parameter validation
Development
Available Scripts
Code Quality
- TypeScript: Strict type checking
- ESLint: Code linting with TypeScript rules
- Prettier: Code formatting
- Jest: Testing framework
Error Handling
The server includes comprehensive error handling:
- Twitter API errors (rate limits, authentication, etc.)
- Network errors
- Validation errors
- Graceful shutdown handling
Security
- Environment variable validation
- Input validation
- Error handling without information leakage
- Secure credential management
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Model Context Protocol server that enables programmatic interaction with Twitter API, allowing users to post tweets, search for content, and retrieve user timelines through standardized MCP tools.
Related MCP Servers
- -securityAlicense-qualityEnables interaction with Twitter through a Model Context Protocol, allowing large language models to post tweets, search for tweets, and reply to tweets.Last updated -25318TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI to interact with Twitter, allowing functions like searching tweets, comparing sentiments across accounts, and retrieving timeline content.Last updated -MIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI models and applications to interact directly with Twitter/X, providing capabilities to create posts, reply to tweets, retrieve user data, and manage account actions.Last updated -108TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI agents to interact with Twitter without direct API access, supporting tweet operations, user interactions, and Grok AI integration.Last updated -1513TypeScriptMIT License