Skip to main content
Glama

get-current-playback

Retrieve details on the user's current Spotify playback state, including track, artist, and progress, for integration with MCP Claude Spotify commands.

Instructions

Get information about the user's current playback state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler implementation for the get-current-playback tool. Fetches current playback state from Spotify API endpoint /me/player, formats the response with track info, progress, device details, shuffle and repeat status.
          if (name === "get-current-playback") {
            const playback = await spotifyApiRequest("/me/player");
            
            if (!playback) {
              return {
                content: [
                  {
                    type: "text",
                    text: "No active playback found. Make sure you have an active Spotify session.",
                  },
                ],
              };
            }
            
            let responseText = "";
            
            if (playback.item) {
              responseText = `
    Currently ${playback.is_playing ? "Playing" : "Paused"}:
    Track: ${playback.item.name}
    Artist: ${playback.item.artists.map((a: any) => a.name).join(", ")}
    Album: ${playback.item.album.name}
    Progress: ${Math.floor(playback.progress_ms / 1000 / 60)}:${(
                Math.floor(playback.progress_ms / 1000) % 60
              )
                .toString()
                .padStart(2, "0")} / ${Math.floor(
                playback.item.duration_ms / 1000 / 60
              )}:${(Math.floor(playback.item.duration_ms / 1000) % 60)
                .toString()
                .padStart(2, "0")}
    Device: ${playback.device.name}
    Volume: ${playback.device.volume_percent}%
    Shuffle: ${playback.shuffle_state ? "On" : "Off"}
    Repeat: ${
                playback.repeat_state === "off"
                  ? "Off"
                  : playback.repeat_state === "context"
                  ? "Context"
                  : "Track"
              }`;
            } else {
              responseText = `
    No track currently playing.
    Device: ${playback.device.name}
    Volume: ${playback.device.volume_percent}%
    Shuffle: ${playback.shuffle_state ? "On" : "Off"}
    Repeat: ${
                playback.repeat_state === "off"
                  ? "Off"
                  : playback.repeat_state === "context"
                  ? "Context"
                  : "Track"
              }`;
            }
            
            return {
              content: [
                {
                  type: "text",
                  text: responseText,
                },
              ],
            };
          }
  • index.ts:663-669 (registration)
    Tool registration in the ListTools response, including name, description, and empty input schema.
      name: "get-current-playback",
      description: "Get information about the user's current playback state",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • Input schema definition for the tool (empty object, no parameters required).
    inputSchema: {
      type: "object",
      properties: {},
    },
  • Helper function spotifyApiRequest used by the handler to make authenticated requests to Spotify API, including token refresh logic.
    async function spotifyApiRequest(endpoint: string, method: string = "GET", data: any = null) {
      console.error(`Starting API request to ${endpoint}`);
    
      if (!accessToken || !refreshToken) {
        console.error(`No tokens in memory, trying to load from file...`);
        try {
          if (fs.existsSync(TOKEN_PATH)) {
            const fileContent = fs.readFileSync(TOKEN_PATH, 'utf8');
            console.error(`Read ${fileContent.length} bytes from token file`);
            
            if (fileContent.trim() !== '') {
              const tokenData = JSON.parse(fileContent);
              accessToken = tokenData.accessToken;
              refreshToken = tokenData.refreshToken;
              tokenExpirationTime = tokenData.tokenExpirationTime;
              console.error(`Tokens loaded successfully`);
            } else {
              console.error(`Token file is empty, cannot load tokens`);
            }
          } else {
            console.error(`Token file does not exist: ${TOKEN_PATH}`);
          }
        } catch (err) {
          console.error(`Error loading tokens from file: ${err}`);
        }
      }
    
      if (!accessToken) {
        console.error(`No access token available for request to ${endpoint}`);
        throw new Error("Not authenticated. Please authorize the app first.");
      }
    
      const now = Date.now();
      if (now >= tokenExpirationTime - 60000) {
        if (refreshToken) {
          try {
            console.error(`Token expired, attempting to refresh...`);
            const response = await axios.post(
              `${SPOTIFY_AUTH_BASE}/api/token`,
              querystring.stringify({
                grant_type: "refresh_token",
                refresh_token: refreshToken,
              }),
              {
                headers: {
                  "Content-Type": "application/x-www-form-urlencoded",
                  Authorization: `Basic ${Buffer.from(
                    `${CLIENT_ID}:${CLIENT_SECRET}`
                  ).toString("base64")}`,
                },
              }
            );
            
            accessToken = response.data.access_token;
            tokenExpirationTime = now + response.data.expires_in * 1000;
            
            if (response.data.refresh_token) {
              refreshToken = response.data.refresh_token;
            }
            
            console.error(`Token refreshed successfully, expires at ${new Date(tokenExpirationTime).toISOString()}`);
            
            try {
              if (!fs.existsSync(TOKEN_DIR)) {
                fs.mkdirSync(TOKEN_DIR, { recursive: true });
              }
              
              const tokenData = JSON.stringify({
                accessToken,
                refreshToken,
                tokenExpirationTime
              }, null, 2);
              
              fs.writeFileSync(TOKEN_PATH, tokenData);
              console.error(`Refreshed tokens saved to file`);
            } catch (saveError) {
              console.error(`Failed to save refreshed tokens: ${saveError}`);
            }
          } catch (refreshError) {
            console.error(`Failed to refresh token: ${refreshError}`);
            accessToken = null;
            refreshToken = null;
            tokenExpirationTime = 0;
            throw new Error("Authentication expired. Please authenticate again.");
          }
        } else {
          console.error(`Token expired but no refresh token available`);
          accessToken = null;
          tokenExpirationTime = 0;
          throw new Error("Authentication expired. Please authenticate again.");
        }
      }
      
      console.error(`Making authenticated request to ${endpoint}`);
      
      try {
        const response = await axios({
          method,
          url: `${SPOTIFY_API_BASE}${endpoint}`,
          headers: {
            Authorization: `Bearer ${accessToken}`,
            "Content-Type": "application/json",
          },
          data: data ? data : undefined,
        });
        
        console.error(`Request to ${endpoint} succeeded`);
        return response.data;
      } catch (error: any) {
        console.error(`Spotify API error: ${error.message}`);
        if (error.response) {
          console.error(`Status: ${error.response.status}`);
          console.error(`Data:`, error.response.data);
          
          if (error.response.status === 401) {
            console.error(`Token appears to be invalid, clearing tokens`);
            accessToken = null;
            refreshToken = null;
            tokenExpirationTime = 0;
            throw new Error("Authorization expired. Please authenticate again.");
          }
        }
        throw new Error(`Spotify API error: ${error.message}`);
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states it retrieves information (implying read-only), but doesn't specify what data is returned (e.g., track details, device info, playback status), potential errors (e.g., no active playback), or authentication requirements (implied by 'user's' but not explicit). This is inadequate for a tool with zero annotation coverage.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It's front-loaded with the core purpose, making it easy to parse quickly.

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

Completeness2/5

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

Given no annotations and no output schema, the description is incomplete. It doesn't explain what 'information' is returned (e.g., JSON structure, fields like track name or progress), behavioral aspects like error handling, or how it integrates with sibling tools. For a tool that likely returns complex playback state data, this leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description appropriately doesn't discuss parameters, earning a baseline high score since it doesn't need to compensate for gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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 ('information about the user's current playback state'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'pause-playback' or 'play-track', which are related to playback control rather than state retrieval.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., requires active playback), exclusions, or how it differs from other playback-related tools in the sibling list, leaving the agent to infer usage context.

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

Related 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/imprvhub/mcp-claude-spotify'

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