Skip to main content
Glama

tiktok_user_videos

Retrieve videos from a TikTok user's profile by specifying their username and desired video count for content analysis or data collection.

Instructions

Get videos from a specific TikTok user's profile.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
usernameYesTikTok username (with or without @)
countNoNumber of videos (default 10)

Implementation Reference

  • The actual implementation of the tool handler `get_user_videos` which scrapes TikTok user videos using Playwright.
    async def get_user_videos(self, username: str, count: int = 10) -> list[dict]:
        """Get videos from a specific user's profile."""
        if not username.startswith("@"):
            username = f"@{username}"
    
        page = await self.goto_tiktok(f"/{username}")
        await asyncio.sleep(3)
    
        # Get user info
        user_info = await page.evaluate("""() => {
            const name = document.querySelector('[data-e2e="user-title"]') || document.querySelector('h1');
            const bio = document.querySelector('[data-e2e="user-bio"]');
            const following = document.querySelector('[data-e2e="following-count"]');
            const followers = document.querySelector('[data-e2e="followers-count"]');
            const likes = document.querySelector('[data-e2e="likes-count"]');
            return {
                username: name?.textContent?.trim() || '',
                bio: bio?.textContent?.trim() || '',
                following: following?.textContent?.trim() || '0',
                followers: followers?.textContent?.trim() || '0',
                total_likes: likes?.textContent?.trim() || '0',
            };
        }""")
    
        videos = []
        seen_ids = set()
        scroll_attempts = 0
    
        while len(videos) < count and scroll_attempts < count * 2:
            items = await page.evaluate("""() => {
                const videos = [];
                const cards = document.querySelectorAll('[data-e2e="user-post-item"], [class*="DivItemContainerForSearch"]');
                cards.forEach(card => {
                    try {
                        const link = card.querySelector('a[href*="/video/"]');
                        const views = card.querySelector('[class*="video-count"]') || card.querySelector('strong');
                        const desc = card.querySelector('[title]') || link;
                        
                        const href = link?.href || '';
                        const videoIdMatch = href.match(/video\\/([0-9]+)/);
                        
                        videos.push({
                            video_id: videoIdMatch ? videoIdMatch[1] : null,
                            url: href,
                            description: desc?.title || desc?.textContent?.trim() || '',
                            views: views?.textContent?.trim() || '',
                        });
                    } catch(e) {}
                });
                return videos;
            }""")
    
            for item in items:
                vid = item.get("video_id")
                if vid and vid not in seen_ids:
                    seen_ids.add(vid)
  • The tool invocation logic for `tiktok_user_videos` inside the `call_tool` function.
    elif name == "tiktok_user_videos":
        results = await browser.get_user_videos(
            arguments["username"],
            arguments.get("count", 10),
        )
        return [TextContent(type="text", text=json.dumps(results, indent=2, ensure_ascii=False))]
  • The registration of `tiktok_user_videos` tool definition.
    Tool(
        name="tiktok_user_videos",
        description="Get videos from a specific TikTok user's profile.",
        inputSchema={
            "type": "object",
            "properties": {
                "username": {"type": "string", "description": "TikTok username (with or without @)"},
                "count": {"type": "integer", "description": "Number of videos (default 10)", "default": 10},
            },
            "required": ["username"],
        },

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