Get Playlist Information
playlists_getPlaylistFetch metadata and contents of any YouTube playlist by providing its unique playlist ID. Returns title, description, video items, and other playlist information.
Instructions
Get information about a YouTube playlist
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | The YouTube playlist ID |
Implementation Reference
- src/services/playlist.ts:37-52 (handler)The getPlaylist method in PlaylistService that fetches a YouTube playlist's snippet and contentDetails via the YouTube Data API v3.
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)Registration of the 'playlists_getPlaylist' tool on the MCP server, with input schema and 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/types.ts:69-71 (schema)PlaylistParams interface defining that the tool expects a 'playlistId' string as input.
export interface PlaylistParams { playlistId: string; } - src/services/playlist.ts:18-31 (helper)Initialization helper that sets up the YouTube API client with 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;