post_tweet
Automatically post tweets to X (Twitter) using the X MCP Server. Input tweet text and optionally reply to a specific tweet ID for streamlined social media engagement.
Instructions
Post a tweet to X (Twitter)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reply_to_tweet_id | No | Optional: ID of the tweet to reply to | |
| text | Yes | The text content of the tweet (max 280 characters) |
Implementation Reference
- src/index.ts:151-188 (handler)The main handler function that executes the post_tweet tool logic: validates input, posts tweet via Twitter API v2, handles replies and errors.private async postTweet(args: any) { if (!this.twitterClient) { throw new Error("Twitter client not initialized"); } const { text, reply_to_tweet_id } = args; if (!text || typeof text !== "string") { throw new Error("Text is required and must be a string"); } if (text.length > 280) { throw new Error("Tweet text cannot exceed 280 characters"); } try { const tweetOptions: any = { text }; if (reply_to_tweet_id) { tweetOptions.reply = { in_reply_to_tweet_id: reply_to_tweet_id }; } const tweet = await this.twitterClient.v2.tweet(tweetOptions); return { content: [ { type: "text", text: `Tweet posted successfully! Tweet ID: ${tweet.data.id}`, }, ], }; } catch (error) { // Provide more detailed error information const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Failed to post tweet: ${errorMessage}`); } }
- src/index.ts:32-49 (schema)The tool definition in getTools(), including name, description, and input schema for post_tweet.{ name: "post_tweet", description: "Post a tweet to X (Twitter)", inputSchema: { type: "object", properties: { text: { type: "string", description: "The text content of the tweet (max 280 characters)", }, reply_to_tweet_id: { type: "string", description: "Optional: ID of the tweet to reply to", }, }, required: ["text"], }, },
- src/index.ts:109-110 (registration)Dispatch/registration in the CallToolRequestSchema handler: routes post_tweet calls to the postTweet method.case "post_tweet": return await this.postTweet(args);