Skip to main content
Glama

check-credentials-status

Verify the status of Spotify account credentials to ensure proper functionality for searching songs, creating playlists, adding tracks, and receiving recommendations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Inline handler function for the 'check-credentials-status' tool. Checks if credentials are set in spotifyAuthInfo, then validates by fetching /v1/me endpoint using getValidAccessToken().
    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, }; } });
  • Shared helper function used by the tool to obtain a valid access token, refreshing if necessary.
    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)) ); } }
  • Global state object holding Spotify authentication credentials, directly checked and updated by the tool handler.
    let spotifyAuthInfo = { accessToken: "", refreshToken: "", clientId: "", clientSecret: "", };
  • Tool registration call for 'check-credentials-status' with empty schema and inline handler.
    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, }; } });
  • Identical inline handler for SSE variant of the server.
    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, }; } });

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

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