Skip to content

Menu actions

A provider can add entries to the menu of a track, album, artist, playlist, radio station, podcast, podcast episode or audiobook. You declare them in menu_actions in the manifest and handle them in handle_menu_action(). The app draws the entries, in a submenu under the name of the provider instance, so you ship no code for the app.

"menu_actions": [
{
"id": "send_to_frame",
"label": "Show on the picture frame",
"media_types": ["album", "playlist"],
"scope": "library.read",
"icon": "mdi-image-frame",
"requires_player": false
}
]
Field Rule
id Lower case letters, digits and underscores, at most 32 characters, unique within the provider.
label The English text of the entry: one readable line of at most 40 characters.
media_types One or more of track, album, artist, playlist, radio, podcast, podcast_episode, audiobook.
scope What a user needs to use the action, such as library.read, library.write or queues.control (the values of Scope in the models). The app hides the entry from a user without it, and the server refuses it.
icon Optional. A Material Design Icon name in the form mdi-..., at most 64 characters.
requires_player Optional. true when the action acts on a player: the app then also offers it in the menu of the play button and passes the chosen player.
  • A provider declares at most 10 actions. The limits are constants in helpers/menu_actions.py and, for the label, in provider.py of the models package.
  • To translate the label, put it in the strings.json of the provider under menu_actions.<id>.label. A translation may have up to 80 characters; one that is not a single readable line of at most 80 is not used, and the label from the manifest is shown.
  • An action that breaks a rule, repeats an id or comes after the first 10 valid ones is left out with a warning in the log; the provider loads without it. In the server, check_manifests fails on it.

When a user chooses an entry, the app calls the API command providers/invoke_menu_action with the instance, the action id, the uri of the item and, for an action that requires a player, the player_id. The server checks that the user may use the instance and holds the scope, that the uri is of one of the declared media types and that the user may use the player. Then it calls your method:

async def handle_menu_action(
self, action_id: str, uri: str, player_id: str | None
) -> ConfigActionResult | None:
if action_id != "send_to_frame":
return await super().handle_menu_action(action_id, uri, player_id)
item = await self.mass.music.get_item_by_uri(uri)
...
return ConfigActionResult(message=f"{item.name} is on the picture frame")
  • The server checks only the kind of item in the uri, not that the item exists or belongs to your provider: look it up yourself.
  • player_id is None for an action that does not require a player.
  • Return nothing, or a ConfigActionResult with a message the app shows and an open_url it opens once. For a provider from the community catalog, only an https URL is opened. A translation_key translates the message from config_actions in your strings.json.
  • Raise a MusicAssistantError to tell the user the action failed.
  • Register no command. Each instance of a provider with multi_instance gets the actions chosen for it.

The demo plugin, _demo_plugin_provider, has a complete example.

Music Assistant is a project of the Open Home Foundation.