playlists_getPlaylist
Retrieve YouTube playlist details including videos, metadata, and structure using the playlist ID to analyze or display content.
Instructions
Get information about a YouTube playlist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | The YouTube playlist ID |
Implementation Reference
- src/services/playlist.ts:37-52 (handler)Core implementation of the playlists_getPlaylist tool logic, calling YouTube Data API v3 playlists.list to retrieve playlist details.async getPlaylist({ playlistId }: PlaylistParams): Promise<unknown> { try { this.initialize(); const response = await this.youtube.playlists.list({ part: ['snippet', 'contentDetails'], id: [playlistId] }); return response.data.items?.[0] || null; } catch (error) { throw new Error(`Failed to get playlist: ${error instanceof Error ? error.message : String(error)}`); } }
- src/server-utils.ts:244-263 (registration)Registers the 'playlists_getPlaylist' tool with the MCP server, including input schema, description, and a thin handler that delegates to PlaylistService.getPlaylist.server.registerTool( 'playlists_getPlaylist', { title: 'Get Playlist Information', description: 'Get information about a YouTube playlist', annotations: { readOnlyHint: true, idempotentHint: true }, inputSchema: { playlistId: z.string().describe('The YouTube playlist ID'), }, }, async ({ playlistId }) => { const result = await playlistService.getPlaylist({ playlistId }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } );
- src/server-utils.ts:250-252 (schema)Zod-based input schema for the tool, defining the required 'playlistId' parameter.inputSchema: { playlistId: z.string().describe('The YouTube playlist ID'), },
- src/types.ts:66-71 (schema)TypeScript interface defining the parameters for the playlist service method./** * Playlist parameters */ export interface PlaylistParams { playlistId: string; }
- src/services/playlist.ts:18-32 (helper)Helper method to lazily initialize the YouTube API client using the API key from environment variables.private initialize() { if (this.initialized) return; const apiKey = process.env.YOUTUBE_API_KEY; if (!apiKey) { throw new Error('YOUTUBE_API_KEY environment variable is not set.'); } this.youtube = google.youtube({ version: "v3", auth: apiKey }); this.initialized = true; }