Repository navigation
Add read-only Music playlist tools - #332
Merged
Merged
Conversation
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]>
Contributor
There was a problem hiding this comment.
🟡 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
Owner
|
Thanks, @aashishvanand! I pushed fixes for the three things Copilot flagged — the offset overflow, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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_listlists the playlists in the user's library: persistent ID, name, kind (user,smart,folder, orsystemfor playlists Music manages, such as the library), track count, and the ID of the containing folder.music_playlist_tracksreads 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'stotalandnextOffset, which isnullon the last page. PassnextOffsetback asoffsetto get the next page.Both tools run on the shared AppleScript queue from #307.
Notes
limitdefaults 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.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 withas list.music_playlists_list.Testing
swift format lint --strict --recursive .passes.imcp-serverTestspass 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.🤖 Generated with Claude Code