Skip to main content
Glama
rafaljanicki

X (Twitter) MCP server

by rafaljanicki

post_tweet

Publish tweets with text, media, replies, or hashtags using the X (Twitter) MCP server for streamlined social media posting.

Instructions

Post a tweet with optional media, reply, and tags

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
media_pathsNo
reply_toNo
tagsNo
textYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'post_tweet' tool. It handles rate limiting, initializes Twitter clients, processes text, media uploads (using v1 API), replies, tags, and posts the tweet using the v2 client. Returns the tweet data.
    @server.tool(name="post_tweet", description="Post a tweet with optional media, reply, and tags")
    async def post_tweet(text: str, media_paths: Optional[List[str]] = None, reply_to: Optional[str] = None, tags: Optional[List[str]] = None) -> Dict:
        """Posts a tweet.
    
        Args:
            text (str): The text content of the tweet. Max 280 characters.
            media_paths (Optional[List[str]]): A list of local file paths to media (images, videos) to be uploaded and attached.
            reply_to (Optional[str]): The ID of the tweet to reply to.
            tags (Optional[List[str]]): A list of hashtags (without '#') to append to the tweet.
        """
        if not check_rate_limit("tweet_actions"):
            raise Exception("Tweet action rate limit exceeded")
        client, v1_api = initialize_twitter_clients()
        tweet_data = {"text": text}
        if reply_to:
            tweet_data["in_reply_to_tweet_id"] = reply_to
        if tags:
            tweet_data["text"] += " " + " ".join(f"#{tag}" for tag in tags)
        if media_paths:
            media_ids = []
            for path in media_paths:
                media = v1_api.media_upload(filename=path)
                media_ids.append(media.media_id_string)
            tweet_data["media_ids"] = media_ids
        tweet = client.create_tweet(**tweet_data)
        logger.info(f"Type of response from client.create_tweet: {type(tweet)}; Content: {tweet}")
        return tweet.data
  • The decorator that registers the 'post_tweet' function as an MCP tool with name 'post_tweet' and its description.
    @server.tool(name="post_tweet", description="Post a tweet with optional media, reply, and tags")
  • The function signature with type annotations defining the input schema (parameters: text (str), media_paths (Optional[List[str]]), reply_to (Optional[str]), tags (Optional[List[str]]) ) and output (Dict), along with detailed docstring descriptions.
    async def post_tweet(text: str, media_paths: Optional[List[str]] = None, reply_to: Optional[str] = None, tags: Optional[List[str]] = None) -> Dict:
        """Posts a tweet.
    
        Args:
            text (str): The text content of the tweet. Max 280 characters.
            media_paths (Optional[List[str]]): A list of local file paths to media (images, videos) to be uploaded and attached.
            reply_to (Optional[str]): The ID of the tweet to reply to.
            tags (Optional[List[str]]): A list of hashtags (without '#') to append to the tweet.
        """
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states 'Post a tweet' which implies a write/mutation operation, but doesn't disclose behavioral traits like authentication needs, rate limits, whether it's idempotent, or what happens on failure (e.g., duplicate tweets). For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

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, efficient sentence that front-loads the core action ('Post a tweet') and lists optional features without waste. Every word earns its place, making it easy to scan and understand quickly.

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?

Given the tool's complexity (mutation with 4 parameters), no annotations, and an output schema (which reduces need to describe returns), the description is minimally adequate. It covers the basic purpose and parameters but lacks behavioral context and usage guidelines, making it incomplete for safe, effective use by an agent.

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 0%, so the description must compensate. It mentions 'optional media, reply, and tags' which maps to three parameters (media_paths, reply_to, tags) and implies text is required, adding some meaning beyond the bare schema. However, it doesn't explain parameter formats (e.g., what media_paths expects, how tags differ from text) or constraints, leaving gaps.

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 the action ('Post a tweet') and mentions optional features (media, reply, tags), which distinguishes it from read-only sibling tools like get_timeline or get_tweet_details. However, it doesn't explicitly differentiate from other tweet-creation tools like create_poll_tweet, which is a minor gap.

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 like create_poll_tweet for polls or reply_to for threading context. It mentions optional features but doesn't specify prerequisites, constraints, or typical use cases, leaving the agent to infer usage from parameter names alone.

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

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rafaljanicki/x-twitter-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server