Skip to main content
Glama
superseoworld

MCP Spotify Server

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();
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this generates a new token, reuses cached tokens, requires specific permissions, has rate limits, expiration handling, or error conditions.

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 purpose without any unnecessary words. It's perfectly front-loaded with the essential information.

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?

For an authentication tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the token looks like, how long it's valid, whether it requires prior authentication setup, or what happens on failure. Given the complexity of authentication flows, more context is needed.

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 tool has zero parameters with 100% schema coverage, so no parameter documentation is needed. The description appropriately doesn't discuss parameters, focusing instead on the tool's purpose.

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 ('Spotify access token'), and specifies its use case ('for API requests'). It doesn't distinguish from siblings, but all siblings are content retrieval/manipulation tools, making this token acquisition tool naturally distinct.

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

Usage Guidelines3/5

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

The description implies usage context ('for API requests'), suggesting this tool should be used when authentication is needed for other API operations. However, it doesn't explicitly state when to use it versus alternatives or provide prerequisites like required credentials.

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

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