Skip to main content
Glama
vidhupv

X(Twitter) MCP Server

by vidhupv

publish_draft

Publish a saved draft tweet or thread to X (Twitter) by providing the draft ID. This tool allows you to schedule and post prepared content directly from the chat interface.

Instructions

Publish a draft tweet or thread

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
draft_idYesID of the draft to publish

Implementation Reference

  • Executes the publish_draft tool: validates input, loads draft from file, publishes single tweet or thread to Twitter/X using Tweepy, removes draft, returns published tweet ID.
    async def handle_publish_draft(arguments: Any) -> Sequence[TextContent]:
        if not isinstance(arguments, dict) or "draft_id" not in arguments:
            raise ValueError("Invalid arguments for publish_draft")
        draft_id = arguments["draft_id"]
        filepath = os.path.join("drafts", draft_id)
        if not os.path.exists(filepath):
            raise ValueError(f"Draft {draft_id} does not exist")
        try:
            with open(filepath, "r") as f:
                draft = json.load(f)
            if "content" in draft:
                # Single tweet
                content = draft["content"]
                response = client.create_tweet(text=content)
                tweet_id = response.data['id']
                logger.info(f"Published tweet ID {tweet_id}")
                # Delete the draft after publishing
                os.remove(filepath)
                return [
                    TextContent(
                        type="text",
                        text=f"Draft {draft_id} published as tweet ID {tweet_id}",
                    )
                ]
            elif "contents" in draft:
                # Thread
                contents = draft["contents"]
                # Publish the thread
                last_tweet_id = None
                for content in contents:
                    if last_tweet_id is None:
                        response = client.create_tweet(text=content)
                    else:
                        response = client.create_tweet(text=content, in_reply_to_tweet_id=last_tweet_id)
                    last_tweet_id = response.data['id']
                    await asyncio.sleep(1)  # Avoid hitting rate limits
                logger.info(f"Published thread starting with tweet ID {last_tweet_id}")
                # Delete the draft after publishing
                os.remove(filepath)
                return [
                    TextContent(
                        type="text",
                        text=f"Draft {draft_id} published as thread starting with tweet ID {last_tweet_id}",
                    )
                ]
            else:
                raise ValueError(f"Invalid draft format for {draft_id}")
        except tweepy.TweepError as e:
            logger.error(f"Twitter API error: {e}")
            raise RuntimeError(f"Error publishing draft {draft_id}: {e}")
        except Exception as e:
            logger.error(f"Error publishing draft {draft_id}: {str(e)}")
            raise RuntimeError(f"Error publishing draft {draft_id}: {str(e)}")
  • Registers the publish_draft tool in the @server.list_tools() handler, including name, description, and input schema.
    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"],
        },
    ),
  • Input schema definition for publish_draft tool: object with required 'draft_id' string property.
    inputSchema={
        "type": "object",
        "properties": {
            "draft_id": {
                "type": "string",
                "description": "ID of the draft to publish",
            },
        },
        "required": ["draft_id"],
    },
  • Tool dispatch in @server.call_tool(): routes 'publish_draft' calls to the handle_publish_draft function.
    elif name == "publish_draft":
        return await handle_publish_draft(arguments)
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. It states the tool publishes a draft, implying a write/mutation operation, but lacks critical details: it doesn't specify if this is irreversible, what permissions are required, whether it triggers notifications, or what happens on success/failure. For a mutation tool with zero annotation coverage, this is a significant gap.

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 a single, efficient sentence with zero wasted words. It is front-loaded with the core action ('publish') and resource, making it immediately scannable and easy to understand. Every word earns its place.

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

Completeness2/5

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

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, error conditions, or return values. While concise, it fails to provide the necessary context for safe and effective use by an AI agent.

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 input schema has 100% description coverage, with the single parameter 'draft_id' clearly documented. The description adds no additional parameter semantics beyond what the schema provides (e.g., it doesn't explain format or sourcing of the ID). With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

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 ('publish') and resource ('draft tweet or thread'), making the purpose immediately understandable. It distinguishes from siblings like 'create_draft_thread' and 'delete_draft' by focusing on publishing rather than creation or deletion. However, it doesn't explicitly differentiate from all siblings (e.g., 'list_drafts' is clearly different).

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. It doesn't mention prerequisites (e.g., needing a draft created first), conditions for use, or comparisons to sibling tools like 'create_draft_thread' or 'delete_draft'. The agent must infer usage from context alone.

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

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/vidhupv/x-mcp'

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