delete_tweet
Remove a specific tweet using its unique ID on the X (Twitter) MCP server, ensuring precise content management and cleanup.
Instructions
Delete a tweet by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tweet_id | Yes |
Implementation Reference
- src/x_twitter_mcp/server.py:218-229 (handler)The handler function for the 'delete_tweet' tool, including the @server.tool decorator which also serves as registration. It performs rate limiting check, initializes the Tweepy Twitter client, calls client.delete_tweet to delete the specified tweet, and returns a confirmation dictionary.@server.tool(name="delete_tweet", description="Delete a tweet by its ID") async def delete_tweet(tweet_id: str) -> Dict: """Deletes a tweet. Args: tweet_id (str): The ID of the tweet to delete. """ if not check_rate_limit("tweet_actions"): raise Exception("Tweet action rate limit exceeded") client, _ = initialize_twitter_clients() result = client.delete_tweet(id=tweet_id) return {"id": tweet_id, "deleted": result.data["deleted"]}
- src/x_twitter_mcp/server.py:219-223 (schema)Input schema defined by function signature (tweet_id: str) and output as Dict, with docstring describing the parameter.async def delete_tweet(tweet_id: str) -> Dict: """Deletes a tweet. Args: tweet_id (str): The ID of the tweet to delete.
- src/x_twitter_mcp/server.py:28-66 (helper)Helper function to lazily initialize the Tweepy Twitter v2 Client and v1.1 API, used by delete_tweet to get the client for deletion.def initialize_twitter_clients() -> tuple[tweepy.Client, tweepy.API]: """Initialize Twitter API clients on-demand.""" global _twitter_client, _twitter_v1_api if _twitter_client is not None and _twitter_v1_api is not None: return _twitter_client, _twitter_v1_api # Verify required environment variables required_env_vars = [ "TWITTER_API_KEY", "TWITTER_API_SECRET", "TWITTER_ACCESS_TOKEN", "TWITTER_ACCESS_TOKEN_SECRET", "TWITTER_BEARER_TOKEN", ] for var in required_env_vars: if not os.getenv(var): raise EnvironmentError(f"Missing required environment variable: {var}") # Initialize v2 API client _twitter_client = tweepy.Client( consumer_key=os.getenv("TWITTER_API_KEY"), consumer_secret=os.getenv("TWITTER_API_SECRET"), access_token=os.getenv("TWITTER_ACCESS_TOKEN"), access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET"), bearer_token=os.getenv("TWITTER_BEARER_TOKEN") ) # Initialize v1.1 API for media uploads and other unsupported v2 endpoints auth = tweepy.OAuth1UserHandler( consumer_key=os.getenv("TWITTER_API_KEY"), consumer_secret=os.getenv("TWITTER_API_SECRET"), access_token=os.getenv("TWITTER_ACCESS_TOKEN"), access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET") ) _twitter_v1_api = tweepy.API(auth) return _twitter_client, _twitter_v1_api
- src/x_twitter_mcp/server.py:78-91 (helper)Helper function for rate limiting checks, called by delete_tweet before performing the deletion.def check_rate_limit(action_type: str) -> bool: """Check if the action is within rate limits.""" config = RATE_LIMITS.get(action_type) if not config: return True # No limit defined counter = rate_limit_counters[action_type] now = datetime.now() if now >= counter["reset_time"]: counter["count"] = 0 counter["reset_time"] = now + config["window"] if counter["count"] >= config["limit"]: return False counter["count"] += 1 return True