get_current_track
Retrieve the currently playing track from Spotify to identify what's playing, share song details, or integrate with other music management tasks.
Instructions
Get the currently playing track
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:368-396 (handler)Handler for the 'get_current_track' tool that calls Spotify's /me/player/currently-playing API endpoint, checks if a track is playing, and returns formatted track information including name, artists, album, progress/duration, playing status, and track ID
case "get_current_track": { const data = await spotifyRequest("/me/player/currently-playing"); if (!data || !data.item) { return { content: [{ type: "text", text: "βΈοΈ No track currently playing" }], }; } const track = data.item; const artists = track.artists.map((a: any) => a.name).join(", "); const progress = Math.floor(data.progress_ms / 1000); const duration = Math.floor(track.duration_ms / 1000); return { content: [ { type: "text", text: `π΅ Currently Playing:\n\n` + `π€ ${track.name}\n` + `π€ ${artists}\n` + `πΏ ${track.album.name}\n` + `β±οΈ ${Math.floor(progress / 60)}:${(progress % 60).toString().padStart(2, "0")} / ${Math.floor(duration / 60)}:${(duration % 60).toString().padStart(2, "0")}\n` + `π ${data.is_playing ? "Playing" : "Paused"}\n` + `π ID: ${track.id}`, }, ], }; } - src/index.ts:116-123 (registration)Tool registration defining 'get_current_track' with name, description ('Get the currently playing track'), and empty inputSchema indicating no parameters required
{ name: "get_current_track", description: "Get the currently playing track", inputSchema: { type: "object", properties: {}, }, }, - src/index.ts:119-122 (schema)Input schema for 'get_current_track' tool - an empty object type with no properties, indicating this tool requires no input parameters
inputSchema: { type: "object", properties: {}, }, - src/index.ts:54-74 (helper)Helper function 'spotifyRequest' that handles authenticated requests to Spotify API, including automatic token refresh via getAccessToken() and proper error handling
async function spotifyRequest(endpoint: string, method = "GET", data?: any) { const token = await getAccessToken(); try { const response = await axios({ method, url: `https://api.spotify.com/v1${endpoint}`, headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, data, }); return response.data; } catch (error: any) { if (error.response) { throw new Error(`Spotify API Error: ${error.response.data.error?.message || error.response.statusText}`); } throw new Error(`Network Error: ${error.message}`); } }