add_to_playlist
Add a song to a specific playlist by providing the playlist ID and song ID. Simplifies music management within Claude Music MCP's ecosystem.
Instructions
将歌曲添加到播放列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | 播放列表ID | |
| songId | Yes | 歌曲ID |
Implementation Reference
- src/index.ts:247-259 (handler)The main handler function for the 'add_to_playlist' tool. It extracts playlistId and songId from args, adds the song to the playlist via PlaylistManager, fetches song details, and returns a success message.private async handleAddToPlaylist(args: any) { const { playlistId, songId } = args; await this.playlistManager.addSongToPlaylist(playlistId, songId); const song = await this.musicDb.getSongById(songId); return { content: [ { type: 'text', text: `✅ 歌曲已添加到播放列表!\n\n歌曲: ${song?.title} - ${song?.artist}`, }, ], };
- src/index.ts:97-114 (schema)Input schema and metadata for the 'add_to_playlist' tool, defined in the ListToolsRequestSchema handler.{ name: 'add_to_playlist', description: '将歌曲添加到播放列表', inputSchema: { type: 'object', properties: { playlistId: { type: 'string', description: '播放列表ID', }, songId: { type: 'string', description: '歌曲ID', }, }, required: ['playlistId', 'songId'], }, },
- src/index.ts:175-176 (registration)Switch case in the CallToolRequestSchema handler that registers and routes 'add_to_playlist' calls to its handler function.case 'add_to_playlist': return await this.handleAddToPlaylist(args);
- src/playlist-manager.ts:39-49 (helper)Supporting method in PlaylistManager that performs the actual addition of a song to a playlist, checking existence and avoiding duplicates.async addSongToPlaylist(playlistId: string, songId: string): Promise<void> { const playlist = this.playlists.get(playlistId); if (!playlist) { throw new Error(`播放列表 ${playlistId} 不存在`); } if (!playlist.songIds.includes(songId)) { playlist.songIds.push(songId); playlist.updatedAt = new Date().toISOString(); } }