Skip to main content
Glama
jamiew

Spotify MCP Server

get_recommendations

Generate personalized music recommendations using seed artists, tracks, or genres from Spotify. Input up to 5 seeds to receive tailored track suggestions for discovering new music.

Instructions

Get track recommendations based on seed artists, tracks, or genres.

Args:
    seed_artists: List of artist IDs (up to 5 total seeds combined)
    seed_tracks: List of track IDs (up to 5 total seeds combined)
    seed_genres: List of genres (up to 5 total seeds combined)
    limit: Number of recommendations to return (1-100, default 20)

Returns:
    Dict with 'tracks' list of recommended tracks

Note: Total seeds (artists + tracks + genres) must be between 1 and 5.
Use search_tracks to find seed track/artist IDs, or common genres like:
'pop', 'rock', 'hip-hop', 'electronic', 'jazz', 'classical', 'r-n-b', 'country'

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
seed_artistsNo
seed_tracksNo
seed_genresNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function implementing the get_recommendations tool. Decorated with @mcp.tool() for FastMCP registration and @log_tool_execution. Calls Spotify's recommendations API, validates seeds (1-5 total), parses results using parse_track helper, and returns recommended tracks with seeds used.
    @mcp.tool()
    @log_tool_execution
    def get_recommendations(
        seed_artists: list[str] | None = None,
        seed_tracks: list[str] | None = None,
        seed_genres: list[str] | None = None,
        limit: int = 20,
    ) -> dict[str, Any]:
        """Get track recommendations based on seed artists, tracks, or genres.
    
        Args:
            seed_artists: List of artist IDs (up to 5 total seeds combined)
            seed_tracks: List of track IDs (up to 5 total seeds combined)
            seed_genres: List of genres (up to 5 total seeds combined)
            limit: Number of recommendations to return (1-100, default 20)
    
        Returns:
            Dict with 'tracks' list of recommended tracks
    
        Note: Total seeds (artists + tracks + genres) must be between 1 and 5.
        Use search_tracks to find seed track/artist IDs, or common genres like:
        'pop', 'rock', 'hip-hop', 'electronic', 'jazz', 'classical', 'r-n-b', 'country'
        """
        try:
            # Validate seeds
            total_seeds = (
                len(seed_artists or [])
                + len(seed_tracks or [])
                + len(seed_genres or [])
            )
            if total_seeds == 0:
                raise ValueError("At least one seed (artist, track, or genre) is required")
            if total_seeds > 5:
                raise ValueError("Maximum 5 total seeds allowed (artists + tracks + genres)")
    
            limit = max(1, min(100, limit))
    
            logger.info(
                f"🎲 Getting recommendations (artists={seed_artists}, "
                f"tracks={seed_tracks}, genres={seed_genres}, limit={limit})"
            )
            result = spotify_client.recommendations(
                seed_artists=seed_artists,
                seed_tracks=seed_tracks,
                seed_genres=seed_genres,
                limit=limit,
            )
    
            tracks = []
            for item in result.get("tracks", []):
                if item:
                    tracks.append(parse_track(item).model_dump())
    
            return {
                "tracks": tracks,
                "seeds": {
                    "artists": seed_artists or [],
                    "tracks": seed_tracks or [],
                    "genres": seed_genres or [],
                },
            }
        except SpotifyException as e:
            raise convert_spotify_error(e) from e
  • The @mcp.tool() decorator registers the get_recommendations function as an MCP tool in FastMCP, which automatically generates input schema from type hints.
    @mcp.tool()
  • Pydantic model Track used for parsing and structuring recommended track data in the output.
    class Track(BaseModel):
        """A Spotify track with metadata."""
    
        name: str
        id: str
        artist: str
        artists: list[str] | None = None
        album: str | None = None
        album_id: str | None = None
        release_date: str | None = None
        duration_ms: int | None = None
        popularity: int | None = None
        external_urls: dict[str, str] | None = None
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 and does well by disclosing key behavioral traits: the total seeds constraint (1-5 combined), the limit range (1-100), the default value (20), and the return format (dict with 'tracks' list). It doesn't mention rate limits or authentication needs, but provides substantial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with clear sections (purpose, args, returns, note) and every sentence adds value. It's front-loaded with the core purpose, then provides necessary details without redundancy. The genre examples are helpful rather than wasteful.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity, no annotations, and the existence of an output schema, the description is complete enough. It explains the purpose, parameters, constraints, return format, and even provides usage guidance with sibling references. The output schema handles return value details, so the description appropriately focuses on operational context.

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?

With 0% schema description coverage, the description fully compensates by explaining all 4 parameters in detail: what each seed parameter accepts (IDs or genres), their constraints (up to 5 total combined), the limit range and default, and even provides genre examples. This adds significant 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 with a specific verb ('Get') and resource ('track recommendations'), and distinguishes it from siblings by specifying it's for generating recommendations based on seeds rather than retrieving existing data like get_track_info or searching like search_tracks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (to get recommendations based on seed inputs) and explicitly mentions an alternative tool (search_tracks) for finding seed IDs. However, it doesn't explicitly state when NOT to use this tool versus other siblings like get_saved_tracks or get_playlist_tracks.

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/jamiew/spotify-mcp'

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