Skip to main content
Glama
vidhupv

X(Twitter) MCP Server

by vidhupv

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
NameRequiredDescriptionDefault
contentYesThe content of the tweet

Implementation Reference

  • 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)}")
  • 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"], }, ),
  • 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"], },
  • 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)

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