spotify_get_track
Retrieve detailed metadata for any Spotify track using its ID, including artist information, album details, duration, popularity metrics, and external URLs for comprehensive track analysis.
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
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Input Schema (JSON Schema)
{
"properties": {
"params": {
"$ref": "#/$defs/GetTrackInput"
}
},
"required": [
"params"
],
"type": "object"
}
Implementation Reference
- server.py:536-545 (registration)Registers the 'spotify_get_track' tool with the MCP server using the @mcp.tool decorator, including metadata annotations.@mcp.tool( name="spotify_get_track", annotations={ "title": "Get Spotify Track Details", "readOnlyHint": True, "destructiveHint": False, "idempotentHint": True, "openWorldHint": True, }, )
- server.py:546-577 (handler)The main asynchronous handler function that executes the tool: fetches track data from Spotify API endpoint `/tracks/{track_id}`, formats output as markdown using `format_track_markdown` or JSON, and handles errors.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)
- spotify_mcp/types.py:192-203 (schema)Pydantic BaseModel defining the input parameters for the tool: required `track_id` (Spotify track ID, 1-100 chars) and optional `response_format` (default 'markdown').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'", )