Skip to main content
Glama
davehenke

rekordbox-mcp

add_tracks_to_playlist

Idempotent

Add multiple tracks to an existing rekordbox playlist in one batch operation to modify your DJ database efficiently.

Instructions

Add multiple tracks to an existing playlist in one operation.

⚠️ CAUTION: This modifies your rekordbox database!

Args: playlist_id: ID of the playlist to modify track_ids: List of track IDs to add

Returns: Detailed results of the batch operation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYes
track_idsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Primary MCP tool handler and registration for 'add_tracks_to_playlist'. Handles tool invocation, input validation via type hints/Pydantic, database connection check, delegates to RekordboxDatabase implementation, and returns formatted response with results summary.
    @mcp.tool(
        annotations={
            "readOnlyHint": False,
            "destructiveHint": False,
            "idempotentHint": True
        }
    )
    async def add_tracks_to_playlist(
        playlist_id: str,
        track_ids: List[str]
    ) -> Dict[str, Any]:
        """
        Add multiple tracks to an existing playlist in one operation.
        
        ⚠️ CAUTION: This modifies your rekordbox database!
        
        Args:
            playlist_id: ID of the playlist to modify
            track_ids: List of track IDs to add
            
        Returns:
            Detailed results of the batch operation
        """
        await ensure_database_connected()
        
        try:
            results = await db.add_tracks_to_playlist(playlist_id, track_ids)
            
            return {
                "status": "success",
                "message": f"Batch add completed: {len(results['added'])} added, {len(results['skipped'])} skipped, {len(results['failed'])} failed",
                "playlist_id": playlist_id,
                "summary": {
                    "added_count": len(results['added']),
                    "skipped_count": len(results['skipped']),
                    "failed_count": len(results['failed'])
                },
                "details": results
            }
            
        except Exception as e:
            logger.error(f"Failed to add tracks to playlist: {e}")
            return {
                "status": "error",
                "message": f"Failed to add tracks to playlist: {str(e)}"
            }
  • Core database implementation of add_tracks_to_playlist in RekordboxDatabase class. Creates backup, iterates over track IDs, calls pyrekordbox's add_to_playlist for each, commits transaction, tracks added/failed, handles rollback on error.
    async def add_tracks_to_playlist(self, playlist_id: str, track_ids: List[str]) -> Dict[str, Any]:
        """
        Add multiple tracks to a playlist.
        
        Args:
            playlist_id: ID of the playlist to modify
            track_ids: List of track IDs to add
            
        Returns:
            Dictionary with success/failure details
        """
        if not self.db:
            raise RuntimeError("Database not connected")
        
        try:
            # Create backup before mutation
            await self._create_backup()
            
            results = {
                "added": [],
                "failed": [],
                "skipped": []
            }
            
            playlist_int_id = int(playlist_id)
            
            for track_id in track_ids:
                try:
                    track_int_id = int(track_id)
                    
                    # Use the same method as the working single-track function
                    self.db.add_to_playlist(playlist_int_id, track_int_id)
                    results["added"].append(track_id)
                    logger.info(f"Added track {track_id} to playlist {playlist_id}")
                    
                except Exception as e:
                    results["failed"].append({"track_id": track_id, "reason": str(e)})
                    logger.warning(f"Failed to add track {track_id}: {e}")
            
            # Commit all changes
            self.db.commit()
            
            logger.info(f"Batch add to playlist {playlist_id}: {len(results['added'])} added, {len(results['failed'])} failed")
            return results
            
        except Exception as e:
            logger.error(f"Failed to add tracks to playlist {playlist_id}: {e}")
            # Rollback on error
            if hasattr(self.db, 'rollback'):
                self.db.rollback()
            raise RuntimeError(f"Failed to add tracks to playlist: {str(e)}")
  • Supporting helper method _create_backup called before mutations like add_tracks_to_playlist to create timestamped backup of the master.db file for safety.
    async def _create_backup(self) -> None:
        """
        Create a backup of the database before performing mutations.
        """
        if not self.database_path:
            return
        
        try:
            import shutil
            timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
            
            # Try different database file patterns
            possible_files = [
                self.database_path / "master.db",
                self.database_path / "rekordbox" / "master.db",
                *list(self.database_path.glob("**/master.db")),
                *list(self.database_path.glob("**/*.db"))
            ]
            
            db_file = None
            for file_path in possible_files:
                if file_path.exists() and file_path.is_file():
                    db_file = file_path
                    break
            
            if db_file:
                backup_path = self.database_path / f"master_backup_{timestamp}.db"
                shutil.copy2(db_file, backup_path)
                logger.info(f"Database backup created: {backup_path}")
            else:
                # List available files for debugging
                all_files = list(self.database_path.rglob("*"))
                db_files = [f for f in all_files if f.suffix == '.db']
                logger.warning(f"No database file found for backup. Available .db files: {db_files}")
            
        except Exception as e:
            logger.warning(f"Failed to create database backup: {e}")
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds significant behavioral context beyond annotations: the ⚠️ CAUTION warning about database modification provides crucial safety information, and 'Detailed results of the batch operation' describes output behavior. Annotations indicate mutability (readOnlyHint=false) and idempotency, but the description enhances this with practical implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly structured: purpose statement first, critical warning next, then parameter explanations, and finally return behavior. Every sentence earns its place with no redundancy, making it highly scannable and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a mutation tool with 2 parameters, 0% schema coverage, but with output schema present, the description provides excellent completeness. It covers purpose, safety warning, parameter meanings, and output behavior—everything needed beyond the structured fields for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description compensates well by explaining both parameters: 'playlist_id: ID of the playlist to modify' and 'track_ids: List of track IDs to add'. This adds essential semantic meaning missing from the bare schema. However, it doesn't specify format requirements or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Add multiple tracks'), target resource ('existing playlist'), and scope ('in one operation'). It distinguishes from sibling 'add_track_to_playlist' by emphasizing batch/multiple capability, making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (batch adding to existing playlists) and implicitly distinguishes from 'create_playlist' (requires existing playlist) and 'add_track_to_playlist' (single vs multiple). However, it doesn't explicitly state when NOT to use it or mention all relevant alternatives like 'remove_track_from_playlist'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/davehenke/rekordbox-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server