Skip to main content
Glama
EnesCinr

Twitter MCP Server

post_tweet

Post new tweets to Twitter with optional replies, enabling content sharing and social media interaction through the Twitter MCP Server.

Instructions

Post a new tweet to Twitter

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe content of your tweet
reply_to_tweet_idNoOptional: ID of the tweet to reply to

Implementation Reference

  • MCP tool handler for 'post_tweet': validates input with PostTweetSchema, calls TwitterClient.postTweet, and returns success response with tweet URL.
    private async handlePostTweet(args: unknown) {
      const result = PostTweetSchema.safeParse(args);
      if (!result.success) {
        throw new McpError(
          ErrorCode.InvalidParams,
          `Invalid parameters: ${result.error.message}`
        );
      }
    
      const tweet = await this.client.postTweet(result.data.text, result.data.reply_to_tweet_id);
      return {
        content: [{
          type: 'text',
          text: `Tweet posted successfully!\nURL: https://twitter.com/status/${tweet.id}`
        }] as TextContent[]
      };
    }
  • src/index.ts:66-84 (registration)
    Tool registration metadata for 'post_tweet' returned in ListToolsRequest, including name, description, and input schema.
    {
      name: 'post_tweet',
      description: 'Post a new tweet to Twitter',
      inputSchema: {
        type: 'object',
        properties: {
          text: {
            type: 'string',
            description: 'The content of your tweet',
            maxLength: 280
          },
          reply_to_tweet_id: {
            type: 'string',
            description: 'Optional: ID of the tweet to reply to'
          }
        },
        required: ['text']
      }
    } as Tool,
  • Zod schema for post_tweet input validation, used in the handler.
    export const PostTweetSchema = z.object({
        text: z.string()
            .min(1, 'Tweet text cannot be empty')
            .max(280, 'Tweet cannot exceed 280 characters'),
        reply_to_tweet_id: z.string().optional()
    });
  • Core Twitter API posting logic in TwitterClient.postTweet, called by the MCP handler. Handles rate limiting and error handling.
    async postTweet(text: string, replyToTweetId?: string): Promise<PostedTweet> {
      try {
        const endpoint = 'tweets/create';
        await this.checkRateLimit(endpoint);
    
        const tweetOptions: any = { text };
        if (replyToTweetId) {
          tweetOptions.reply = { in_reply_to_tweet_id: replyToTweetId };
        }
    
        const response = await this.client.v2.tweet(tweetOptions);
        
        console.error(`Tweet posted successfully with ID: ${response.data.id}${replyToTweetId ? ` (reply to ${replyToTweetId})` : ''}`);
        
        return {
          id: response.data.id,
          text: response.data.text
        };
      } catch (error) {
        this.handleApiError(error);
      }
    }

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other 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/EnesCinr/twitter-mcp'

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