Get Video Details
videos_getVideoRetrieve detailed information for a YouTube video by providing its video ID, including the video URL and optional specified data parts.
Instructions
Get detailed information about a YouTube video including URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| videoId | Yes | The YouTube video ID | |
| parts | No | Parts of the video to retrieve |
Implementation Reference
- src/server-utils.ts:132-152 (registration)Registration of the 'videos_getVideo' tool via McpServer.registerTool(). Includes inputSchema with videoId (required) and parts (optional), and the handler that delegates to videoService.getVideo().
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/services/video.ts:59-79 (handler)The getVideo() method on VideoService which is the actual implementation. Calls the YouTube Data API v3 videos.list endpoint with the provided parts and videoId, then structures the result with URL via createStructuredVideo().
/** * Get detailed information about a YouTube video */ 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/types.ts:4-7 (schema)The VideoParams interface defining the input parameters (videoId: string, parts?: string[]) used by videoService.getVideo().
export interface VideoParams { videoId: string; parts?: string[]; } - src/services/video.ts:18-31 (helper)The createStructuredVideo() helper method that enriches raw video data with a YouTube watch URL (https://www.youtube.com/watch?v={videoId}) and extracts videoId.
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 }; }