twitter_reply_to_tweet
Reply to any tweet on Twitter using its ID and a provided text, enabled through direct API access without local credential setup.
Instructions
Reply to an existing tweet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | The reply text content | |
| tweet_id | Yes | ID of the tweet to reply to | |
| twitter_access_token | Yes | Twitter OAuth2 access token |
Implementation Reference
- Core handler function in TwitterClient that executes the reply logic: validates token, constructs POST request to Twitter API /tweets with in_reply_to_tweet_id, handles response and errors.def reply_to_tweet(self, tweet_id: str, text: str) -> str: """Reply to an existing tweet Args: tweet_id: ID of the tweet to reply to text: The reply text content """ try: if not self.access_token: return json.dumps({ "error": "No valid access token provided. Please refresh your token first.", "status": "error" }) logger.debug(f"Replying to tweet {tweet_id} with text: {text[:30]}...") # Twitter API v2 create tweet (reply) endpoint url = f"{self.api_base_url}/tweets" headers = { "Authorization": f"Bearer {self.access_token}", "Content-Type": "application/json" } # Create request body with reply information data = { "text": text, "reply": { "in_reply_to_tweet_id": tweet_id } } response = requests.post(url, headers=headers, json=data) response.raise_for_status() # Return the raw JSON response return json.dumps(response.json()) except requests.exceptions.RequestException as e: logger.error(f"API request error: {str(e)}") return json.dumps({"error": str(e), "status": "error"}) except Exception as e: logger.error(f"Exception in reply_to_tweet: {str(e)}") return json.dumps({"error": str(e), "status": "error"})
- src/mcp_server_twitter_noauth/server.py:587-599 (registration)Tool registration in list_tools() with name, description, and input schema definition.types.Tool( name="twitter_reply_to_tweet", description="Reply to an existing tweet", inputSchema={ "type": "object", "properties": { "twitter_access_token": {"type": "string", "description": "Twitter OAuth2 access token"}, "tweet_id": {"type": "string", "description": "ID of the tweet to reply to"}, "text": {"type": "string", "description": "The reply text content"} }, "required": ["twitter_access_token", "tweet_id", "text"] }, ),
- Dispatch handler in MCP server's call_tool() that extracts arguments, validates inputs, instantiates TwitterClient, and invokes the reply_to_tweet method.elif name == "twitter_reply_to_tweet": tweet_id = arguments.get("tweet_id") text = arguments.get("text") if not tweet_id: raise ValueError("tweet_id is required for twitter_reply_to_tweet") if not text: raise ValueError("text is required for twitter_reply_to_tweet") results = twitter.reply_to_tweet(tweet_id=tweet_id, text=text) return [types.TextContent(type="text", text=results)]