Skip to main content
Glama
tijs

MCP Sound Tool

by tijs

play_sound

Play notification sounds to indicate command success, failure, or alerts, providing audio feedback for task outcomes.

Instructions

    Play a notification sound on the user's device.
    
    WHEN TO USE THIS TOOL:
    - Use 'completion' sound when a task or command has SUCCESSFULLY completed
    - Use 'error' sound when a command has FAILED or an error has occurred
    - Use 'notification' sound for important alerts or information that needs attention
    - Use 'custom' sound only when you need a specific sound not covered by the standard types
    
    AI agents SHOULD proactively use these sounds to provide audio feedback based on
    the outcome of commands or operations, enhancing the user experience with
    non-visual status indicators.
    
    Example usage: After executing a terminal command, play a 'completion' sound if 
    successful or an 'error' sound if it failed.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sound_typeNocompletion
custom_sound_pathNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler function that resolves the sound file path and delegates to SoundPlayer.play_sound() to play the audio.
    def play_sound(sound_type: Literal["completion", "error", "notification", "custom"] = "completion",
               custom_sound_path: Optional[str] = None) -> str:
        if sound_type == "custom" and custom_sound_path:
            sound_path = custom_sound_path
        else:
            # Try MP3 file first, then WAV if MP3 doesn't exist
            mp3_filename = f"{sound_type}.mp3"
            wav_filename = f"{sound_type}.wav"
            mp3_path = os.path.join(self.sounds_dir, mp3_filename)
            wav_path = os.path.join(self.sounds_dir, wav_filename)
            
            # Check which file exists
            if os.path.exists(mp3_path):
                sound_path = mp3_path
            elif os.path.exists(wav_path):
                sound_path = wav_path
            else:
                # Print debug information
                print(f"Sounds directory: {self.sounds_dir}")
                print(f"Sound files available: {os.listdir(self.sounds_dir)}")
                return f"Error: Sound files not found: {mp3_path} or {wav_path}"
        
        # Play the sound
        try:
            self.player.play_sound(sound_path)
            return f"Successfully played {sound_type} sound"
        except Exception as e:
            return f"Error playing sound: {e}"
  • The static method on SoundPlayer that actually plays a sound file, dispatching to platform-specific commands (afplay on macOS, winsound on Windows, paplay/aplay/mpg123 on Linux).
    def play_sound(sound_file: str) -> None:
        """Play a sound file using the appropriate method for the current platform."""
        if not os.path.exists(sound_file):
            print(f"Error: Sound file not found: {sound_file}")
            return
        
        system = platform.system()
        
        try:
            if system == "Darwin":  # macOS
                subprocess.run(["afplay", sound_file], check=True)
            elif system == "Windows":
                import winsound
                winsound.PlaySound(sound_file, winsound.SND_FILENAME)
            elif system == "Linux":
                # Try different players until one works
                for player in ["paplay", "aplay", "mpg123", "mpg321"]:
                    try:
                        subprocess.run([player, sound_file], check=True)
                        break
                    except (subprocess.SubprocessError, FileNotFoundError):
                        continue
                else:
                    print("Error: Could not find a suitable audio player on Linux")
        except Exception as e:
            print(f"Error playing sound: {e}")
  • Schema definition for the play_sound tool, specifying name, description, parameters (sound_type enum + optional custom_sound_path), and return type.
    play_sound_tool_definition = {
        "name": "play_sound",
        "description": """
        Play a notification sound on the user's device.
        
        Use this tool to provide audio feedback to the user:
        - Use 'completion' when a task or command has successfully completed
        - Use 'error' when an error or failure has occurred
        - Use 'notification' for important information or alerts
        - Use 'custom' when you need to play a specific sound file
        
        AI agents should proactively use these sounds to improve user experience by
        providing audio cues for important events.
        """,
        "parameters": {
            "type": "object",
            "properties": {
                "sound_type": {
                    "type": "string",
                    "enum": ["completion", "error", "notification", "custom"],
                    "description": "The type of sound to play. Default is 'completion'."
                },
                "custom_sound_path": {
                    "type": "string",
                    "description": "Path to a custom sound file (only used if sound_type is 'custom')."
                }
            },
            "required": []
        },
        "returns": {
            "type": "string",
            "description": "A message indicating the result of the operation"
        }
    }
  • Registration of the play_sound tool via the @self.mcp.tool() decorator on the SoundToolServer, making it available as an MCP tool.
    def register_tools(self):
        """Register all MCP tools."""
        @self.mcp.tool(description="""
        Play a notification sound on the user's device.
        
        WHEN TO USE THIS TOOL:
        - Use 'completion' sound when a task or command has SUCCESSFULLY completed
        - Use 'error' sound when a command has FAILED or an error has occurred
        - Use 'notification' sound for important alerts or information that needs attention
        - Use 'custom' sound only when you need a specific sound not covered by the standard types
        
        AI agents SHOULD proactively use these sounds to provide audio feedback based on
        the outcome of commands or operations, enhancing the user experience with
        non-visual status indicators.
        
        Example usage: After executing a terminal command, play a 'completion' sound if 
        successful or an 'error' sound if it failed.
        """)
        def play_sound(sound_type: Literal["completion", "error", "notification", "custom"] = "completion",
                   custom_sound_path: Optional[str] = None) -> str:
            if sound_type == "custom" and custom_sound_path:
                sound_path = custom_sound_path
            else:
                # Try MP3 file first, then WAV if MP3 doesn't exist
                mp3_filename = f"{sound_type}.mp3"
                wav_filename = f"{sound_type}.wav"
                mp3_path = os.path.join(self.sounds_dir, mp3_filename)
                wav_path = os.path.join(self.sounds_dir, wav_filename)
                
                # Check which file exists
                if os.path.exists(mp3_path):
                    sound_path = mp3_path
                elif os.path.exists(wav_path):
                    sound_path = wav_path
                else:
                    # Print debug information
                    print(f"Sounds directory: {self.sounds_dir}")
                    print(f"Sound files available: {os.listdir(self.sounds_dir)}")
                    return f"Error: Sound files not found: {mp3_path} or {wav_path}"
            
            # Play the sound
            try:
                self.player.play_sound(sound_path)
                return f"Successfully played {sound_type} sound"
            except Exception as e:
                return f"Error playing sound: {e}"
  • Test for the SoundPlayer.play_sound static method, verifying error handling when the file doesn't exist.
    def test_play_sound_file_not_found(self, capfd):
        """Test behavior when sound file is not found."""
        # Call with non-existent file
        SoundPlayer.play_sound("nonexistent_file.mp3")
Behavior2/5

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

No annotations are provided, and the description does not disclose behavioral traits such as whether audio playback is synchronous, permission requirements, or error handling. The output schema exists but is not described.

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

Conciseness4/5

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

The description is well-structured with a clear introduction and bullet-point guidelines. The example adds context. It is slightly verbose but efficiently conveys necessary information.

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 simplicity (2 parameters, no required ones), the description covers the purpose, usage scenarios, and parameter semantics adequately. It does not discuss return values, but that is acceptable for a straightforward action.

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%, but the description adds meaning to the sound_type parameter by explaining when to use each value. The custom_sound_path parameter is implied but not detailed. This compensates partially for the lack of schema descriptions.

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 explicitly states 'Play a notification sound on the user's device' and differentiates between sound types with specific use cases. It clearly distinguishes from sibling tools like install_to_user_dir and list_available_sounds.

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

Usage Guidelines5/5

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

Provides detailed WHEN TO USE guidelines for each sound type (completion, error, notification, custom) and an example. This gives clear context for when the tool should be invoked.

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/tijs/py-sound-mcp'

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