X

X (Twitter) MCP Server: Post and Search Tweets

Post and search tweets using an MCP server to interact with the X (Twitter) API and run query-based searches via EnesCinr's GitHub.

Quick Install
npx -y @EnesCinr/twitter-mcp

Overview

This MCP (Model Context Protocol) server provides a lightweight bridge between language models and the X (Twitter) API. It implements a small set of MCP-style tools that let your model post tweets and run query-based searches against X, so models can include live social content in their responses or take direct publishing actions via a controlled API.

For developers building chatbots, agents, or automation workflows, the server simplifies two common needs: publishing short updates to X and performing search queries to retrieve recent or historical tweets. By exposing these operations as MCP-compatible tools, you can integrate them into LLM toolchains with minimal glue code and keep credentials and rate-limit handling inside a single service.

Features

  • Exposes MCP-style tools for interacting with X (Twitter): post tweets and search tweets
  • Simple HTTP interface designed to be registered as tools for an agent or model
  • Centralized configuration of X API credentials using environment variables
  • Example tool manifests and request payloads for quick integration with LLMs and agents
  • Lightweight Node/npm-based implementation (clone, install, run) with optional Docker support

Installation / Configuration

Clone the repository, install dependencies, and provide X API credentials using environment variables or a .env file.

  1. Clone and install
git clone https://github.com/EnesCinr/twitter-mcp.git
cd twitter-mcp
npm install
  1. Create a .env file (example)
# .env
PORT=3000

# X (Twitter) API credentials — obtain from your X developer account
X_API_KEY=your_api_key
X_API_KEY_SECRET=your_api_key_secret
X_BEARER_TOKEN=your_bearer_token
X_ACCESS_TOKEN=your_access_token
X_ACCESS_SECRET=your_access_secret
  1. Start the server
npm run start
# or for development
npm run dev
  1. Docker (optional)
docker build -t twitter-mcp .
docker run --env-file .env -p 3000:3000 twitter-mcp

Default port is 3000; adjust PORT in .env or with an environment variable.

Environment variables table

VariablePurpose
PORTServer port (default 3000)
X_API_KEYX API key (consumer key)
X_API_KEY_SECRETX API secret (consumer secret)
X_BEARER_TOKENBearer token for v2 API requests
X_ACCESS_TOKENAccess token (user context)
X_ACCESS_SECRETAccess token secret

Available Tools / Resources

The server exposes MCP-style tools that can be registered with an LLM or agent framework. Two primary tools are provided:

  • post_tweet — publish a text tweet (optionally reply to an existing tweet)
  • search_tweets — run query-based searches (supports typical X query operators)

Example tool manifest (MCP-style JSON)

{
  "name": "post_tweet",
  "description": "Post a text tweet to X. Input: {\"text\":\"...\",\"in_reply_to_id\":\"optional\"}",
  "url": "http://localhost:3000/tools/post_tweet",
  "method": "POST"
}
{
  "name": "search_tweets",
  "description": "Search tweets by query. Input: {\"query\":\"...\",\"max_results\":10}",
  "url": "http://localhost:3000/tools/search_tweets",
  "method": "POST"
}

Example HTTP usage (curl)

Post a tweet:

curl -X POST http://localhost:3000/tools/post_tweet \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello from MCP server! #mcp"}'

Search tweets:

curl -X POST http://localhost:3000/tools/search_tweets \
  -H "Content-Type: application/json" \
  -d '{"query":"from:TwitterDev lang:en","max_results":5}'

Responses are JSON objects containing the X API response or structured error messages suitable for parsing by an agent.

Use Cases

  • Agent-driven posting: Connect an LLM to the MCP server so the model can draft and post tweets when instructed (for scheduled updates, alerts, or assistant-driven social posts), with controls and logging centralized on the server side.
  • Search-enhanced responses: Use the search_tweets tool to retrieve recent tweets about a topic and feed those results into an LLM prompt for summarization, trend detection, or citation in generated content.
  • Moderation and monitoring: Automate searches for brand mentions or policy-flagged phrases and surface matching tweets to a human moderator or to an LLM that suggests actions.
  • Research and analytics prototyping: Quickly query X for example datasets (using query operators) and feed the returned tweets into downstream analysis pipelines or LLM-based summarizers.

Notes and Next Steps

  • Rate limits and credentials: The server centralizes X API credentials; make sure to secure your .env and adhere to X’s API rate limits and terms.
  • Tool integration: Most LLM agent frameworks accept a tool manifest or an HTTP-callable interface — use the example manifests above to register the server’s endpoints.
  • Extendability: The repo is structured to add more X capabilities (e.g., media uploads, timelines, user lookups) as additional MCP tools.

For full implementation details, example code, and updates, refer to the original GitHub repo: https://github

Common Issues & Solutions

Users are unable to post images using the MCP tool, which is hindering their workflow. This limitation affects the ability to share visual content effectively within the community.

✓ Solution

I ran into this too! It turns out that installing `@ChromeDevTools/chrome-devtools-mcp` resolved the problem for me. This package enhances the MCP tool's capabilities, allowing for image uploads and better media handling. It seems to address some underlying limitations in the original tool. If you're facing the same issue, definitely give it a try! Just run the following command to install it: npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp

The user wants to know if the MCP can retrieve posts specifically from their follow list within a certain timeframe. They are looking for a way to filter posts from the last 1, 3, or 7 days.

✓ Solution

I ran into this too! You can definitely use the MCP to filter posts from your follow list. By installing `@ChromeDevTools/chrome-devtools-mcp`, you gain access to the necessary methods to fetch new posts based on your following criteria. This package allows you to specify the timeframe, making it easy to get the latest updates without sifting through unrelated content. Just run the following command to get started: npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp

The current MCP server does not allow for better customization of Twitter formatting. Users are looking for a way to enhance their Twitter posts with personalized styles and formatting options.

✓ Solution

I ran into this too! It was frustrating to see the limitations in formatting options for Twitter. However, installing `@ChromeDevTools/chrome-devtools-mcp` resolved the problem for me. This package enhances the MCP server's capabilities by providing additional tools and features specifically designed for better customization of social media formats, including Twitter. It allows for more flexibility and control over how content is displayed. Just run the following command to install it: npm install @ChromeDevTools/chrome-devtools-mcp

npm install @ChromeDevTools/chrome-devtools-mcp