Skip to main content
Glama
kylestratis

Spotify Playlist MCP Server

by kylestratis

spotify_get_track

Retrieve comprehensive metadata for a specific Spotify track using its ID, including artist details, album information, duration, popularity, and external URLs.

Instructions

Get detailed information about a specific Spotify track by ID.

Retrieves comprehensive metadata for a single track including artists, album, duration,
popularity, URIs, and external URLs.

Args:
    - track_id: Spotify track ID (not URI), extract from URIs or search results
    - response_format: 'markdown' or 'json'

Returns:
    Markdown: Track details (name, artists, album, duration, ID, URI, popularity)
    JSON: Full API response (id, name, artists, album, duration_ms, popularity, uri, external_urls, preview_url, track_number, disc_number, explicit, available_markets)

Examples:
    - "Get details for track ID 4u7EnebtmKWzUH433cf5Qv" -> Retrieve track info
    - "Show me info about this track" -> When you have the track ID

Errors: Returns error for invalid track (404), auth failure (401), rate limits (429).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • The async handler function that executes the spotify_get_track tool, fetching track details from Spotify API and formatting as markdown or JSON.
    async def spotify_get_track(params: GetTrackInput) -> str:
        """Get detailed information about a specific Spotify track by ID.
    
        Retrieves comprehensive metadata for a single track including artists, album, duration,
        popularity, URIs, and external URLs.
    
        Args:
            - track_id: Spotify track ID (not URI), extract from URIs or search results
            - response_format: 'markdown' or 'json'
    
        Returns:
            Markdown: Track details (name, artists, album, duration, ID, URI, popularity)
            JSON: Full API response (id, name, artists, album, duration_ms, popularity, uri, external_urls, preview_url, track_number, disc_number, explicit, available_markets)
    
        Examples:
            - "Get details for track ID 4u7EnebtmKWzUH433cf5Qv" -> Retrieve track info
            - "Show me info about this track" -> When you have the track ID
    
        Errors: Returns error for invalid track (404), auth failure (401), rate limits (429).
        """
        try:
            data = await make_spotify_request(f"tracks/{params.track_id}")
    
            if params.response_format == ResponseFormat.MARKDOWN:
                return f"# Track Details\n\n{format_track_markdown(data)}"
            else:
                # JSON format
                return json.dumps(data, indent=2)
    
        except Exception as e:
            return handle_spotify_error(e)
  • server.py:536-545 (registration)
    MCP tool registration decorator specifying the name and annotations for spotify_get_track.
    @mcp.tool(
        name="spotify_get_track",
        annotations={
            "title": "Get Spotify Track Details",
            "readOnlyHint": True,
            "destructiveHint": False,
            "idempotentHint": True,
            "openWorldHint": True,
        },
    )
  • Pydantic BaseModel defining the input parameters for the spotify_get_track tool: track_id (required string) and response_format (markdown or json).
    class GetTrackInput(BaseModel):
        """Input model for getting track details."""
    
        model_config = ConfigDict(str_strip_whitespace=True, validate_assignment=True)
    
        track_id: str = Field(
            ..., description="Spotify track ID", min_length=1, max_length=100
        )
        response_format: ResponseFormat = Field(
            default=ResponseFormat.MARKDOWN,
            description="Output format: 'markdown' or 'json'",
        )

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

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