youtube_metadata
Retrieve YouTube video metadata by providing a video ID. Extracts details like title, description, and more for analysis or integration.
Instructions
Scrape YouTube video metadata
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | YouTube video ID (e.g., "dFu9aKJoqGg") |
Implementation Reference
- The YoutubeMetadataTool class containing the register method which defines the tool handler. The handler accepts a YouTube video ID, wraps it with the SCRAPER_API_TARGETS.YOUTUBE_METADATA target, calls sapiClient.scrape(), and returns the scraped data as JSON text.
export class YoutubeMetadataTool extends Tool { toolset = TOOLSET.SOCIAL_MEDIA; transformResponse = ({ data }: { data: object }) => { return { data: JSON.stringify(data) }; }; register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'youtube_metadata', { description: 'Scrape YouTube video metadata', inputSchema: { query: z.string().describe('YouTube video ID (e.g., "dFu9aKJoqGg")'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.YOUTUBE_METADATA, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } ); }; } - Input schema using Zod: expects a single 'query' string parameter (a YouTube video ID like 'dFu9aKJoqGg').
inputSchema: { query: z.string().describe('YouTube video ID (e.g., "dFu9aKJoqGg")'), }, - src/tools/youtube-metadata/youtube-metadata-tool.ts:14-44 (registration)The register method that calls server.registerTool('youtube_metadata', ...) to register the tool with the MCP server.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'youtube_metadata', { description: 'Scrape YouTube video metadata', inputSchema: { query: z.string().describe('YouTube video ID (e.g., "dFu9aKJoqGg")'), }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.YOUTUBE_METADATA, } 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:30-87 (registration)The YoutubeMetadataTool is imported and instantiated as part of the static allTools array (line 87) in ScraperAPIBaseServer, which registers it on server startup.
YoutubeMetadataTool, YoutubeChannelTool, YoutubeSubtitlesTool, YoutubeSearchTool, ScrapeAsMarkdownTool, ScreenshotTool, } from '../tools'; import { Tool } from '../tools/tool'; import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; import { TOOLSET } from '../constants'; export class ScraperAPIBaseServer { server: McpServer; sapiClient: ScraperApiClient; auth: string = ''; constructor({ auth, toolsets = [] }: { auth: string; toolsets: TOOLSET[] }) { this.server = new McpServer({ name: 'decodo', version: PACKAGE_VERSION, }); this.sapiClient = new ScraperApiClient({}); this.auth = auth; this.registerTools({ toolsets }); this.registerResources(); } connect(transport: StdioServerTransport | StreamableHTTPServerTransport) { this.server.connect(transport); } static allTools: Tool[] = [ new ScrapeAsMarkdownTool(), new ScreenshotTool(), new GoogleSearchTool(), new GoogleAdsTool(), new GoogleLensTool(), new GoogleAiModeTool(), new GoogleTravelHotelsTool(), new AmazonSearchTool(), new AmazonProductTool(), new AmazonPricingTool(), new AmazonSellersTool(), new AmazonBestsellersTool(), new WalmartSearchTool(), new WalmartProductTool(), new TargetSearchTool(), new TargetProductTool(), new TiktokPostTool(), new TiktokShopSearchTool(), new TiktokShopProductTool(), new TiktokShopUrlTool(), new YoutubeMetadataTool(), - src/constants.ts:35-35 (helper)Defines the SCRAPER_API_TARGETS.YOUTUBE_METADATA constant with value 'youtube_metadata', used by the tool to set the scraping target.
YOUTUBE_METADATA = 'youtube_metadata',