Skip to main content
Glama

get_access_token

Obtain a Spotify API access token to authenticate and authorize requests for interacting with Spotify's music catalog and services.

Instructions

Get a valid Spotify access token for API requests

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that implements the logic to retrieve or refresh the Spotify access token using client credentials grant type, with caching based on expiration.
    async getAccessToken(): Promise<string> { // Check if we have a valid token if (this.tokenInfo && Date.now() < this.tokenInfo.expiresAt) { return this.tokenInfo.accessToken; } // Get new token try { const response = await axios.post('https://accounts.spotify.com/api/token', new URLSearchParams({ grant_type: 'client_credentials' }).toString(), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic ' + Buffer.from(SPOTIFY_CLIENT_ID + ':' + SPOTIFY_CLIENT_SECRET).toString('base64') } } ); this.tokenInfo = { accessToken: response.data.access_token, expiresAt: Date.now() + (response.data.expires_in * 1000) }; return this.tokenInfo.accessToken; } catch (error) { if (axios.isAxiosError(error)) { throw new McpError( ErrorCode.InternalError, `Failed to get Spotify access token: ${error.response?.data?.error ?? error.message}` ); } throw error; } }
  • MCP tool dispatch handler case for 'get_access_token' that invokes AuthManager.getAccessToken() and returns the token as text content.
    case 'get_access_token': { const token = await this.authManager.getAccessToken(); return { content: [{ type: 'text', text: token }], }; }
  • src/index.ts:106-113 (registration)
    Registration of the 'get_access_token' tool in the MCP server's list of available tools, including name, description, and schema.
    { name: 'get_access_token', description: 'Get a valid Spotify access token for API requests', inputSchema: { type: 'object', properties: {}, required: [] },
  • Input schema definition for the 'get_access_token' tool, which requires no parameters (empty object).
    inputSchema: { type: 'object', properties: {}, required: []
  • Usage of getAccessToken in SpotifyApi.makeRequest as a supporting utility.
    const token = await this.authManager.getAccessToken();

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

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