delete_draft
Remove unwanted draft tweets or threads from your X/Twitter account by specifying the draft ID to free up space and maintain organized draft management.
Instructions
Delete a draft tweet or thread
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| draft_id | Yes | ID of the draft to delete |
Implementation Reference
- src/x_mcp/server.py:820-843 (handler)The main handler function that executes the delete_draft tool: validates input, constructs draft file path, checks existence, removes the file, logs the action, and returns a success message.async def handle_delete_draft(arguments: Any) -> Sequence[TextContent]: if not isinstance(arguments, dict) or "draft_id" not in arguments: raise ValueError("Invalid arguments for delete_draft") draft_id = arguments["draft_id"] filepath = os.path.join("drafts", draft_id) try: if not os.path.exists(filepath): raise ValueError(f"Draft {draft_id} does not exist") os.remove(filepath) logger.info(f"Deleted draft: {draft_id}") return [ TextContent( type="text", text=f"Successfully deleted draft {draft_id}", ) ] except Exception as e: logger.error(f"Error deleting draft {draft_id}: {str(e)}") raise RuntimeError(f"Error deleting draft {draft_id}: {str(e)}")
- src/x_mcp/server.py:155-168 (registration)Registration of the 'delete_draft' tool in the MCP server's list_tools() method, including name, description, and input schema.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"], }, ),
- src/x_mcp/server.py:158-167 (schema)Input schema for the delete_draft tool, defining a required 'draft_id' string parameter.inputSchema={ "type": "object", "properties": { "draft_id": { "type": "string", "description": "ID of the draft to delete", }, }, "required": ["draft_id"], },
- src/x_mcp/server.py:546-547 (handler)Dispatch in the main call_tool handler that routes 'delete_draft' calls to the specific handle_delete_draft function.elif name == "delete_draft": return await handle_delete_draft(arguments)
- src/x_mcp/server.py:87-97 (helper)Supporting helper function to conditionally delete drafts on publishing failures based on AUTO_DELETE_FAILED_DRAFTS configuration.def delete_draft_on_failure(draft_id: str, filepath: str) -> None: """Delete draft file if auto-delete is enabled""" if AUTO_DELETE_FAILED_DRAFTS: try: os.remove(filepath) logger.info(f"Deleted draft {draft_id} due to publishing failure (auto-delete enabled)") except Exception as delete_error: logger.error(f"Failed to delete draft {draft_id} after publishing error: {delete_error}") else: logger.info(f"Draft {draft_id} preserved for retry (auto-delete disabled)")