add_track_to_playlist
Add a track to an existing rekordbox playlist by specifying playlist and track IDs. Modifies the rekordbox database directly.
Instructions
Add a track to an existing playlist.
⚠️ CAUTION: This modifies your rekordbox database!
Args: playlist_id: ID of the playlist to modify track_id: ID of the track to add
Returns: Result of the operation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| playlist_id | Yes | ||
| track_id | Yes |
Implementation Reference
- rekordbox_mcp/server.py:596-602 (registration)The @mcp.tool decorator registers the 'add_track_to_playlist' tool with MCP/FastMCP, including annotations for behavior hints.@mcp.tool( annotations={ "readOnlyHint": False, "destructiveHint": False, "idempotentHint": True } )
- rekordbox_mcp/server.py:603-639 (handler)The primary handler function for the 'add_track_to_playlist' MCP tool. Ensures database connection, calls the database helper, handles errors, and formats the response.async def add_track_to_playlist( playlist_id: str, track_id: str ) -> Dict[str, Any]: """ Add a track to an existing playlist. ⚠️ CAUTION: This modifies your rekordbox database! Args: playlist_id: ID of the playlist to modify track_id: ID of the track to add Returns: Result of the operation """ await ensure_database_connected() try: success = await db.add_track_to_playlist(playlist_id, track_id) if success: return { "status": "success", "message": f"Added track {track_id} to playlist {playlist_id}", "playlist_id": playlist_id, "track_id": track_id } else: return { "status": "error", "message": "Failed to add track to playlist" } except Exception as e: return { "status": "error", "message": f"Failed to add track to playlist: {str(e)}" }
- rekordbox_mcp/database.py:817-853 (helper)The RekordboxDatabase class method that implements the core logic for adding a track to a playlist, including backup, pyrekordbox operations, commit/rollback, and logging.async def add_track_to_playlist(self, playlist_id: str, track_id: str) -> bool: """ Add a track to an existing playlist. Args: playlist_id: ID of the playlist track_id: ID of the track to add Returns: True if successful """ if not self.db: raise RuntimeError("Database not connected") try: # Create backup before mutation await self._create_backup() # Verify playlist and track exist playlist_int_id = int(playlist_id) track_int_id = int(track_id) # Add track to playlist using pyrekordbox self.db.add_to_playlist(playlist_int_id, track_int_id) # Commit changes self.db.commit() logger.info(f"Added track {track_id} to playlist {playlist_id}") return True except Exception as e: logger.error(f"Failed to add track {track_id} to playlist {playlist_id}: {e}") # Rollback on error if hasattr(self.db, 'rollback'): self.db.rollback() raise RuntimeError(f"Failed to add track to playlist: {str(e)}")