Skip to main content
Glama

itunes_play_song

Play a specific song in Apple Music by searching for its exact name. Use this tool to control playback on macOS through AppleScript commands.

Instructions

Play the first track whose name exactly matches the given song name. Returns a confirmation message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
songYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool(), implementing the logic to play a specific song from the Music (iTunes) library using AppleScript. It searches for the first track matching the song name exactly and plays it, returning a confirmation message with artist.
    @mcp.tool()
    def itunes_play_song(song: str) -> str:
        """
        Play the first track whose name exactly matches the given song name.
        Returns a confirmation message.
        """
        script = f"""
        tell application "Music"
            set theTrack to first track of playlist "Library" whose name is "{song}"
            play theTrack
            return "Now playing: " & (name of theTrack) & " by " & (artist of theTrack)
        end tell
        """
        return run_applescript(script)
  • Helper function used by itunes_play_song and other tools to execute AppleScript commands via subprocess.
    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()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It discloses key behavior: plays the first exact match and returns a confirmation message. However, it doesn't mention error handling (e.g., if no match found), permissions, or side effects like interrupting current playback. It adds value but lacks comprehensive behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, zero waste. The first sentence states the action and matching logic; the second specifies the return. It's front-loaded with the core functionality and appropriately sized for a simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (1 parameter, simple action), an output schema exists (so return values are covered), and no annotations, the description is mostly complete. It covers purpose, basic behavior, and parameter use. Minor gaps include lack of error cases or playback context, but it's sufficient for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that the 'song' parameter is used for exact name matching and triggers playback of the first match. This clarifies the parameter's purpose beyond the schema's basic string type. However, it doesn't detail format constraints (e.g., case sensitivity).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Play'), the resource ('first track whose name exactly matches the given song name'), and distinguishes it from siblings like 'itunes_play' (general play) or 'itunes_search' (search without playing). It precisely defines the matching behavior as exact name match and first result.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context: when you want to play a specific song by exact name. It doesn't explicitly state when not to use it or name alternatives, but the sibling tools provide clear alternatives (e.g., use 'itunes_search' for broader search, 'itunes_play' for general playback). The guidance is clear but not exhaustive.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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