Skip to main content
Glama

compose_music

Generate music from text prompts or composition plans and save the audio file to a specified directory. This tool converts descriptive input into musical compositions using ElevenLabs' audio generation technology.

Instructions

Convert a prompt to music and save the output audio file to a given directory. Directory is optional, if not provided, the output file will be saved to $HOME/Desktop.

Args:
    prompt: Prompt to convert to music. Must provide either prompt or composition_plan.
    output_directory: Directory to save the output audio file
    composition_plan: Composition plan to use for the music. Must provide either prompt or composition_plan.
    music_length_ms: Length of the generated music in milliseconds. Cannot be used if composition_plan is provided.

⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
composition_planNo
music_length_msNo
output_directoryNo
promptNo

Implementation Reference

  • The handler function that implements the core logic of the 'compose_music' tool. It validates inputs, calls the ElevenLabs client to generate music from a prompt or composition plan, saves the audio to a file, and returns the file path.
    def compose_music(
        prompt: str | None = None,
        output_directory: str | None = None,
        composition_plan: MusicPrompt | None = None,
        music_length_ms: int | None = None,
    ) -> TextContent:
        if prompt is None and composition_plan is None:
            make_error(
                f"Either prompt or composition_plan must be provided. Prompt: {prompt}"
            )
    
        if prompt is not None and composition_plan is not None:
            make_error("Only one of prompt or composition_plan must be provided")
    
        if music_length_ms is not None and composition_plan is not None:
            make_error("music_length_ms cannot be used if composition_plan is provided")
    
        output_path = make_output_path(output_directory, base_path)
        output_file_name = make_output_file("music", "", output_path, "mp3")
    
        audio_data = client.music.compose(
            prompt=prompt,
            music_length_ms=music_length_ms,
            composition_plan=composition_plan,
        )
    
        audio_bytes = b"".join(audio_data)
    
        output_path.parent.mkdir(parents=True, exist_ok=True)
        with open(output_path / output_file_name, "wb") as f:
            f.write(audio_bytes)
    
        return TextContent(
            type="text",
            text=f"Success. File saved as: {output_path / output_file_name}.",
        )
  • The @mcp.tool decorator registers the 'compose_music' tool with MCP and provides the input schema via the description and type annotations.
    @mcp.tool(
        description="""Convert a prompt to music and save the output audio file to a given directory.
        Directory is optional, if not provided, the output file will be saved to $HOME/Desktop.
    
        Args:
            prompt: Prompt to convert to music. Must provide either prompt or composition_plan.
            output_directory: Directory to save the output audio file
            composition_plan: Composition plan to use for the music. Must provide either prompt or composition_plan.
            music_length_ms: Length of the generated music in milliseconds. Cannot be used if composition_plan is provided.
    
        ⚠️ COST WARNING: This tool makes an API call to ElevenLabs which may incur costs. Only use when explicitly requested by the user."""
    )
  • Supporting tool 'create_composition_plan' that generates a MusicPrompt composition plan from a prompt, which can be passed to the compose_music handler.
    @mcp.tool(
        description="""Create a composition plan for music generation. Usage of this endpoint does not cost any credits but is subject to rate limiting depending on your tier. Composition plans can be used when generating music with the compose_music tool.
    
        Args:
            prompt: Prompt to create a composition plan for
            music_length_ms: The length of the composition plan to generate in milliseconds. Must be between 10000ms and 300000ms. Optional - if not provided, the model will choose a length based on the prompt.
            source_composition_plan: An optional composition plan to use as a source for the new composition plan
        """
    )
    def create_composition_plan(
        prompt: str,
        music_length_ms: int | None = None,
        source_composition_plan: MusicPrompt | None = None,
    ) -> MusicPrompt:
        composition_plan = client.music.composition_plan.create(
            prompt=prompt,
            music_length_ms=music_length_ms,
            source_composition_plan=source_composition_plan,
        )
    
        return composition_plan
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key traits: it mentions the API call to ElevenLabs with cost implications, specifies the default output directory ($HOME/Desktop), and outlines parameter constraints. However, it lacks details on error handling or response format, which would enhance transparency.

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 and appropriately sized: it starts with the core purpose, lists parameters with clear guidelines, and ends with a cost warning. Every sentence adds value, though the parameter explanations could be slightly more concise without losing clarity.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description is largely complete: it covers purpose, usage, parameters, and behavioral aspects like costs. However, it omits details on the output (e.g., file format or success indicators), which would be helpful given the lack of output schema.

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

Parameters5/5

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

Given 0% schema description coverage, the description fully compensates by explaining all four parameters: it defines 'prompt' and 'composition_plan' as mutually exclusive inputs, clarifies 'output_directory' as optional with a default, and notes that 'music_length_ms' cannot be used with 'composition_plan'. This adds essential meaning beyond the bare schema.

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 tool's purpose: 'Convert a prompt to music and save the output audio file to a given directory.' It specifies both the action (convert to music) and the resource (audio file), and distinguishes itself from sibling tools like 'create_composition_plan' by focusing on music generation rather than planning.

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?

The description provides explicit usage guidelines: it explains when to use the tool ('Only use when explicitly requested by the user'), includes a cost warning, and details parameter dependencies (e.g., 'Must provide either prompt or composition_plan' and 'Cannot be used if composition_plan is provided'). This offers clear context for when and how to invoke the tool.

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/projectservan8n/elevenlabs-mcp'

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