tiktok_post
Scrapes a TikTok post URL to extract structured data including engagement metrics, captions, and hashtags.
Instructions
Scrape a TikTok post URL for structured data such as engagement, captions, and hashtags
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | TikTok post URL, e.g. https://www.tiktok.com/@user/video/1234567890 | |
| xhr | No | When true, includes XHR/fetch responses in the scrape result where supported by the target |
Implementation Reference
- The TiktokPostTool class with the register method containing the full handler logic. It registers the 'tiktok_post' tool which takes a TikTok post URL and optional xhr parameter, calls the ScraperAPI client with target 'tiktok_post', and returns scraped data as text content.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'tiktok_post', { description: 'Scrape a TikTok post URL for structured data such as engagement, captions, and hashtags', inputSchema: { url: z .string() .describe('TikTok post URL, e.g. https://www.tiktok.com/@user/video/1234567890'), xhr: zodXhr, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.TIKTOK_POST, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } ); }; - Input schema for the tiktok_post tool: requires a 'url' string and optional 'xhr' boolean, with read-only and open-world annotations.
inputSchema: { url: z .string() .describe('TikTok post URL, e.g. https://www.tiktok.com/@user/video/1234567890'), xhr: zodXhr, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, - src/server/sapi-base-server.ts:113-117 (registration)TiktokPostTool is instantiated as part of the allTools array (line 83) and registered via the registerAllTools method or registerTools method in the server.
registerAllTools() { for (const tool of ScraperAPIBaseServer.allTools) { tool.register({ server: this.server, sapiClient: this.sapiClient, auth: this.auth }); } } - The toolset is SOCIAL_MEDIA, which controls which toolsets filter the tool is included in.
import { ProgressExtra } from '../../utils'; export class TiktokPostTool extends Tool { toolset = TOOLSET.SOCIAL_MEDIA; - src/constants.ts:29-48 (helper)The SCRAPER_API_TARGETS constant that maps 'tiktok_post' to the target used in the scraping request.
TIKTOK_POST = 'tiktok_post', TIKTOK_SHOP_SEARCH = 'tiktok_shop_search', TIKTOK_SHOP_PRODUCT = 'tiktok_shop_product', TIKTOK_SHOP_URL = 'tiktok', YOUTUBE_VIDEO = 'youtube_video', YOUTUBE_METADATA = 'youtube_metadata', YOUTUBE_CHANNEL = 'youtube_channel', YOUTUBE_SUBTITLES = 'youtube_subtitles', YOUTUBE_SEARCH = 'youtube_search', REDDIT_POST = 'reddit_post', REDDIT_SUBREDDIT = 'reddit_subreddit', REDDIT_USER = 'reddit_user', BING_SEARCH = 'bing_search', CHATGPT = 'chatgpt', PERPLEXITY = 'perplexity', }