Skip to main content
Glama
cjkcr

X(Twitter) MCP Server

by cjkcr

quote_tweet

Share a tweet with your own commentary to provide context, add perspective, or engage in discussion on X (Twitter).

Instructions

Quote tweet with comment (retweet with your own comment)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
commentYesYour comment on the quoted tweet
tweet_idYesThe ID of the tweet to quote

Implementation Reference

  • The main handler function for the 'quote_tweet' tool. It validates the input arguments (tweet_id and comment), uses the Twitter API client to create a quote tweet by calling create_tweet with quote_tweet_id parameter, logs the result, and returns a success message with the new quote tweet ID.
    async def handle_quote_tweet(arguments: Any) -> Sequence[TextContent]:
        if not isinstance(arguments, dict) or "tweet_id" not in arguments or "comment" not in arguments:
            raise ValueError("Invalid arguments for quote_tweet")
        
        tweet_id = arguments["tweet_id"]
        comment = arguments["comment"]
        
        try:
            # Quote tweet with comment
            response = get_write_client().create_tweet(text=comment, quote_tweet_id=tweet_id)
            quote_tweet_id = response.data['id']
            
            logger.info(f"Quote tweeted tweet {tweet_id} with comment. Quote tweet ID: {quote_tweet_id}")
            
            return [
                TextContent(
                    type="text",
                    text=f"Successfully quote tweeted tweet {tweet_id} with comment. Quote tweet ID: {quote_tweet_id}",
                )
            ]
        except tweepy.TweepError as e:
            logger.error(f"Twitter API error quote tweeting tweet {tweet_id}: {e}")
            raise RuntimeError(f"Twitter API error quote tweeting tweet {tweet_id}: {e}")
        except Exception as e:
            logger.error(f"Error quote tweeting tweet {tweet_id}: {str(e)}")
            raise RuntimeError(f"Error quote tweeting tweet {tweet_id}: {str(e)}")
  • Registration of the 'quote_tweet' tool in the list_tools() function decorated with @server.list_tools(). Defines the tool name, description, and input schema for MCP.
        name="quote_tweet",
        description="Quote tweet with comment (retweet with your own comment)",
        inputSchema={
            "type": "object",
            "properties": {
                "tweet_id": {
                    "type": "string",
                    "description": "The ID of the tweet to quote",
                },
                "comment": {
                    "type": "string",
                    "description": "Your comment on the quoted tweet",
                },
            },
            "required": ["tweet_id", "comment"],
        },
    ),
  • Input schema definition for the 'quote_tweet' tool, specifying required string parameters 'tweet_id' and 'comment'.
        "type": "object",
        "properties": {
            "tweet_id": {
                "type": "string",
                "description": "The ID of the tweet to quote",
            },
            "comment": {
                "type": "string",
                "description": "Your comment on the quoted tweet",
            },
        },
        "required": ["tweet_id", "comment"],
    },
  • Dispatch/registration in the call_tool() function that routes calls to the 'quote_tweet' tool to its handler function.
    elif name == "quote_tweet":
        return await handle_quote_tweet(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