Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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: {},
      },
    },
  • 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: {},
    },
  • 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}`);
      }
    }

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/MadhurToshniwal/Spotify-MCP-Server'

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