add_to_playlist
Add songs to music playlists using song and playlist IDs. This tool helps organize your music collection by placing tracks into specific playlists for better listening management.
Instructions
将歌曲添加到播放列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlistId | Yes | 播放列表ID | |
| songId | Yes | 歌曲ID |
Implementation Reference
- src/index.ts:247-259 (handler)Main handler function for 'add_to_playlist' tool. Extracts playlistId and songId, delegates to playlistManager.addSongToPlaylist, fetches song info for response, and returns 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:100-113 (schema)Input schema definition for the 'add_to_playlist' tool, defining playlistId and songId as required string parameters.inputSchema: { type: 'object', properties: { playlistId: { type: 'string', description: '播放列表ID', }, songId: { type: 'string', description: '歌曲ID', }, }, required: ['playlistId', 'songId'], },
- src/index.ts:175-176 (registration)Registration of the 'add_to_playlist' handler in the switch statement for tool dispatch.case 'add_to_playlist': return await this.handleAddToPlaylist(args);
- src/playlist-manager.ts:39-49 (helper)Helper method implementing the core logic: retrieves playlist, checks existence, adds songId if not already present, updates timestamp.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(); } }
- src/playlist-manager.ts:1-8 (schema)Type definition for Playlist used internally by the playlist manager.export interface Playlist { id: string; name: string; description?: string; songIds: string[]; createdAt: string; updatedAt: string; }