add_to_playlist
Add a video to an existing YouTube playlist by providing the playlist ID and video ID (both YouTube IDs, not URLs).
Instructions
Add a video to an existing playlist. Both playlist_id and video_id are YouTube IDs (not URLs).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_id | Yes | YouTube playlist ID | |
| video_id | Yes | YouTube video ID to add |
Implementation Reference
- src/tools/playlists.ts:38-55 (handler)The tool handler for 'add_to_playlist' registered with the MCP server. Calls client.addToPlaylist() and returns a success message with the video and playlist IDs.
server.tool( "add_to_playlist", "Add a video to an existing playlist. Both playlist_id and video_id are YouTube IDs (not URLs).", addToPlaylistSchema, async (args) => { await client.addToPlaylist({ playlistId: args.playlist_id, videoId: args.video_id, }); return { content: [ { type: "text" as const, text: `Added video ${args.video_id} to playlist ${args.playlist_id}`, }, ], }; }, - src/tools/playlists.ts:11-14 (schema)Zod schema defining the input parameters for the 'add_to_playlist' tool: playlist_id (YouTube playlist ID) and video_id (YouTube video ID), both strings.
const addToPlaylistSchema = { playlist_id: z.string().describe("YouTube playlist ID"), video_id: z.string().describe("YouTube video ID to add"), }; - src/tools/playlists.ts:16-57 (registration)The registerPlaylistTools function registers both 'create_playlist' and 'add_to_playlist' tools on the MCP server, and is called from src/server.ts line 48.
export function registerPlaylistTools(server: McpServer, client: YouTubeClient): void { server.tool( "create_playlist", "Create a new playlist on the authenticated channel. Default privacy is 'private'.", createPlaylistSchema, async (args) => { const playlist = await client.createPlaylist({ title: args.title, description: args.description, privacyStatus: args.privacy_status, }); return { content: [ { type: "text" as const, text: `Created ${args.privacy_status} playlist: ${playlist.snippet?.title ?? args.title} (${playlist.id})`, }, ], }; }, ); server.tool( "add_to_playlist", "Add a video to an existing playlist. Both playlist_id and video_id are YouTube IDs (not URLs).", addToPlaylistSchema, async (args) => { await client.addToPlaylist({ playlistId: args.playlist_id, videoId: args.video_id, }); return { content: [ { type: "text" as const, text: `Added video ${args.video_id} to playlist ${args.playlist_id}`, }, ], }; }, ); } - src/youtube/client.ts:193-204 (helper)The YouTubeClient.addToPlaylist() helper method that makes the actual API call to POST /playlistItems with the playlist ID and video resource ID.
addToPlaylist(input: { playlistId: string; videoId: string }): Promise<unknown> { return this.dataPost( "/playlistItems", { part: "snippet" }, { snippet: { playlistId: input.playlistId, resourceId: { kind: "youtube#video", videoId: input.videoId }, }, }, ); }