tiktok_get_subtitle
Retrieve the subtitle (content) from a TikTok video URL. Supports video URL or ID, and optional language code to get subtitles in a specific language; defaults to automatic speech recognition.
Instructions
Get the subtitle (content) for a TikTok video url.This is used for getting the subtitle, content or context for a TikTok video.Supports TikTok video url (or video ID) as input and optionally language code from the tool post detailsReturns the subtitle for the video in the requested language and format.If no language code is provided, the tool will return the subtitle of automatic speech recognition.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tiktok_url | Yes | TikTok video URL, e.g., https://www.tiktok.com/@username/video/1234567890 or https://vm.tiktok.com/1234567890, or just the video ID like 7409731702890827041 | |
| language_code | No | Language code for the subtitle, e.g., en for English, es for Spanish, fr for French, etc. |
Implementation Reference
- index.ts:12-34 (schema)Tool definition and input schema for tiktok_get_subtitle, specifying name, description, and input validation schema requiring tiktok_url and optionally language_code.
const GET_SUBTITLE: Tool = { name: "tiktok_get_subtitle", description: "Get the subtitle (content) for a TikTok video url." + "This is used for getting the subtitle, content or context for a TikTok video." + "Supports TikTok video url (or video ID) as input and optionally language code from the tool post details" + "Returns the subtitle for the video in the requested language and format." + "If no language code is provided, the tool will return the subtitle of automatic speech recognition.", inputSchema: { type: "object", properties: { tiktok_url: { type: "string", description: "TikTok video URL, e.g., https://www.tiktok.com/@username/video/1234567890 or https://vm.tiktok.com/1234567890, or just the video ID like 7409731702890827041", }, language_code: { type: "string", description: "Language code for the subtitle, e.g., en for English, es for Spanish, fr for French, etc.", }, }, required: ["tiktok_url"] } }; - index.ts:254-277 (handler)Core handler function that calls the TikNeuron API (https://tikneuron.com/api/mcp/get-subtitles) with tiktok_url and optional language_code, returning subtitle_content.
async function performGetSubtitle(tiktok_url: string, language_code: string) { const url = new URL('https://tikneuron.com/api/mcp/get-subtitles'); url.searchParams.set('tiktok_url', tiktok_url); if (language_code){ url.searchParams.set('language_code', language_code); } const response = await fetch(url, { headers: { 'Accept': 'application/json', 'Accept-Encoding': 'gzip', 'MCP-API-KEY': TIKNEURON_MCP_API_KEY, } }); if (!response.ok) { throw new Error(`TikNeuron API error: ${response.status} ${response.statusText}\n${await response.text()}`); } const data = await response.json() as Subtitle; return data.subtitle_content || 'No subtitle available'; } - index.ts:331-342 (handler)Request handler switch case that validates args and delegates to performGetSubtitle for the tiktok_get_subtitle tool.
case "tiktok_get_subtitle": { if (!isGetSubtitleArgs(args)) { throw new Error("Invalid arguments for tiktok_get_subtitle"); } const { tiktok_url, language_code } = args; const results = await performGetSubtitle(tiktok_url, language_code); return { content: [{ type: "text", text: results }], isError: false, }; } - index.ts:171-178 (helper)Type guard that validates the arguments for tiktok_get_subtitle, checking that tiktok_url is present and is a string.
function isGetSubtitleArgs(args: unknown): args is { tiktok_url: string, language_code: string } { return ( typeof args === "object" && args !== null && "tiktok_url" in args && typeof (args as { tiktok_url: string }).tiktok_url === "string" ); } - index.ts:318-319 (registration)Registration of tiktok_get_subtitle (via GET_SUBTITLE constant) in the list of tools exposed by the MCP server.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [GET_SUBTITLE, GET_POST_DETAILS, SEARCH],