videos_getVideo
Retrieve comprehensive YouTube video details including metadata, statistics, and content information by providing the video ID.
Instructions
Get detailed information about a YouTube video including URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| videoId | Yes | The YouTube video ID | |
| parts | No | Parts of the video to retrieve |
Implementation Reference
- src/services/video.ts:62-79 (handler)Core implementation of getVideo method that fetches YouTube video details using the YouTube Data API v3 (videos.list), structures the response with video URL, and handles initialization and errors.async getVideo({ videoId, parts = ['snippet', 'contentDetails', 'statistics'] }: VideoParams): Promise<unknown> { try { this.initialize(); const response = await this.youtube.videos.list({ part: parts, id: [videoId] }); const videoData = response.data.items?.[0] || null; return this.createStructuredVideo(videoData); } catch (error) { throw new Error(`Failed to get video: ${error instanceof Error ? error.message : String(error)}`); } }
- src/server-utils.ts:132-152 (registration)MCP tool registration for 'videos_getVideo', including Zod input schema, tool metadata, and thin async handler that delegates to VideoService.getVideo and formats response for MCP.server.registerTool( 'videos_getVideo', { title: 'Get Video Details', description: 'Get detailed information about a YouTube video including URL', annotations: { readOnlyHint: true, idempotentHint: true }, inputSchema: { videoId: z.string().describe('The YouTube video ID'), parts: z.array(z.string()).optional().describe('Parts of the video to retrieve'), }, }, async ({ videoId, parts }) => { const result = await videoService.getVideo({ videoId, parts }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } );
- src/types.ts:4-7 (schema)TypeScript interface VideoParams defining input parameters for the getVideo function, matching the tool's input schema.export interface VideoParams { videoId: string; parts?: string[]; }
- src/services/video.ts:18-31 (helper)Helper function to structure video data by adding canonical YouTube URL and ensuring videoId is present.private createStructuredVideo(videoData: unknown): unknown { if (!videoData) return null; // eslint-disable-next-line @typescript-eslint/no-explicit-any const v = videoData as any; const videoId = v.id || v.id?.videoId; const url = videoId ? `https://www.youtube.com/watch?v=${videoId}` : null; return { ...v, url, videoId }; }