@apple-music-agent/mcp-server
README.md
# đ Apple Music Agent
> **English** | [įŽäŊ䏿](./README.zh-CN.md)
[](https://github.com/zuoherry66-boop/apple-music-agent/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@apple-music-agent/mcp-server)
[](./LICENSE)
**Zero-developer-account open-source Apple Music AI assistant** â an MCP Server, Agent Skill, and local-only Manifest V3 Chrome Extension powered by the Apple Music Web Player API (`amp-api.music.apple.com`).
Control your Apple Music catalog, library, playlists, favorites, cross-platform migrations, and AI recommendations in plain natural language from **Claude Desktop**, **Claude Code**, **Cursor**, **Antigravity**, or any MCP-compatible AI agent â without paying \$99/year for an Apple Developer account.
---
> [!WARNING]
> **Disclaimer**: This project is strictly for personal learning and self-hosted productivity. It communicates with Apple Music's unofficial Web Player API (`amp-api.music.apple.com`), is **not affiliated with or endorsed by Apple Inc.**, and may break if Apple changes internal endpoints. All credentials remain 100% on your local machine. **Do NOT publish the bundled token-capture Chrome extension to the Chrome Web Store or any public extension marketplace.**
---
## 30-Second Quickstart
Requires **Node.js >= 20** and an Apple Music subscription.
```bash
# Claude Code â one line, no clone needed
claude mcp add apple-music -- npx -y @apple-music-agent/mcp-server
```
Claude Desktop / Cursor / Antigravity â add to your MCP config and restart the client:
```json
{
"mcpServers": {
"apple-music": {
"command": "npx",
"args": ["-y", "@apple-music-agent/mcp-server"]
}
}
}
```
Then sign in at [music.apple.com](https://music.apple.com) and load the Chrome extension (see [Auth setup](#auth--chrome-extension) below) â it syncs your session tokens automatically. That's it: try _"List my Apple Music playlists"_ or _"Move my NetEase playlist 'Running' into Apple Music"_.
> **Install from source instead?** `git clone https://github.com/zuoherry66-boop/apple-music-agent.git && cd apple-music-agent && npm install && npm run build`, then point your MCP config at `packages/mcp-server/dist/index.js` (see [Development](#development--testing)).
## Demo
<!-- TODO: add 1-minute demo video link here -->
_Demo walkthrough (video coming soon):_ in one sentence, ask the agent to migrate a NetEase Cloud Music playlist into Apple Music â it parses the playlist, matches each track against Apple's catalog (ISRC-first), and creates the playlist with a match report. Then ask it to delete a song: instead of deleting immediately, it shows a dry-run preview and waits for your explicit confirmation before anything is removed.
## Features
| Feature | What it does |
| :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Zero Developer Account Cost** | Reuses your own local `music.apple.com` web session tokens (`Authorization` Bearer + `Music-User-Token`) with automatic storefront region detection (`cn`, `us`, `jp`, etc.) |
| **14 Strict-Typed MCP Tools** | Catalog search (keyword + ISRC), library & playlist reading, recently played history, playlist creation, library/playlist additions, Favorites/Ratings, cross-platform import, safe deletion |
| **Mandatory Anti-Accident Protection** | `remove_from_playlist` and `remove_from_library` enforce **Two-Step Confirmation** â `confirm: false` returns a dry-run preview and a single-use, payload-bound `confirmation_token` (5-minute TTL); nothing is deleted until you confirm the exact track list |
| **Smart Cross-Platform Migration** | Built-in CSV / JSON / plain-text parser (Spotify, NetEase Cloud Music, QQ Music), marketing-noise title cleaner, version detector (Studio Original vs. Live / Remix / Cover / Instrumental), ISRC-first scorer, deduplicator |
| **Privacy-First MV3 Extension** | Captures headers locally via read-only `webRequest.onSendHeaders`, never transmits tokens to external servers; supports Copy `.env`, Download `auth.json`, or one-time `127.0.0.1` pairing sync |
| **Ready-to-Use Agent Skill** | [`skills/apple-music-manager/SKILL.md`](./skills/apple-music-manager/SKILL.md) defines standard operating workflows for playlist migration, playability-verified AI curation, and safe library cleanup |
## Comparison
Honest comparison with the closest alternative, [`epheterson/applemusic-mcp`](https://github.com/epheterson/applemusic-mcp) (Python, 140 stars). Pick whichever fits your setup â the table states what each project actually does.
| | apple-music-agent (this project) | epheterson/applemusic-mcp |
| :--------------------------- | :------------------------------------------------------------- | :-------------------------------------------------------- |
| **Install** | `npx -y @apple-music-agent/mcp-server` | `pipx install applemusic-mcp` |
| **Apple Developer account** | Never needed (web session tokens) | Not needed on macOS; needed for API mode on Windows/Linux |
| **Playback control** | â Not possible via the `amp-api` REST interface | â Via Mac Music.app or web player |
| **Engines** | 1 (Apple Music web API, any OS) | 4 (Music.app, API, Safari/Chrome web player, full) |
| **Token sync** | â Chrome extension auto-syncs on every `music.apple.com` visit | Manual `applemusic-mcp login` |
| **Cross-platform migration** | â Built-in parsers for Spotify / NetEase / QQ Music | Playlist import only, no built-in source parsers |
| **Delete safety** | â Mandatory two-step confirmation + dry-run preview | No equivalent confirmation flow |
| **Agent Skill** | â Bundled `skills/apple-music-manager/SKILL.md` | â |
| **Language** | TypeScript | Python |
## Architecture
```mermaid
flowchart LR
EXT["MV3 Chrome Extension\n(Local Header Capture)"] -.->|"Copy / Download / 127.0.0.1 Sync"| AUTH["~/.config/apple-music-agent/auth.json"]
SKILL["Agent Skill\n(SKILL.md)"] --> AGENT["AI Agent\n(Claude / Cursor / Antigravity)"]
AGENT <-->|"MCP (stdio)"| MCP["@apple-music-agent/mcp-server"]
MCP --> CORE["@apple-music-agent/core\n(Client / Matching / Safety)"]
AUTH --> CORE
CORE <-->|"HTTPS"| AMP["amp-api.music.apple.com"]
```
See [docs/architecture.md](./docs/architecture.md) for sequence diagrams and verified `amp-api` endpoint mappings.
## Auth & Chrome Extension
While running, the MCP server listens on `127.0.0.1:48123` (strictly allowing only `chrome-extension://` origins with a custom preflight header; set `APPLE_MUSIC_DISABLE_LOCAL_SYNC=1` to disable) and reloads `~/.config/apple-music-agent/auth.json` dynamically on every request.
Load `packages/chrome-extension/dist` as an unpacked extension in `chrome://extensions` (Developer mode ON):
1. Open [https://music.apple.com](https://music.apple.com) and sign in.
2. Browse your library briefly â the extension captures your headers and **silently auto-syncs** them to `~/.config/apple-music-agent/auth.json` (badge turns green **`OK`**). No terminal commands or pairing codes required!
3. Whenever tokens expire in the future, simply refresh `https://music.apple.com` and they refresh automatically.
_(Prefer manual export? Click **Download auth.json** or **Copy .env** in the popup, or follow [docs/auth-setup.md](./docs/auth-setup.md).)_
### Install the Agent Skill (Optional but Recommended)
Copy or symlink `skills/apple-music-manager` into your agent's skills directory (e.g., `~/.agents/skills/apple-music-manager` or `.claude/skills/apple-music-manager`) so your AI automatically follows the migration, recommendation, and safe-deletion SOPs.
## Available MCP Tools
| Tool | Description |
| :------------------------ | :-------------------------------------------------------------------------------------------- |
| `check_auth_status` | Verify credentials and detect active Apple Music storefront (`cn`/`us`/`jp`, etc.) |
| `search_catalog` | Search catalog by keyword or batch ISRCs (`songs`, `albums`, `artists`) with playability flag |
| `get_library_playlists` | List user's library playlists (paginated) |
| `get_playlist_tracks` | Read playlist tracks (paginated) with optional duplicate analysis |
| `get_library_songs` | List user's library songs (paginated) |
| `get_recently_played` | Fetch recently played tracks for taste profiling |
| `create_playlist` | Create a new library playlist with optional initial tracks |
| `add_to_library` | Add catalog songs, albums, or playlists to library |
| `add_to_playlist` | Append songs to an editable library playlist |
| `set_favorite` | Mark Favorite (`POST /v1/me/favorites`), Dislike (`-1`), or Clear rating |
| `remove_from_playlist` | Remove tracks from playlist (**Two-Step Confirmation required**) |
| `remove_from_library` | Delete songs from library (**Two-Step Confirmation required**) |
| `import_playlist_preview` | Parse CSV/JSON/text playlist, clean titles, and classify matches into 3 buckets |
| `import_playlist_execute` | Create or append confirmed catalog tracks with deduplication |
## Development & Testing
```bash
npm run lint # ESLint across all packages
npm run typecheck # TypeScript strict check
npm run build # Build core, mcp-server, and chrome-extension
npm test # Vitest unit tests (cleaner, scorer, dedup, parsers, confirmation, mocked API)
```
## Troubleshooting
- **`AUTH_EXPIRED` (HTTP 401 / 403)**: Apple Music web tokens expire periodically. Reopen `https://music.apple.com`, ensure you are signed in, and re-sync with the Chrome extension. No MCP restart is needed.
- **`RATE_LIMITED` (HTTP 429)**: The client automatically retries with exponential backoff (respecting `Retry-After`). For very large playlists (200+ songs), split imports into batches of ~100 tracks.
- **Track marked `unavailable_in_storefront`**: The song exists in Apple's catalog metadata, but lacks `playParams` in your account's storefront due to regional licensing.
- **Deleting a song from library removed it from playlists**: This is standard Apple Music behavior. `remove_from_library` always warns about this during dry-run preview.
## License
[MIT](./LICENSE)
<!-- Identifier for the official MCP Registry. -->
<!-- mcp-name: io.github.zuoherry66-boop/apple-music-agent -->