Skip to main content
Glama
cjkcr

X(Twitter) MCP Server

by cjkcr

retweet

Share an existing tweet with your followers by providing its ID, enabling content redistribution on X/Twitter through the MCP server.

Instructions

Retweet an existing tweet (simple retweet without comment)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tweet_idYesThe ID of the tweet to retweet

Implementation Reference

  • The main handler function for the 'retweet' tool. Validates input, calls tweepy.Client.retweet(tweet_id) using the write client, logs the action, and returns a success message or raises appropriate errors.
    async def handle_retweet(arguments: Any) -> Sequence[TextContent]:
        if not isinstance(arguments, dict) or "tweet_id" not in arguments:
            raise ValueError("Invalid arguments for retweet")
        
        tweet_id = arguments["tweet_id"]
        
        try:
            # Simple retweet without comment using the retweet method
            response = get_write_client().retweet(tweet_id)
            
            logger.info(f"Retweeted tweet {tweet_id}")
            
            return [
                TextContent(
                    type="text",
                    text=f"Successfully retweeted tweet {tweet_id}",
                )
            ]
        except tweepy.TweepError as e:
            logger.error(f"Twitter API error retweeting tweet {tweet_id}: {e}")
            raise RuntimeError(f"Twitter API error retweeting tweet {tweet_id}: {e}")
        except Exception as e:
            logger.error(f"Error retweeting tweet {tweet_id}: {str(e)}")
            raise RuntimeError(f"Error retweeting tweet {tweet_id}: {str(e)}")
  • Registers the 'retweet' tool in the list_tools() function, providing name, description, and input schema requiring a 'tweet_id' string.
    Tool(
        name="retweet",
        description="Retweet an existing tweet (simple retweet without comment)",
        inputSchema={
            "type": "object",
            "properties": {
                "tweet_id": {
                    "type": "string",
                    "description": "The ID of the tweet to retweet",
                },
            },
            "required": ["tweet_id"],
        },
    ),
  • Dispatches calls to the 'retweet' tool handler in the general call_tool function.
    elif name == "retweet":
        return await handle_retweet(arguments)

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/cjkcr/x-mcp'

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