create_draft_tweet
Create draft tweets for X/Twitter by providing content, enabling users to prepare posts for review and scheduling through the chat interface.
Instructions
Create a draft tweet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The content of the tweet |
Implementation Reference
- src/x_mcp/server.py:133-155 (handler)The handler function that executes the create_draft_tweet tool. It validates the input arguments, creates a draft by saving the tweet content to a local JSON file with a unique ID, logs the action, and returns a success message with the draft ID.async def handle_create_draft_tweet(arguments: Any) -> Sequence[TextContent]: if not isinstance(arguments, dict) or "content" not in arguments: raise ValueError("Invalid arguments for create_draft_tweet") content = arguments["content"] try: # Simulate creating a draft by storing it locally draft = {"content": content, "timestamp": datetime.now().isoformat()} # Ensure drafts directory exists os.makedirs("drafts", exist_ok=True) # Save the draft to a file draft_id = f"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 tweet created: {draft_id}") return [ TextContent( type="text", text=f"Draft tweet created with ID {draft_id}", ) ] except Exception as e: logger.error(f"Error creating draft tweet: {str(e)}") raise RuntimeError(f"Error creating draft tweet: {str(e)}")
- src/x_mcp/server.py:49-62 (registration)Registers the 'create_draft_tweet' tool in the list_tools() function, including its name, description, and input schema.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"], }, ),
- src/x_mcp/server.py:52-61 (schema)Defines the JSON schema for the tool's input, requiring a 'content' property of type string.inputSchema={ "type": "object", "properties": { "content": { "type": "string", "description": "The content of the tweet", }, }, "required": ["content"], },
- src/x_mcp/server.py:120-121 (handler)Dispatches the tool call to the specific handler function in the general call_tool handler.if name == "create_draft_tweet": return await handle_create_draft_tweet(arguments)