Skip to content

Add Music service - #133

Merged
mattt merged 15 commits into
mainfrom
mattt/music
Oct 23, 2026
Merged

mattt merged 15 commits into
mainfrom
mattt/music

Conversation

@mattt

@mattt mattt commented Jan 30, 2026 •

Copy link
Copy Markdown
Owner

This PR adds a Music service with tools to read what's playing in the Music app, control playback, and search the Apple Music catalog.

music_now_playing and music_control talk to the Music app through AppleScript, so they need Automation permission for Music, which macOS asks for the first time iMCP sends Music an Apple event. music_catalog_search uses MusicKit and needs Apple Music access. Each tool family checks only the permission it uses: the catalog tool asks for Apple Music access only while the user hasn't decided yet, and a denial leaves the playback tools working. MusicKit also needs the MusicKit App Service turned on for the app's App ID in the developer portal; there's no entitlement key for it. The app adds a temporary Apple Events exception for com.apple.Music and usage descriptions for Apple Events and Apple Music.

music_control takes an action (play, pause, playpause, next, previous, stop, or seek). A seek position must be a finite number; iMCP clamps it to the current track's duration, or to 24 hours when the duration is unknown, and writes it into the script in plain decimal notation whatever the user's locale. music_catalog_search accepts a list of catalog types and defaults to songs, albums, artists, and playlists when the list is omitted; an empty list is an error. Limits and offsets must be whole numbers.

The README lists the new service with its icon, and the hero images include it.

Screenshot 2026-01-30 at 06 32 42

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.

Pull request overview

This PR adds a comprehensive Music service to iMCP, enabling control of the macOS Music app and search of the Apple Music catalog. The service integrates with MusicKit for catalog search and uses AppleScript for playback control.

Changes:

  • Adds MusicService with three tools: music_now_playing for track info, music_control for playback control, and music_catalog_search for searching the Apple Music catalog
  • Updates entitlements and Info.plist with required permissions for Apple Music API access and Apple Events to control the Music app
  • Registers Music service in ServerController with appropriate configuration and default-disabled state

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
App/Services/Music.swift Implements MusicService with MusicKit integration for catalog search and AppleScript-based playback control
App/Info.plist Adds NSAppleMusicUsageDescription and NSAppleEventsUsageDescription for required permissions
App/App.entitlements Adds com.apple.Music to apple-events exception array for production build
App/App.Debug.entitlements Adds com.apple.Music to apple-events exception array for debug build
App/Controllers/ServerController.swift Registers MusicService in service registry with pink icon and default-disabled state

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread App/Services/Music.swift Resolved
Comment thread App/Services/Music.swift Resolved
bratland added a commit to bratland/iMCP that referenced this pull request Apr 13, 2026
@mattt
mattt requested a balanced review from Copilot September 8, 2026 13:46

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

Missing MusicKit entitlements, unsafe numeric conversions, and off-main AppleScript execution can cause authorization failures or crashes.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 5
  • Review effort level: Balanced

Comment thread App/Services/Music.swift Resolved
Comment thread App/Services/Music.swift Resolved
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.

🟡 Changes recommended

Integer seek positions fail, and malformed search types silently broaden catalog queries.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

App/Services/Music.swift:287

  • Malformed or unknown types values are silently discarded; if none remain, resolveSearchTypes broadens the request to the four default types. Because tool schemas are only advertised and are not enforced before this handler runs, an invalid request can unexpectedly return unrelated catalog data. Reject a non-array, non-string element, or unknown enum value instead.
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Balanced

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.

🟡 Changes recommended

MusicKit capability entitlements are missing, and several catalog arguments are not strictly validated.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

App/Services/Music.swift:352

  • This non-strict conversion accepts values such as the string "10", contrary to the integer schema and the emitted error message. Validate with intValue so malformed input is rejected at runtime.
            guard let offset = Int(value, strict: false), offset >= 0 else {
  • Files reviewed: 5/5 changed files
  • Comments generated: 4
  • Review effort level: Balanced

Comment thread App/App.Debug.entitlements Resolved
Comment thread App/App.entitlements Resolved
Comment thread App/Services/Music.swift Resolved
Comment thread App/Services/Music.swift Resolved
@mattt
mattt force-pushed the mattt/music branch 2 times, most recently from 10e9c4e to f43ef9e Compare October 21, 2026 14:11
mattt added 13 commits October 23, 2026 09:09
- Sort Music service entries alphabetically after Messages
- Use a distinct error code for generic AppleScript failures
- Default catalog search limit to defaultSearchLimit
- Isolate the NSAppleScript call path to the main actor
- Return an empty list for empty Apple event descriptors
- Reject non-integer and out-of-range limit/offset instead of trapping
- Accept integer as well as fractional seek positions
- Reject malformed catalog types instead of falling back to defaults
- Reject non-boolean includeTopResults values
- Reject numeric strings for limit and offset
mattt added 2 commits October 23, 2026 09:20
# Conflicts:
#	App/Controllers/ServerController.swift
#	Assets/hero-dark.svg
#	Assets/hero-light.svg
@mattt
mattt merged commit 502cfdc into main Oct 23, 2026
2 checks passed
@mattt
mattt deleted the mattt/music branch October 23, 2026 20:04
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.

2 participants