0.0.1 • Published 10 months ago
@crazyrabbitltc/mcp-twitter-server v0.0.1
# Twitter MCP Server
A Model Context Protocol (MCP) server that allows Large Language Models (LLMs) to interact with Twitter (X). This server provides tools for posting tweets, searching tweets, and replying to tweets.
## Features
- **Post Tweets:** Allows LLMs to post new tweets to your Twitter account.
- **Search Tweets:** Allows LLMs to search for tweets based on keywords.
- **Reply to Tweets:** Allows LLMs to reply to existing tweets, which can be used to make threads.
## Prerequisites
Before you begin, ensure you have met the following requirements:
* **Node.js** (version 18 or higher) installed. You can download it from [nodejs.org](https://nodejs.org/).
* **npm** (comes with Node.js)
* A **Twitter Developer Account** and API keys (see [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard)). You will need API Key, API Secret Key, Access Token, Access Token Secret.
* **Claude for Desktop** installed. You can download it from [claude.ai/download](https://claude.ai/download).
## Installation
1. **Clone the repository:**
```bash
git clone <repository_url>
cd <repository_directory>
```
2. **Install dependencies:**
```bash
npm install
```
3. **Set up environment variables:**
* Create a `.env` file in the root of the repository.
* Add your Twitter API keys and access tokens.
```env
# Twitter API Credentials
X_API_KEY=your_api_key
X_API_SECRET=your_api_secret
X_ACCESS_TOKEN=your_access_token
X_ACCESS_TOKEN_SECRET=your_access_token_secret
```
* Replace `your_api_key`, `your_api_secret`, `your_access_token`, and `your_access_token_secret` with your actual Twitter API credentials.
4. **Build the server:**
```bash
npm run build
```
## Running the Server
To start the server:
```bash
node dist/index.jsThe server will start and listen for MCP connections, logging to the console.
Using with Claude Desktop
To connect this Twitter MCP server to Claude Desktop:
- Open Claude Desktop Settings:
- Open the Claude Desktop application.
- Click the Claude menu from the top of your screen.
- Select "Settings...".
- Open Developer Settings:
- Select the "Developer" tab in the left panel.
- Click "Edit Config." This should open a
claude_desktop_config.jsonfile in your text editor. If this file doesn't exist, it will be created for you.
Add the Server Configuration:
- Add the following configuration inside the
mcpServersobject inclaude_desktop_config.json. If you don't have this object, create it. Make sure that this file is in valid JSON format. - Important: Update the
"args"path to match the location of yourdist/index.jsfile and add your actual twitter keys in theenvsection.
{ "mcpServers": { "twitter": { "command": "node", "args": [ "/ABSOLUTE/PATH/TO/YOUR/PROJECT/dist/index.js" ], "env": { "X_API_KEY": "YOUR_TWITTER_API_KEY", "X_API_SECRET": "YOUR_TWITTER_API_SECRET", "X_ACCESS_TOKEN": "YOUR_TWITTER_ACCESS_TOKEN", "X_ACCESS_TOKEN_SECRET": "YOUR_TWITTER_ACCESS_TOKEN_SECRET" } } } }- Replace
/ABSOLUTE/PATH/TO/YOUR/PROJECTwith the correct absolute path to the directory containing yourdist/index.jsfile. - Replace
YOUR_TWITTER_API_KEY,YOUR_TWITTER_API_SECRET,YOUR_TWITTER_ACCESS_TOKEN, andYOUR_TWITTER_ACCESS_TOKEN_SECRETwith your actual Twitter API credentials in theenvsection. - macOS path example:
/Users/yourusername/path/to/your/project/dist/index.js - Windows path example:
C:\\Users\\yourusername\\path\\to\\your\\project\\dist\\index.js
- Add the following configuration inside the
Save and Restart:
- Save the
claude_desktop_config.jsonfile. - Restart Claude Desktop.
- Save the
After restarting, the Twitter MCP server should be connected. You can verify this by:
- Looking for the hammer icon in the input bar
- Clicking the icon to see that the
postTweet,searchTweets, andreplyToTweettools are available.
Using the tools in Claude
Once the server is set up and connected, you can use the available tools by prompting Claude. For example:
Post a tweet:
Post a tweet saying "Hello, world!"Search for tweets:
Search for tweets about "artificial intelligence".Reply to a tweet:
- First search for a tweet using the
searchTweetstool:
Search for tweets about "test"* Copy the tweet `id` from the search results.- Then reply to the tweet:
Reply to tweet with id <PASTE_TWEET_ID_HERE> saying "This is a reply."- Replace
<PASTE_TWEET_ID_HERE>with the tweet id you got from the search results.
- First search for a tweet using the
Claude will interpret the prompts, identify the appropriate tools, and execute them through the server.
Important Notes:
- When Claude is executing these tools, it will ask you for permission before actually performing actions (posting a tweet etc)
- If you are getting errors, you can view the logs by checking
~/Library/Logs/Claudeon MacOS and%APPDATA%\Claude\logson Windows.
Development
To run the server outside of Claude, you can:
- Set up environment variables: Make sure you have setup your
.envfile with your twitter keys - Build the server:
npm run build - Run the server directly:
node dist/index.js
Contributing
Contributions are welcome! Please feel free to submit pull requests or create issues to suggest improvements.
License
This project is licensed under the MIT License.
0.0.1
10 months ago