Skip to main content
Glama

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
NameRequiredDescriptionDefault
reply_to_tweet_idNoOptional: ID of the tweet to reply to
textYesThe text content of the tweet (max 280 characters)

Implementation Reference

  • 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}`); } }
  • 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);

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/krishna-paulraj/x-mcp-server'

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