Skip to main content
Glama

check-credentials-status

Verify the status of Spotify account credentials to ensure proper connectivity and authorization for managing music, playlists, and recommendations through the Spotify MCP Server.

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": {}, "type": "object" }

Implementation Reference

  • Handler for the check-credentials-status tool: checks if credentials are set and validates them by fetching the Spotify user profile using a potentially refreshed access token.
    server.tool("check-credentials-status", {}, async () => { if ( !spotifyAuthInfo.accessToken || !spotifyAuthInfo.refreshToken || !spotifyAuthInfo.clientId || !spotifyAuthInfo.clientSecret ) { return { content: [ { type: "text", text: "Spotify credentials are not set. Please use the set-spotify-credentials tool.", }, ], }; } try { const accessToken = await getValidAccessToken(); const response = await fetch("https://api.spotify.com/v1/me", { headers: { Authorization: `Bearer ${accessToken}`, }, }); if (response.ok) { const userData = (await response.json()) as any; return { content: [ { type: "text", text: `Spotify credentials are valid.\nLogged in as: ${ userData.display_name } (${userData.email || "email not available"})`, }, ], }; } else { return { content: [ { type: "text", text: `Spotify credentials may be invalid. Status code: ${response.status}`, }, ], isError: true, }; } } catch (error) { return { content: [ { type: "text", text: `Error checking credentials: ${ error instanceof Error ? error.message : String(error) }`, }, ], isError: true, }; } });
  • Helper function to obtain a valid Spotify access token, refreshing it if the current one is expired or invalid.
    async function getValidAccessToken() { if (!spotifyAuthInfo.accessToken || !spotifyAuthInfo.refreshToken) { throw new Error( "No access token available. Please set credentials first using the set-spotify-credentials tool." ); } try { // Try using current token const response = await fetch("https://api.spotify.com/v1/me", { headers: { Authorization: `Bearer ${spotifyAuthInfo.accessToken}`, }, }); // If token works, return it if (response.ok) { return spotifyAuthInfo.accessToken; } console.error("Access token expired, refreshing..."); // If token doesn't work, refresh it const refreshResponse = await fetch( "https://accounts.spotify.com/api/token", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded", Authorization: "Basic " + Buffer.from( spotifyAuthInfo.clientId + ":" + spotifyAuthInfo.clientSecret ).toString("base64"), }, body: new URLSearchParams({ grant_type: "refresh_token", refresh_token: spotifyAuthInfo.refreshToken, }), } ); const data = (await refreshResponse.json()) as any; if (data.access_token) { console.error("Successfully refreshed access token"); spotifyAuthInfo.accessToken = data.access_token; return spotifyAuthInfo.accessToken; } throw new Error("Failed to refresh access token"); } catch (error) { throw new Error( "Error with access token: " + (error instanceof Error ? error.message : String(error)) ); } }

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/hrishi0102/spotifyyy-mcp'

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