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
| Name | Required | Description | Default |
|---|---|---|---|
| media_paths | No | ||
| reply_to | No | ||
| tags | No | ||
| text | Yes |
Implementation Reference
- src/x_twitter_mcp/server.py:190-216 (handler)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
- src/x_twitter_mcp/server.py:190-190 (registration)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")
- src/x_twitter_mcp/server.py:191-199 (schema)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. """