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.
Declare the tools
Section titled “Declare the 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
playerorinstance. - A property has a
type(string,integer,number,boolean, orarraywithitemsof one of the other types) and adescriptionof one readable line of at most 200 characters. - Optionally a
defaultof its type, and for a string anenumof 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.
What the server adds
Section titled “What the server adds”- A required
playerargument (a player name or id) to a tool that requires a player. - A required
instanceargument when the user may use several instances of your provider. (from the <provider name> provider)at the end of the description.
Handle the call
Section titled “Handle the call”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}argumentsholds every declared property: the value passed, else its default, elseNone.player_idis the checked player, orNonefor a tool without one.- What the tool calls on
massruns as the user, so it sees only the players and music sources that user may use. A tool that acts on another player thanplayer_idcallsmass.players.check_player_access()first. - Return a
dictof JSON values. Keep it short (the built-in tools return at most 50 items) and refer to media items by theiruri. - Raise a
MusicAssistantErrorto report a failure: the assistant reads its message. Any other exception, or a result that is not adictof 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.