Skip to main content
Glama

itunes_search

Search the Apple Music library for tracks by name using a query, returning results formatted as 'Track Name - Artist'.

Instructions

Search the Music library for tracks whose names contain the given query. Returns a list of tracks formatted as "Track Name - Artist".

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The primary handler for the 'itunes_search' tool. It uses AppleScript via run_applescript to find tracks in the Music library matching the query and returns a formatted list.
    @mcp.tool() def itunes_search(query: str) -> str: """ Search the Music library for tracks whose names contain the given query. Returns a list of tracks formatted as "Track Name - Artist". """ script = f""" tell application "Music" set trackList to every track of playlist "Library" whose name contains "{query}" set output to "" repeat with t in trackList set output to output & (name of t) & " - " & (artist of t) & linefeed end repeat return output end tell """ return run_applescript(script)
  • Helper function used by itunes_search to execute the AppleScript code for searching the library.
    def run_applescript(script: str) -> str: """Execute an AppleScript command via osascript and return its output.""" result = subprocess.run(["osascript", "-e", script], capture_output=True, text=True) if result.returncode != 0: return f"Error: {result.stderr.strip()}" return result.stdout.strip()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kennethreitz/mcp-applemusic'

If you have feedback or need assistance with the MCP directory API, please join our Discord server