Skip to content

Add read-only Music playlist tools - #332

Merged
mattt merged 4 commits into
mattt:mainfrom
aashishvanand:music-playlist-tools
Nov 5, 2026
Merged

mattt merged 4 commits into
mattt:mainfrom
aashishvanand:music-playlist-tools

Conversation

@aashishvanand

Copy link
Copy Markdown
Contributor

This PR adds two read-only tools to the Music service, as discussed in #327. Neither tool changes anything; the write tools stay out until these are in.

Tools

  • music_playlists_list lists the playlists in the user's library: persistent ID, name, kind (user, smart, folder, or system for playlists Music manages, such as the library), track count, and the ID of the containing folder.
  • music_playlist_tracks reads one page of a playlist's tracks in playlist order, by persistent ID. Each track has its persistent ID, name, artist, album, and duration. The result includes the playlist's total and nextOffset, which is null on the last page. Pass nextOffset back as offset to get the next page.

Both tools run on the shared AppleScript queue from #307.

Notes

  • Page size. limit defaults to 100, with a maximum of 500. Music isn't the bottleneck: reading all 2,041 tracks of my library in one script took about 0.26 s. The cap keeps a single response a reasonable size for a model's context, since the whole library comes to roughly 250 KB of text. Happy to change the numbers.
  • One Apple event per property. The script reads each property for the whole page at once (name of tracks 101 thru 200 of thePlaylist) instead of looping over tracks. A one-track range returns a bare value, so each result is coerced with as list.
  • Script safety. The playlist ID must be 16 hexadecimal digits before it goes into the script. A playlist ID that doesn't exist returns an error pointing the agent to music_playlists_list.
  • I also updated the Music row in the README.

Testing

  • swift format lint --strict --recursive . passes.
  • Build and imcp-serverTests pass locally on macOS 27.2 with Xcode 27.2: 168 tests, 0 failures. The new tests cover ID validation, paging arguments, nextOffset, and compiling both scripts against Music's dictionary.
  • I ran both scripts as generated against a real library. They return the right results for the first and last pages, a one-track page, a page past the end, an unknown ID, and smart and system playlists.

🤖 Generated with Claude Code

music_playlists_list lists the playlists in the user's Music library
with each playlist's persistent ID, kind (user, smart, folder, or system),
track count, and containing folder.

music_playlist_tracks reads one page of a playlist's tracks in playlist order,
by persistent ID, with limit (default 100, at most 500) and offset.
The result includes the playlist's total track count and nextOffset,
which is null on the last page.
Each property is read for the whole page in one Apple event.
The ID must be 16 hexadecimal digits, so it is safe to put in the script.

Both tools run on the shared AppleScript queue and change nothing.

Part of mattt#327

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An accepted Int.max offset causes pagination arithmetic to overflow and terminate iMCP instead of returning a tool error.

3 open issues
What changed in this PR

Adds read-only playlist access to the Music service, covering the first step of #327 and using the shared AppleScript queue introduced in #307. Playlist write operations remain out of scope.

Changes:

  • Adds tools to list playlists and retrieve paginated tracks with metadata.
  • Adds tests for playlist IDs, paging arguments, completion offsets, and script compilation.
  • Updates the README with playlist capabilities and permission requirements.
File Description
Tests/​imcp-serverTests/​MusicTests.swift Tests playlist validation, pagination, and script compilation.
README.md Documents playlist tools and required Automation permission.
App/​Services/​Music.swift Implements playlist tools, scripts, validation, and response models.

Review effort: Balanced

Comment thread App/Services/Music.swift Resolved
Comment thread App/Services/Music.swift Resolved
Comment thread App/Services/Music.swift Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the read-only playlist access changes.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@mattt
mattt merged commit c30e84c into mattt:main Nov 5, 2026
3 of 4 checks passed
@mattt

mattt commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Thanks, @aashishvanand! I pushed fixes for the three things Copilot flagged — the offset overflow, nextOffset: null on the last page, and the library playlist — and merged. Looking forward to the write tools whenever you're ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants