youtube_search
Search YouTube videos by keyword. Returns metadata including title, URL, and description for each result.
Instructions
Search YouTube videos
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | YouTube search query (e.g., "How to care for chinchillas") |
Implementation Reference
- The YoutubeSearchTool class that contains both the definition and the handler logic for the 'youtube_search' tool. It registers the tool with a 'query' input schema, sets the target to SCRAPER_API_TARGETS.YOUTUBE_SEARCH, and calls sapiClient.scrape to execute the search.
export class YoutubeSearchTool extends Tool { toolset = TOOLSET.SOCIAL_MEDIA; transformResponse = ({ data }: { data: object }) => { return { data: JSON.stringify(data) }; }; register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'youtube_search', { description: 'Search YouTube videos', inputSchema: { query: z.string().describe('YouTube search query (e.g., "How to care for chinchillas")'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.YOUTUBE_SEARCH, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } ); }; } - Input schema definition for youtube_search: requires a 'query' string parameter describing the YouTube search query.
description: 'Search YouTube videos', inputSchema: { query: z.string().describe('YouTube search query (e.g., "How to care for chinchillas")'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, - src/tools/youtube-search/youtube-search-tool.ts:15-44 (registration)Registration of the tool with the MCP server via server.registerTool('youtube_search', ...).
server.registerTool( 'youtube_search', { description: 'Search YouTube videos', inputSchema: { query: z.string().describe('YouTube search query (e.g., "How to care for chinchillas")'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.YOUTUBE_SEARCH, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } ); - src/server/sapi-base-server.ts:90-90 (registration)Instantiation of YoutubeSearchTool in the allTools static array, making it available for registration on the server.
new YoutubeSearchTool(), - src/constants.ts:38-38 (helper)Definition of the SCRAPER_API_TARGETS.YOUTUBE_SEARCH constant used as the target identifier for the YouTube search API call.
YOUTUBE_SEARCH = 'youtube_search',