playlist_add
Append multiple files to a specified existing playlist in mpv media player. Provide playlist name and list of file paths to extend the playlist.
Instructions
Add files to an existing playlist.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Playlist name | |
| files | Yes | Files to append |
Implementation Reference
- index.js:446-461 (schema)Tool definition and input schema for 'playlist_add'. Declares required parameters: name (string) and files (array of strings).
{ name: "playlist_add", description: "Add files to an existing playlist.", inputSchema: { type: "object", properties: { name: { type: "string", description: "Playlist name" }, files: { type: "array", items: { type: "string" }, description: "Files to append", }, }, required: ["name", "files"], }, }, - index.js:646-652 (handler)Handler for 'playlist_add' tool. Reads the existing playlist, appends new files, and writes back. Returns a success message with the total count.
case "playlist_add": { const existing = readPlaylist(args.name); writePlaylist(args.name, [...existing, ...args.files]); return ok( `Added ${args.files.length} item(s) to "${args.name}" (total: ${existing.length + args.files.length})` ); } - index.js:294-297 (helper)writePlaylist helper - writes an M3U playlist file (with #EXTM3U header) to the playlist directory.
function writePlaylist(name, files) { const content = "#EXTM3U\n" + files.join("\n") + "\n"; fs.writeFileSync(playlistPath(name), content, "utf8"); } - index.js:284-292 (helper)readPlaylist helper - reads an existing M3U playlist file, strips M3U headers and comments, returns array of file paths.
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("#")); } - index.js:724-729 (registration)Tool registration via MCP SDK - the TOOLS array (containing all tool schemas) is registered via ListToolsRequestSchema handler, and CallToolRequestSchema dispatches to handleTool().
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS })); server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; return handleTool(name, args || {}); });