youtube_subtitles
Retrieve subtitles from any YouTube video by providing its video ID. Supports specifying a language code for localized captions.
Instructions
Scrape YouTube video subtitles
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | YouTube video ID (e.g., "L8zSWbQN-v8") | |
| language_code | No | Language code for subtitles (e.g., "en", "es") |
Implementation Reference
- The async handler function that calls the ScraperAPI client with youtube_subtitles target and returns the subtitles data as text content.
async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.YOUTUBE_SUBTITLES, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } ); - Registration of the youtube_subtitles tool with input schema (query string for video ID, optional language_code) and annotations.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'youtube_subtitles', { description: 'Scrape YouTube video subtitles', inputSchema: { query: z.string().describe('YouTube video ID (e.g., "L8zSWbQN-v8")'), language_code: zodLanguageCode, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, - src/server/sapi-base-server.ts:89-90 (registration)Registration of YoutubeSubtitlesTool in the allTools array and subsequent registration via registerTools/registerAllTools.
new YoutubeSubtitlesTool(), new YoutubeSearchTool(), - src/constants.ts:37-37 (helper)Constant defining the SCRAPER_API_TARGETS.YOUTUBE_SUBTITLES enum value used as the target parameter for the ScraperAPI call.
YOUTUBE_SUBTITLES = 'youtube_subtitles',