Skip to content

Tools for AI assistants (MCP)

A provider can offer its own tools to AI assistants, such as Home Assistant Assist, that use the built-in MCP server of Music Assistant (mcp_server). You declare them in mcp_tools in the manifest and implement them in handle_mcp_tool(). The MCP server offers them next to its own tools.

"mcp_tools": [
{
"id": "play_station",
"description": "Play one of the user's saved stations of this service on a player.",
"scope": "queues.control",
"requires_player": true,
"input_schema": {
"type": "object",
"properties": {
"station": {"type": "string", "description": "The name of the station."},
"shuffle": {"type": "boolean", "description": "Shuffle the station.", "default": false}
},
"required": ["station"]
}
}
]
Field Rule
id Groups of lower case letters and digits joined by single underscores, at most 32 characters, unique within the provider. The assistant sees the tool as <domain>__<id>, which may have at most 64 characters.
description What the tool does, in English: one readable line of at most 300 characters. It is not translated, as a language model reads it.
scope What a user needs to use the tool, such as library.read or queues.control. A user without it does not get the tool. A tool whose scope ends in .read is announced as read-only; for any other tool a client may ask the user to confirm.
requires_player Optional. true when the tool acts on a player.
input_schema Optional. The arguments, as below. A tool without it takes none.

The input_schema is type object with properties and required, and nothing else:

  • At most 10 properties. A name has lower case letters, digits and underscores, starts with a letter, has at most 32 characters, and is not player or instance.
  • A property has a type (string, integer, number, boolean, or array with items of one of the other types) and a description of one readable line of at most 200 characters.
  • Optionally a default of its type, and for a string an enum of at most 50 values of at most 64 characters each.

The descriptions, like the results, only describe the tool and its outcome. They never instruct the assistant about other tools, the user or the conversation.

A provider declares at most 10 tools. A tool that breaks a rule, repeats an id or comes after the first 10 valid ones is left out with a warning in the log, and in the server check_manifests fails on it. The limits are constants in helpers/mcp_tools.py.

  • A required player argument (a player name or id) to a tool that requires a player.
  • A required instance argument when the user may use several instances of your provider.
  • (from the <provider name> provider) at the end of the description.

The server checks that the user may use the instance and holds the scope, that the arguments match the schema and that the user may use the player. Then it calls your method:

async def handle_mcp_tool(
self, tool_id: str, arguments: dict[str, Any], player_id: str | None
) -> dict[str, Any]:
if tool_id != "play_station":
return await super().handle_mcp_tool(tool_id, arguments, player_id)
station = await self._find_station(arguments["station"])
...
return {"playing": station.uri}
  • arguments holds every declared property: the value passed, else its default, else None. player_id is the checked player, or None for a tool without one.
  • What the tool calls on mass runs as the user, so it sees only the players and music sources that user may use. A tool that acts on another player than player_id calls mass.players.check_player_access() first.
  • Return a dict of JSON values. Keep it short (the built-in tools return at most 50 items) and refer to media items by their uri.
  • Raise a MusicAssistantError to report a failure: the assistant reads its message. Any other exception, or a result that is not a dict of JSON values, is logged and the assistant reads “Internal error”.
  • Register nothing: the tools come and go with your provider.

The demo plugin, _demo_plugin_provider, has a complete example.

Music Assistant is a project of the Open Home Foundation.