Skip to main content
Glama
rafaljanicki

X (Twitter) MCP server

by rafaljanicki

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
NameRequiredDescriptionDefault
tweet_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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"]}
  • 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.
  • 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
  • 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
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'Delete' implies a destructive mutation, the description doesn't specify whether this action is reversible, what permissions are required, rate limits, or what happens upon success/failure. This leaves significant behavioral gaps for a destructive operation.

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 extremely concise with a single, clear sentence that states exactly what the tool does without any unnecessary words. It's perfectly front-loaded and every word earns its place.

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

Completeness3/5

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

Given this is a destructive mutation tool with no annotations, the description is minimally adequate but has clear gaps. The existence of an output schema helps, but the description doesn't address important contextual aspects like authentication requirements, irreversibility, or error conditions that would be crucial for safe tool invocation.

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?

The description mentions 'by its ID' which adds context about the tweet_id parameter's purpose, but with 0% schema description coverage and only 1 parameter, this provides minimal additional value beyond what's obvious from the parameter name. The baseline for 0 parameters would be 4, but with 1 parameter and low coverage, 3 is appropriate.

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

Purpose4/5

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

The description clearly states the action ('Delete') and target resource ('a tweet by its ID'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'delete_bookmark' or 'delete_all_bookmarks', which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites (like authentication), when not to use it, or how it differs from other deletion tools in the sibling list, leaving the agent without contextual usage information.

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

Related 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/rafaljanicki/x-twitter-mcp-server'

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