create_draft_thread
Create a draft tweet thread by providing an array of tweet contents for later review and publishing on X/Twitter.
Instructions
Create a draft tweet thread
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contents | Yes | An array of tweet contents for the thread |
Implementation Reference
- src/x_mcp/server.py:615-639 (handler)The main handler function that executes the create_draft_thread tool. Validates input arguments, creates a JSON draft file containing the thread contents array and timestamp, saves it to the 'drafts' directory with a unique ID, and returns a success message with the draft ID.async def handle_create_draft_thread(arguments: Any) -> Sequence[TextContent]: if not isinstance(arguments, dict) or "contents" not in arguments: raise ValueError("Invalid arguments for create_draft_thread") contents = arguments["contents"] if not isinstance(contents, list) or not all(isinstance(item, str) for item in contents): raise ValueError("Invalid contents for create_draft_thread") try: draft = {"contents": contents, "timestamp": datetime.now().isoformat()} # Ensure drafts directory exists os.makedirs("drafts", exist_ok=True) # Save the draft to a file draft_id = f"thread_draft_{int(datetime.now().timestamp())}.json" with open(os.path.join("drafts", draft_id), "w") as f: json.dump(draft, f, indent=2) logger.info(f"Draft thread created: {draft_id}") return [ TextContent( type="text", text=f"Draft thread created with ID {draft_id}", ) ] except Exception as e: logger.error(f"Error creating draft thread: {str(e)}") raise RuntimeError(f"Error creating draft thread: {str(e)}")
- src/x_mcp/server.py:117-131 (schema)The tool schema definition within the list_tools() function, specifying the input schema that requires a 'contents' array of strings for the thread tweets.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"], }, ),
- src/x_mcp/server.py:540-541 (registration)The dispatch registration in the call_tool() function that routes calls to the 'create_draft_thread' tool to its handler function.elif name == "create_draft_thread": return await handle_create_draft_thread(arguments)
- src/x_mcp/server.py:99-533 (registration)The @server.list_tools() decorated function that registers the create_draft_thread tool by including it in the returned list of available tools.@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": [], }, ), ]