Skip to main content
Glama

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
NameRequiredDescriptionDefault
videoIdYesThe YouTube video ID
partsNoParts of the video to retrieve

Implementation Reference

  • 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)}`); } }
  • 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) }] }; } );
  • TypeScript interface VideoParams defining input parameters for the getVideo function, matching the tool's input schema.
    export interface VideoParams { videoId: string; parts?: string[]; }
  • 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 }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sfiorini/youtube-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server