playlist_remove
Remove a specific file from a saved playlist by providing the playlist name and the 0-based index of the track to delete.
Instructions
Remove a file from a saved playlist by index (0-based).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Playlist name | |
| index | Yes | 0-based index to remove |
Implementation Reference
- index.js:462-472 (schema)Schema definition for the playlist_remove tool - requires 'name' (string) and 'index' (number) parameters.
{ name: "playlist_remove", description: "Remove a file from a saved playlist by index (0-based).", inputSchema: { type: "object", properties: { name: { type: "string", description: "Playlist name" }, index: { type: "number", description: "0-based index to remove" }, }, required: ["name", "index"], }, - index.js:654-685 (handler)Handler logic for playlist_remove: reads playlist file, removes the entry at the given 0-based index, writes back the playlist, and also removes the matching entry from the live mpv queue if mpv is running.
case "playlist_remove": { const files = readPlaylist(args.name); if (args.index < 0 || args.index >= files.length) return fail(`Index ${args.index} out of range (0–${files.length - 1})`); const removed = files.splice(args.index, 1); writePlaylist(args.name, files); // Also remove from live mpv queue if running if (await isMpvRunning()) { const currentPos = await getProperty("playlist-pos").catch(() => null); const plCount = await getProperty("playlist-count").catch(() => 0); // Find matching entry in mpv's live playlist let liveIndex = null; for (let i = 0; i < plCount; i++) { const entry = await getProperty(`playlist/${i}/filename`).catch(() => null); if (entry && (entry === removed[0] || entry.replace(/\\/g, "/") === removed[0].replace(/\\/g, "/"))) { liveIndex = i; break; } } if (liveIndex !== null) { await mpv("playlist-remove", [liveIndex]); // If we removed the currently playing track, mpv auto-advances; // make sure it's playing (not paused) if (liveIndex === currentPos) { await setProperty("pause", false); } } } return ok(`Removed "${removed[0]}" from "${args.name}" (live queue updated)`); } - index.js:726-729 (registration)CallToolRequestSchema handler dispatches all tool calls (including playlist_remove) to the handleTool function via a switch statement.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; return handleTool(name, args || {}); }); - index.js:724-724 (registration)ListToolsRequestSchema handler returns the TOOLS array which includes the playlist_remove definition.
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS })); - index.js:284-297 (helper)Helper functions readPlaylist and writePlaylist used by playlist_remove to read and write .m3u playlist files.
function readPlaylist(name) { const p = playlistPath(name); if (!fs.existsSync(p)) throw new Error(`Playlist "${name}" not found`); return fs .readFileSync(p, "utf8") .split("\n") .map((l) => l.trim()) .filter((l) => l && !l.startsWith("#")); } function writePlaylist(name, files) { const content = "#EXTM3U\n" + files.join("\n") + "\n"; fs.writeFileSync(playlistPath(name), content, "utf8"); }