tiktok_interact
Perform interactions on TikTok videos: like posts, add comments, or follow creators through automated browser sessions.
Instructions
Interact with a TikTok video: like, comment, or follow the creator.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Interaction type | |
| video_url | Yes | Target video URL | |
| text | No | Comment text (required for comment action) |
Implementation Reference
- tiktok_mcp/browser.py:519-577 (handler)The interact method in TikTokBrowser handles the logic for liking, commenting, or following a video.
async def interact(self, video_url: str, action: str, text: str = "") -> dict: """Interact with a video: like, comment, follow.""" page = await self.launch() await page.goto(video_url, wait_until="domcontentloaded", timeout=30000) await asyncio.sleep(3) result = {"action": action, "url": video_url, "success": False} try: if action == "like": btn = await page.query_selector('[data-e2e="like-icon"], [data-e2e="browse-like-icon"]') if btn: await btn.click() await asyncio.sleep(1) result["success"] = True elif action == "comment": if not text: result["error"] = "Comment text required" return result # Click comment input comment_input = await page.query_selector( '[data-e2e="comment-input"] div[contenteditable], ' '[class*="DivInputEditorContainer"] div[contenteditable]' ) if comment_input: await comment_input.click() await asyncio.sleep(0.5) await comment_input.type(text, delay=random.randint(30, 80)) await asyncio.sleep(0.5) # Click post button post_btn = await page.query_selector( '[data-e2e="comment-post"], [class*="DivPostButton"]' ) if post_btn: await post_btn.click() await asyncio.sleep(2) result["success"] = True else: await page.keyboard.press("Enter") await asyncio.sleep(2) result["success"] = True elif action == "follow": btn = await page.query_selector( '[data-e2e="browse-follow"], button:has-text("Follow")' ) if btn: await btn.click() await asyncio.sleep(1) result["success"] = True else: result["error"] = f"Unknown action: {action}" except Exception as e: result["error"] = str(e) return result - tiktok_mcp/server.py:149-165 (registration)The tiktok_interact tool is defined and registered in the TOOLS list.
Tool( name="tiktok_interact", description="Interact with a TikTok video: like, comment, or follow the creator.", inputSchema={ "type": "object", "properties": { "action": { "type": "string", "enum": ["like", "comment", "follow"], "description": "Interaction type", }, "video_url": {"type": "string", "description": "Target video URL"}, "text": {"type": "string", "description": "Comment text (required for comment action)"}, }, "required": ["action", "video_url"], }, ), - tiktok_mcp/server.py:274-280 (handler)The call_tool handler in server.py dispatches the tiktok_interact request to the browser instance.
elif name == "tiktok_interact": result = await browser.interact( arguments["video_url"], arguments["action"], arguments.get("text", ""), ) return [TextContent(type="text", text=json.dumps(result, indent=2, ensure_ascii=False))]