Skip to main content
Glama
zas

MusicBrainz MCP Server

by zas

get_entity_relationships

Retrieve relationships for music entities like band members, producers, studios, and Wikipedia links using entity type and MBID from the MusicBrainz database.

Instructions

Get relationships for any entity type (e.g., band members, producers, recording studios, Wikipedia links). Args: entity_type: artist, release, release-group, recording, work, label, area, place, event, instrument, series entity_id: The MBID (must match the entity_type)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
entity_typeYes
entity_idYes

Implementation Reference

  • The 'get_entity_relationships' function implementation which fetches entity metadata from the MusicBrainz API and formats relationship data.
    def get_entity_relationships(entity_type: str, entity_id: str) -> str:
        """
        Get relationships for any entity type (e.g., band members, producers,
        recording studios, Wikipedia links).
        Args:
            entity_type: artist, release, release-group, recording, work, label, area,
                         place, event, instrument, series
            entity_id: The MBID (must match the entity_type)
        """
        valid_types = {
            "artist": (musicbrainzngs.get_artist_by_id, ["artist-rels", "url-rels"]),
            "release": (musicbrainzngs.get_release_by_id, ["artist-rels", "url-rels"]),
            "release-group": (
                musicbrainzngs.get_release_group_by_id,
                ["artist-rels", "url-rels"],
            ),
            "recording": (
                musicbrainzngs.get_recording_by_id,
                ["artist-rels", "work-rels", "url-rels"],
            ),
            "work": (musicbrainzngs.get_work_by_id, ["artist-rels", "url-rels"]),
            "label": (musicbrainzngs.get_label_by_id, ["artist-rels", "url-rels"]),
            "area": (musicbrainzngs.get_area_by_id, ["area-rels", "url-rels"]),
            "place": (musicbrainzngs.get_place_by_id, ["place-rels", "url-rels"]),
            "event": (musicbrainzngs.get_event_by_id, ["artist-rels", "url-rels"]),
            "instrument": (
                musicbrainzngs.get_instrument_by_id,
                ["instrument-rels", "url-rels"],
            ),
            "series": (musicbrainzngs.get_series_by_id, ["series-rels", "url-rels"]),
        }
    
        if entity_type not in valid_types:
            return f"Invalid entity type. Choose from: {', '.join(valid_types.keys())}"
    
        func, includes = valid_types[entity_type]
        res = func(entity_id, includes=includes)
        entity = res.get(entity_type)
        if not entity:
            return f"No data found for {entity_type} {entity_id}."
    
        lines = [f"Relationships for {entity_type} {entity_id}:"]
        found = False
    
        # Standardize relation list keys (artist-relation-list, url-relation-list, etc.)
        for key, value in entity.items():
            if key.endswith("-relation-list") and isinstance(value, list):
                for rel in value:
                    rtype = rel.get("type", "Unknown")
                    target = (
                        rel.get("artist", {}).get("name")
                        or rel.get("work", {}).get("title")
                        or rel.get("release", {}).get("title")
                        or rel.get("label", {}).get("name")
                        or rel.get("target", "Unknown")
                    )
                    lines.append(f"  - {rtype.capitalize()}: {target}")
                    found = True
    
        if not found:
            return f"No relationships found for this {entity_type}."
    
        return "\n".join(lines)

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/zas/mcp-musicbrainz'

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