Skip to main content
Glama
cjkcr

X(Twitter) MCP Server

by cjkcr

reply_to_tweet

Post a direct reply to an existing X/Twitter tweet by specifying the tweet ID and reply content, enabling real-time engagement with conversations.

Instructions

Reply to an existing tweet directly (without creating a draft)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe content of the reply tweet
reply_to_tweet_idYesThe ID of the tweet to reply to

Implementation Reference

  • The main handler function for the 'reply_to_tweet' tool. It validates input arguments, uses the Twitter API client to create a reply tweet to the specified tweet ID, logs the result, and returns a success message with the new tweet ID.
    async def handle_reply_to_tweet(arguments: Any) -> Sequence[TextContent]:
        if not isinstance(arguments, dict) or "content" not in arguments or "reply_to_tweet_id" not in arguments:
            raise ValueError("Invalid arguments for reply_to_tweet")
        
        content = arguments["content"]
        reply_to_tweet_id = arguments["reply_to_tweet_id"]
        
        try:
            # Reply to the tweet directly
            response = get_write_client().create_tweet(text=content, in_reply_to_tweet_id=reply_to_tweet_id)
            tweet_id = response.data['id']
            
            logger.info(f"Published reply tweet ID {tweet_id} to tweet {reply_to_tweet_id}")
            
            return [
                TextContent(
                    type="text",
                    text=f"Successfully replied to tweet {reply_to_tweet_id} with tweet ID {tweet_id}",
                )
            ]
        except tweepy.TweepError as e:
            logger.error(f"Twitter API error: {e}")
            raise RuntimeError(f"Error replying to tweet {reply_to_tweet_id}: {e}")
        except Exception as e:
            logger.error(f"Error replying to tweet {reply_to_tweet_id}: {str(e)}")
            raise RuntimeError(f"Error replying to tweet {reply_to_tweet_id}: {str(e)}")
  • The input schema definition for the 'reply_to_tweet' tool, specifying the required 'content' and 'reply_to_tweet_id' parameters with their types and descriptions.
    Tool(
        name="reply_to_tweet",
        description="Reply to an existing tweet directly (without creating a draft)",
        inputSchema={
            "type": "object",
            "properties": {
                "content": {
                    "type": "string",
                    "description": "The content of the reply tweet",
                },
                "reply_to_tweet_id": {
                    "type": "string",
                    "description": "The ID of the tweet to reply to",
                },
            },
            "required": ["content", "reply_to_tweet_id"],
        },
    ),
  • Registration of the 'reply_to_tweet' tool handler in the main call_tool dispatcher function.
    elif name == "reply_to_tweet":
        return await handle_reply_to_tweet(arguments)
  • The list_tools function registers all available tools including 'reply_to_tweet' with its schema, making it discoverable by MCP clients.
    @server.list_tools()
    async def list_tools() -> list[Tool]:
        """List available tools for interacting with Twitter/X."""
        return [
            Tool(
                name="create_draft_tweet",
                description="Create a draft tweet",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The content of the tweet",
                        },
                    },
                    "required": ["content"],
                },
            ),
            Tool(
                name="create_draft_thread",
                description="Create a draft tweet thread",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "contents": {
                            "type": "array",
                            "items": {"type": "string"},
                            "description": "An array of tweet contents for the thread",
                        },
                    },
                    "required": ["contents"],
                },
            ),
            Tool(
                name="list_drafts",
                description="List all draft tweets and threads",
                inputSchema={
                    "type": "object",
                    "properties": {},
                    "required": [],
                },
            ),
            Tool(
                name="publish_draft",
                description="Publish a draft tweet or thread",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "draft_id": {
                            "type": "string",
                            "description": "ID of the draft to publish",
                        },
                    },
                    "required": ["draft_id"],
                },
            ),
            Tool(
                name="delete_draft",
                description="Delete a draft tweet or thread",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "draft_id": {
                            "type": "string",
                            "description": "ID of the draft to delete",
                        },
                    },
                    "required": ["draft_id"],
                },
            ),
            Tool(
                name="create_draft_reply",
                description="Create a draft reply to an existing tweet",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The content of the reply tweet",
                        },
                        "reply_to_tweet_id": {
                            "type": "string",
                            "description": "The ID of the tweet to reply to",
                        },
                    },
                    "required": ["content", "reply_to_tweet_id"],
                },
            ),
            Tool(
                name="reply_to_tweet",
                description="Reply to an existing tweet directly (without creating a draft)",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The content of the reply tweet",
                        },
                        "reply_to_tweet_id": {
                            "type": "string",
                            "description": "The ID of the tweet to reply to",
                        },
                    },
                    "required": ["content", "reply_to_tweet_id"],
                },
            ),
            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"],
                },
            ),
            Tool(
                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"],
                },
            ),
            Tool(
                name="create_draft_quote_tweet",
                description="Create a draft quote tweet with 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"],
                },
            ),
            Tool(
                name="upload_media",
                description="Upload media file (image, video, or GIF) for use in tweets",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "file_path": {
                            "type": "string",
                            "description": "Path to the media file to upload",
                        },
                        "media_type": {
                            "type": "string",
                            "enum": ["image", "video", "gif"],
                            "description": "Type of media file",
                        },
                        "alt_text": {
                            "type": "string",
                            "description": "Alternative text for accessibility (optional, for images)",
                        },
                    },
                    "required": ["file_path", "media_type"],
                },
            ),
            Tool(
                name="create_tweet_with_media",
                description="Create a tweet with attached media files",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The text content of the tweet",
                        },
                        "media_ids": {
                            "type": "array",
                            "items": {"type": "string"},
                            "description": "List of media IDs to attach to the tweet",
                        },
                    },
                    "required": ["content", "media_ids"],
                },
            ),
            Tool(
                name="create_draft_tweet_with_media",
                description="Create a draft tweet with media files",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "content": {
                            "type": "string",
                            "description": "The text content of the tweet",
                        },
                        "media_files": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "file_path": {"type": "string"},
                                    "media_type": {"type": "string", "enum": ["image", "video", "gif"]},
                                    "alt_text": {"type": "string"}
                                },
                                "required": ["file_path", "media_type"]
                            },
                            "description": "List of media files to include in the draft",
                        },
                    },
                    "required": ["content", "media_files"],
                },
            ),
            Tool(
                name="get_media_info",
                description="Get information about uploaded media",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "media_id": {
                            "type": "string",
                            "description": "The media ID to get information for",
                        },
                    },
                    "required": ["media_id"],
                },
            ),
            Tool(
                name="get_tweet",
                description="Get the content and information of a specific tweet",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "tweet_id": {
                            "type": "string",
                            "description": "The ID of the tweet to retrieve",
                        },
                        "include_author": {
                            "type": "boolean",
                            "description": "Whether to include author information (default: true)",
                            "default": True,
                        },
                    },
                    "required": ["tweet_id"],
                },
            ),
            Tool(
                name="get_tweets",
                description="Get the content and information of multiple tweets",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "tweet_ids": {
                            "type": "array",
                            "items": {"type": "string"},
                            "description": "List of tweet IDs to retrieve (max 100)",
                        },
                        "include_author": {
                            "type": "boolean",
                            "description": "Whether to include author information (default: true)",
                            "default": True,
                        },
                    },
                    "required": ["tweet_ids"],
                },
            ),
            Tool(
                name="search_tweets",
                description="Search for recent tweets (last 7 days for free users)",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string",
                            "description": "Search query (e.g., 'AI OR artificial intelligence', '#python', 'from:username')",
                        },
                        "max_results": {
                            "type": "integer",
                            "description": "Maximum number of tweets to return (default: 10, max: 100)",
                            "default": 10,
                            "minimum": 1,
                            "maximum": 100,
                        },
                        "include_author": {
                            "type": "boolean",
                            "description": "Whether to include author information (default: true)",
                            "default": True,
                        },
                    },
                    "required": ["query"],
                },
            ),
            Tool(
                name="test_api_connection",
                description="Test Twitter API connection and permissions",
                inputSchema={
                    "type": "object",
                    "properties": {},
                    "required": [],
                },
            ),
            Tool(
                name="get_global_trends",
                description="Get current global trending topics on Twitter/X",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "limit": {
                            "type": "integer",
                            "description": "Maximum number of trends to return (default: 10, max: 50)",
                            "default": 10,
                            "minimum": 1,
                            "maximum": 50,
                        },
                    },
                    "required": [],
                },
            ),
            Tool(
                name="get_regional_trends",
                description="Get trending topics for a specific region/location",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "woeid": {
                            "type": "integer",
                            "description": "Where On Earth ID for the location (e.g., 1 for worldwide, 23424977 for US, 23424856 for Japan)",
                        },
                        "location_name": {
                            "type": "string",
                            "description": "Location name (alternative to woeid, e.g., 'United States', 'Japan', 'United Kingdom')",
                        },
                        "limit": {
                            "type": "integer",
                            "description": "Maximum number of trends to return (default: 10, max: 50)",
                            "default": 10,
                            "minimum": 1,
                            "maximum": 50,
                        },
                    },
                    "required": [],
                },
            ),
            Tool(
                name="get_available_trend_locations",
                description="Get list of available locations for trend queries",
                inputSchema={
                    "type": "object",
                    "properties": {},
                    "required": [],
                },
            ),
            Tool(
                name="get_topic_details",
                description="Get detailed information about a specific trending topic or hashtag",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "topic": {
                            "type": "string",
                            "description": "The trending topic or hashtag to get details for (e.g., '#AI', 'ChatGPT')",
                        },
                        "max_results": {
                            "type": "integer",
                            "description": "Maximum number of related tweets to return (default: 20, max: 100)",
                            "default": 20,
                            "minimum": 1,
                            "maximum": 100,
                        },
                        "include_retweets": {
                            "type": "boolean",
                            "description": "Whether to include retweets in results (default: false)",
                            "default": False,
                        },
                    },
                    "required": ["topic"],
                },
            ),
            Tool(
                name="search_trending_hashtags",
                description="Search for trending hashtags related to a keyword",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "keyword": {
                            "type": "string",
                            "description": "Keyword to search for related trending hashtags",
                        },
                        "max_results": {
                            "type": "integer",
                            "description": "Maximum number of results to return (default: 10, max: 50)",
                            "default": 10,
                            "minimum": 1,
                            "maximum": 50,
                        },
                    },
                    "required": ["keyword"],
                },
            ),
            Tool(
                name="configure_auto_delete_failed_drafts",
                description="Configure whether to automatically delete drafts when publishing fails",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "enabled": {
                            "type": "boolean",
                            "description": "Whether to automatically delete drafts on publishing failure",
                        },
                    },
                    "required": ["enabled"],
                },
            ),
            Tool(
                name="get_auto_delete_config",
                description="Get current configuration for auto-deleting failed drafts",
                inputSchema={
                    "type": "object",
                    "properties": {},
                    "required": [],
                },
            ),
        ]
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It indicates this is a write operation ('Reply to') but doesn't disclose behavioral traits like authentication requirements, rate limits, error conditions, or what happens if the tweet ID is invalid. The description adds some context about direct posting but lacks comprehensive behavioral details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the key information ('Reply to an existing tweet directly') and adds necessary clarification ('without creating a draft'). Every word earns its place with zero waste.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (a write operation with 2 parameters), no annotations, and no output schema, the description is reasonably complete for purpose and usage but lacks behavioral details like error handling or response format. It compensates well for the absence of annotations in differentiating from siblings but could be more comprehensive.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already fully documents both parameters ('content' and 'reply_to_tweet_id'). The description doesn't add any meaning beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate when the schema does all the work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Reply to an existing tweet') and resource ('tweet'), distinguishing it from siblings like 'create_draft_reply' by specifying 'directly (without creating a draft)'. This provides precise differentiation and avoids ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool ('Reply to an existing tweet directly') and when not to use it ('without creating a draft'), clearly differentiating it from alternatives like 'create_draft_reply' and 'publish_draft'. This provides perfect guidance for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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