Skip to main content
Glama

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
NameRequiredDescriptionDefault
actionYesInteraction type
video_urlYesTarget video URL
textNoComment text (required for comment action)

Implementation Reference

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

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/follox42/tiktok-mcp'

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