Skip to main content
Glama

itunes_search

Search Apple Music library to find tracks matching a specified query. Retrieve results as a list formatted as "Track Name - Artist" for easy identification and selection.

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 handler function for the 'itunes_search' tool. It uses AppleScript executed via run_applescript to search the Music library for tracks 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)
  • Supporting helper function used by itunes_search and other tools to execute AppleScript commands.
    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()
  • The @mcp.tool() decorator registers the itunes_search function as an MCP tool.
    @mcp.tool()

Other Tools

Related Tools

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