Skip to main content
Glama
SarthakRay26

MCP Twitter/X Server

by SarthakRay26

MCP Twitter/X Server

A Model Context Protocol (MCP) server that provides integration with Twitter/X, allowing you to read posts from users and create new posts.

Features

  • Read Posts: Fetch the latest tweets from any public Twitter/X user

  • Create Posts: Post new tweets to your Twitter/X account

  • Get Specific Post: Retrieve a specific tweet by its ID

  • Search Posts: Search for tweets matching a query

  • Configurable Options: Control tweet count, include/exclude replies and retweets

Related MCP server: X MCP Server

Available Tools

1. read_posts

Fetch the latest posts from a specified Twitter/X user.

Parameters:

  • username (required): The Twitter/X username (without @)

  • count (optional): Number of tweets to fetch (1-100, default: 20)

  • includeReplies (optional): Whether to include replies (default: false)

  • includeRetweets (optional): Whether to include retweets (default: true)

Example:

{
  "username": "elonmusk",
  "count": 10,
  "includeReplies": false,
  "includeRetweets": true
}

2. create_post

Create a new post on Twitter/X.

Parameters:

  • text (required): The text content of the tweet (max 280 characters)

Example:

{
  "text": "Hello, world! This is my first tweet via MCP."
}

3. get_post

Get a specific tweet by ID.

Parameters:

  • tweetId (required): The ID of the tweet to retrieve

Example:

{
  "tweetId": "1234567890123456789"
}

4. search_posts

Search for tweets matching a query.

Parameters:

  • query (required): The search query

  • count (optional): Number of tweets to fetch (1-100, default: 10)

  • resultType (optional): "recent" or "popular" (default: "recent")

Example:

{
  "query": "AI and machine learning",
  "count": 15,
  "resultType": "popular"
}

Setup

1. Prerequisites

  • Node.js 18 or higher

  • Twitter Developer Account with API access

2. Twitter API Setup

  1. Go to the Twitter Developer Portal

  2. Create a new app or use an existing one

  3. Generate the following credentials:

    • API Key

    • API Secret

    • Access Token

    • Access Token Secret

    • Bearer Token

  4. Make sure your app has the following permissions:

    • Read and Write (for creating posts)

    • Users and Tweets (for reading posts)

3. Installation

Option A: Local Installation

  1. Clone or download this repository

  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build
  4. Set up environment variables:

    cp .env.example .env

Option B: Docker Installation

  1. Clone or download this repository

  2. Set up environment variables:

    cp .env.example .env
  3. Build and run with Docker:

    docker build -t mcp-twitter-x-server .
    docker run -it --env-file .env mcp-twitter-x-server

    Or use Docker Compose:

    docker-compose up --build
  4. Edit .env and add your Twitter API credentials:

    TWITTER_API_KEY=your_api_key_here
    TWITTER_API_SECRET=your_api_secret_here
    TWITTER_ACCESS_TOKEN=your_access_token_here
    TWITTER_ACCESS_TOKEN_SECRET=your_access_token_secret_here
    TWITTER_BEARER_TOKEN=your_bearer_token_here

4. Configuration for MCP Clients

Add the server to your MCP client configuration. For example, in Claude Desktop:

{
  "mcpServers": {
    "mcp-twitter-x-server": {
      "command": "node",
      "args": ["/path/to/MCP-X/dist/index.js"],
      "env": {
        "TWITTER_API_KEY": "your_api_key_here",
        "TWITTER_API_SECRET": "your_api_secret_here",
        "TWITTER_ACCESS_TOKEN": "your_access_token_here",
        "TWITTER_ACCESS_TOKEN_SECRET": "your_access_token_secret_here",
        "TWITTER_BEARER_TOKEN": "your_bearer_token_here"
      }
    }
  }
}

Usage Examples

Reading Posts

# Get latest 5 tweets from @elonmusk (excluding replies)
{
  "tool": "read_posts",
  "arguments": {
    "username": "elonmusk",
    "count": 5,
    "includeReplies": false
  }
}

Creating a Post

# Post a new tweet
{
  "tool": "create_post", 
  "arguments": {
    "text": "Just set up my MCP Twitter server! šŸš€ #MCP #TwitterAPI"
  }
}

Searching Posts

# Search for recent tweets about AI
{
  "tool": "search_posts",
  "arguments": {
    "query": "artificial intelligence",
    "count": 10,
    "resultType": "recent"
  }
}

Response Format

Tweet Object Structure

{
  "id": "1234567890123456789",
  "text": "This is a tweet",
  "author": {
    "username": "example_user",
    "name": "Example User",
    "id": "987654321"
  },
  "created_at": "2023-10-01T12:00:00.000Z",
  "metrics": {
    "likes": 42,
    "retweets": 7,
    "replies": 3,
    "quotes": 1
  },
  "url": "https://twitter.com/example_user/status/1234567890123456789"
}

Development

Scripts

  • npm run build - Build the TypeScript project

  • npm run start - Start the server

  • npm run dev - Development mode with auto-restart

  • npm run clean - Clean build artifacts

Project Structure

src/
ā”œā”€ā”€ index.ts              # Main MCP server
ā”œā”€ā”€ twitter-client.ts     # Twitter API v2 wrapper
ā”œā”€ā”€ twitter-client-v1.ts  # Twitter API v1.1 fallback
dist/                     # Compiled JavaScript
mcp-config.json           # Sample MCP configuration
.env.example              # Environment variables template

Error Handling

The server includes comprehensive error handling for:

  • Invalid Twitter API credentials

  • Rate limiting

  • User not found

  • Tweet not found

  • Invalid parameters

  • Network errors

All errors are returned in a structured format:

{
  "success": false,
  "error": "Detailed error message"
}

Rate Limiting

The Twitter API has rate limits. The server will throw errors when limits are exceeded. Consider implementing caching or request throttling for production use.

Security Notes

  • Never commit your .env file with real credentials

  • Use environment variables for all sensitive configuration

  • Consider implementing additional authentication for production deployments

  • Monitor your Twitter API usage to avoid unexpected charges

License

MIT License - see LICENSE file for details.

Docker MCP Registry

This server is designed to be compatible with the Docker MCP Registry. The repository includes:

  • Dockerfile - Container configuration for production deployment

  • docker-compose.yml - Easy local testing with Docker

  • tools.json - Tool definitions for the Docker MCP Registry

  • .dockerignore - Optimized Docker build context

Using with Docker MCP Toolkit

This server can be easily installed and managed through Docker Desktop's MCP Toolkit once it's available in the Docker MCP Registry.

Contributing

  1. Fork the repository

  2. Create a feature branch

  3. Make your changes

  4. Test with Docker: docker-compose up --build

  5. Submit a pull request

Support

For issues related to:

Available Tools

4 tools
create_postB

Create a new post on Twitter/X

ParametersJSON Schema
NameRequiredDescriptionDefault
textYesThe text content of the tweet (max 280 characters)

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'Create' (implying a write operation) but does not disclose any side effects, authentication requirements, rate limits, or what happens upon success/failure. This is a significant gap for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, short sentence that is front-loaded with the essential action and resource. It is concise and easy to parse, though it omits other useful details. It earns high marks for efficiency but is slightly under-specified for a complete tool description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This is a simple tool with one parameter and no output schema, but the description is minimal. It does not explain what the tool returns (e.g., the created post object), whether it requires special permissions, or any other behavioral context. Given no annotations, the description leaves important gaps for an agent to invoke the tool confidently.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema fully documents the single parameter 'text' with type, maxLength, and a clear description. The tool description does not mention parameters, so it adds no additional meaning. Given the schema coverage is 100%, a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function with a specific verb ('Create') and resource ('a new post on Twitter/X'), and it distinguishes itself from sibling tools which are all read/search operations (read_posts, get_post, search_posts). This is unambiguous and action-oriented.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The usage is implied by the verb 'Create' in contrast to the read-oriented sibling tools, but there is no explicit guidance on when to use this tool versus alternatives, nor any exclusions or prerequisites. It's clear that this is for creating posts, but no further context is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_postA

Get a specific tweet by ID

ParametersJSON Schema
NameRequiredDescriptionDefault
tweetIdYesThe ID of the tweet to retrieve

TDQS

A3.7/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden of behavioral disclosure. It only says 'Get', which implies read-only, but it does not mention authentication, error behavior, rate limits, or response format. This is a minimal coverage for a tool with no annotation-based safety hints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that is front-loaded with the action and resource. It is minimal yet complete for the purpose, with no wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This is a simple one-parameter tool, but with no output schema and no annotations, the description should at least hint at the return value or error cases. It does not, so the context is only partially complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema fully describes the 'tweetId' parameter with a clear description, and the tool description adds no extra meaning. According to the high schema coverage (100%), the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Get') with a specific resource ('tweet') and a distinguishing qualifier ('by ID'). This clearly separates it from sibling tools like read_posts (likely listing), search_posts (searching), and create_post (creating).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is for retrieving one specific tweet by ID, which provides clear context for when to use it. However, it does not explicitly mention alternatives or exclusions, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

read_postsB

Fetch the latest posts from a specified Twitter/X user

ParametersJSON Schema
NameRequiredDescriptionDefault
countNoNumber of tweets to fetch (default: 20, max: 100)
usernameYesThe Twitter/X username (without @)
includeRepliesNoWhether to include replies (default: false)
includeRetweetsNoWhether to include retweets (default: true)

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations are absent, so the description must disclose behavioral traits. It does not mention filters (includeReplies/includeRetweets), count limits, pagination, rate limits, or return structure. The bare statement 'Fetch the latest posts' gives minimal insight beyond the schema.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of ten words, front-loaded with the action and resource. There is zero redundancy or filler. Every word contributes to the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema and four parameters, the description provides a concise summary but lacks usage guidance and behavioral context. The schema compensates for parameter details, but the description does not explain expected return format or when to prefer this tool. It is adequate but not complete for a tool with no annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions and defaults for all four parameters (username, count, includeReplies, includeRetweets). The description adds no parameter-level detail beyond what the schema already provides, so the baseline of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a specific action ('Fetch the latest posts') and resource ('specified Twitter/X user'). This distinguishes it from siblings: create_post (creation), get_post (likely a single post), and search_posts (searching). The verb and target are unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention scenarios like 'when you need a user's timeline' or contrast with search_posts for keyword-based retrieval. No exclusions or alternatives are named.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_postsC

Search for tweets matching a query

ParametersJSON Schema
NameRequiredDescriptionDefault
countNoNumber of tweets to fetch (default: 10, max: 100)
queryYesThe search query
resultTypeNoType of results to return (default: recent)recent

TDQS

C2.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full responsibility for behavioral disclosure, but it only gives a terse statement. It omits details about result ordering, pagination, rate limits, or what the query matches against, making the tool's runtime behavior largely opaque.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence, which is appropriately short for a simple operation. However, it lacks any structural breakdown or additional context that could make it more useful, so it is adequate but not exemplary.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is incomplete for a tool with three parameters and no output schema. It does not explain the return format, how resultType affects behavior, or any limitations, leaving the agent with significant uncertainty about the tool's operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the parameters are fully described in the schema. The description does not add any extra parameter-specific context, but it doesn't need to since the schema is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states a search operation with a query, which distinguishes it from sibling tools like read_posts, create_post, and get_post. However, it does not explicitly name an alternative or clarify how it differs from read_posts, so it doesn't reach the top score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives such as read_posts or get_post. The absence of any contextual hints or exclusions leaves the agent without direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 4 tool updatesv1.0.0
    • First observedcreate_post
    • First observedget_post
    • First observedread_posts
    • First observedsearch_posts

TDQS

A3.5/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a clearly distinct purpose: fetching a user's timeline, creating a post, retrieving a specific post by ID, and searching by query. There is no meaningful overlap between any pair of tools.

Naming Consistency4/5

All names follow a verb_noun pattern (read_posts, create_post, get_post, search_posts), but pluralization is inconsistent (posts vs post) and 'read' vs 'get' are semantically similar yet used for different operations. Minor deviations from perfect consistency.

Tool Count5/5

With only 4 tools, the server is well-scoped for a minimal Twitter/X client. Each tool covers a core action without unnecessary duplication or overwhelming the agent.

Completeness3/5

The surface covers reading (individual and timeline), creating, and searching posts, but notably lacks a delete operation, leaving a dead end after creation. No user profile or account-related tools, which is a notable gap for the domain.

Maintenance

ActivityInactive
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables interaction with X (formerly Twitter), allowing for posting tweets, searching content, managing accounts, and organizing lists.
    8 npm
    3
    MIT
  • F
    license
    B
    quality
    D
    maintenance
    Enables users to interact with X (Twitter) through the X API. Supports posting tweets, retrieving user timelines, searching tweets, and replying to tweets with comprehensive error handling.
    3
    5 npm
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables interaction with X (Twitter) to post tweets, threads, and replies while retrieving tweet metrics and account information. It supports core management tasks like deleting tweets and verifying authentication through the Twitter API.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI assistants to interact with X (Twitter) API v2 for posting tweets, searching, liking, retweeting, and more through natural language.
    MIT