playlists_getPlaylistItems
Retrieve videos from a YouTube playlist by providing the playlist ID. This tool helps users access and manage playlist content through the YouTube Data API.
Instructions
Get videos in a YouTube playlist
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | The YouTube playlist ID | |
| maxResults | No | Maximum number of results to return |
Implementation Reference
- src/services/playlist.ts:57-74 (handler)Core handler implementation in PlaylistService that initializes the YouTube API client and fetches playlist items using the playlistItems.list endpoint.async getPlaylistItems({ playlistId, maxResults = 50 }: PlaylistItemsParams): Promise<unknown[]> { try { this.initialize(); const response = await this.youtube.playlistItems.list({ part: ['snippet', 'contentDetails'], playlistId, maxResults }); return response.data.items || []; } catch (error) { throw new Error(`Failed to get playlist items: ${error instanceof Error ? error.message : String(error)}`); } }
- src/server-utils.ts:266-285 (registration)Registers the MCP tool 'playlists_getPlaylistItems' with Zod input schema, annotations, and a thin async handler that delegates to PlaylistService.getPlaylistItems and formats the response.'playlists_getPlaylistItems', { title: 'Get Playlist Items', description: 'Get videos in a YouTube playlist', annotations: { readOnlyHint: true, idempotentHint: true }, inputSchema: { playlistId: z.string().describe('The YouTube playlist ID'), maxResults: z.number().optional().describe('Maximum number of results to return'), }, }, async ({ playlistId, maxResults }) => { const result = await playlistService.getPlaylistItems({ playlistId, maxResults }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } );
- src/types.ts:76-79 (schema)TypeScript interface defining the input parameters for getPlaylistItems, used by the PlaylistService.export interface PlaylistItemsParams { playlistId: string; maxResults?: number; }