tiktok_get_subtitle
Retrieve subtitles or content for any TikTok video URL. Optionally specify language code; 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 as input and optionally language code from tool 'AVAILABLE_SUBTITLES'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.
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 | |
| language_code | No | Language code for the subtitle, e.g., en for English, es for Spanish, fr for French, etc. |
Implementation Reference
- index.ts:187-210 (handler)The performGetSubtitle function is the core handler that calls the TikNeuron API to fetch the subtitle content for a TikTok video. It takes tiktok_url and optional language_code, sends a fetch request to https://tikneuron.com/api/mcp/get-subtitles, and returns the 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:32-54 (schema)The GET_SUBTITLE Tool definition providing name 'tiktok_get_subtitle', description, and inputSchema which requires tiktok_url (string) and optionally language_code (string).
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 as input and optionally language code from tool 'AVAILABLE_SUBTITLES'" + "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", }, 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:144-151 (schema)The isGetSubtitleArgs type guard function validates that the input arguments match the expected shape (object with tiktok_url 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:109-116 (schema)The Subtitle interface defines the response shape from the API, including subtitle_content field which holds the actual subtitle text.
interface Subtitle { success?: boolean; subtitles?: Array<{ language?: string; source?: string; }>; subtitle_content?: string; } - index.ts:249-251 (registration)Registration of the tool in the ListToolsRequestSchema handler, adding GET_SUBTITLE to the list of available tools.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [AVAILABLE_SUBTITLES, GET_SUBTITLE, GET_POST_DETAILS], })); - index.ts:276-287 (registration)The case handler in the CallToolRequestSchema switch statement that dispatches to performGetSubtitle when the tool name is 'tiktok_get_subtitle'.
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, }; }