Skip to main content
Glama

auth-spotify

Authenticate with Spotify to enable Claude Desktop integration, allowing for music playback control, playlist management, and recommendations via natural language commands.

Instructions

Authenticate with Spotify

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • index.ts:631-638 (registration)
    Registration of the 'auth-spotify' tool in the ListTools handler, including its schema with no input parameters.
    {
      name: "auth-spotify",
      description: "Authenticate with Spotify",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • Input schema for 'auth-spotify' tool: empty object (no parameters required).
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
  • Core handler logic for executing the 'auth-spotify' tool: manages OAuth2 flow with Spotify, token storage, and validation.
    if (name === "auth-spotify") {
      try {
        console.error(`Checking current authentication status...`);
        try {
          if (accessToken) {
            console.error(`We have an access token in memory, testing it...`);
            try {
              const testResponse = await axios({
                method: 'GET',
                url: `${SPOTIFY_API_BASE}/me`,
                headers: {
                  Authorization: `Bearer ${accessToken}`,
                  "Content-Type": "application/json",
                },
              });
              
              console.error(`Current token is valid! Already authenticated as: ${testResponse.data.display_name}`);
              return {
                content: [
                  {
                    type: "text",
                    text: `Already authenticated with Spotify as ${testResponse.data.display_name}!`,
                  },
                ],
              };
            } catch (testError) {
              console.error(`Current token is invalid, proceeding with authentication flow`);
            }
          } else {
            console.error(`No access token in memory, checking token file...`);
            
            try {
              if (fs.existsSync(TOKEN_PATH)) {
                console.error(`Token file exists, attempting to load...`);
                const fileContent = fs.readFileSync(TOKEN_PATH, 'utf8');
                
                if (fileContent && fileContent.trim() !== '') {
                  console.error(`Found token file with content, parsing...`);
                  const tokenData = JSON.parse(fileContent);
                  accessToken = tokenData.accessToken;
                  refreshToken = tokenData.refreshToken;
                  tokenExpirationTime = tokenData.tokenExpirationTime;
                  
                  try {
                    console.error(`Testing loaded token...`);
                    const testResponse = await axios({
                      method: 'GET',
                      url: `${SPOTIFY_API_BASE}/me`,
                      headers: {
                        Authorization: `Bearer ${accessToken}`,
                        "Content-Type": "application/json",
                      },
                    });
                    
                    console.error(`Loaded token is valid! Authenticated as: ${testResponse.data.display_name}`);
                    return {
                      content: [
                        {
                          type: "text",
                          text: `Already authenticated with Spotify as ${testResponse.data.display_name}!`,
                        },
                      ],
                    };
                  } catch (loadedTokenError) {
                    console.error(`Loaded token is invalid, continuing with auth flow...`);
                  }
                }
              }
            } catch (fileError) {
              console.error(`Error handling token file: ${fileError}`);
            }
          }
        } catch (testError) {
          console.error(`Error testing current authentication: ${testError}`);
        }
    
        console.error('Starting authentication process...');
        await startAuthServer();
        
        if (!accessToken || !refreshToken) {
          throw new Error("Authentication failed: No tokens received");
        }
        
        console.error(`Authentication successful, received tokens`);
        
        try {
          console.error(`Testing new tokens...`);
          const testResponse = await axios({
            method: 'GET',
            url: `${SPOTIFY_API_BASE}/me`,
            headers: {
              Authorization: `Bearer ${accessToken}`,
              "Content-Type": "application/json",
            },
          });
          
          console.error(`New tokens are valid! Authenticated as: ${testResponse.data.display_name}`);
          return {
            content: [
              {
                type: "text",
                text: `Successfully authenticated with Spotify as ${testResponse.data.display_name}!`,
              },
            ],
          };
        } catch (newTokenError) {
          console.error(`New tokens failed verification: ${newTokenError}`);
          throw new Error("Authentication succeeded but tokens are invalid");
        }
        
      } catch (error: any) {
        if (error instanceof ServerAlreadyRunningError) {
          console.error(`Server already running error: ${error.message}`);
          
          try {
            if (accessToken) {
              const testResponse = await axios({
                method: 'GET',
                url: `${SPOTIFY_API_BASE}/me`,
                headers: {
                  Authorization: `Bearer ${accessToken}`,
                  "Content-Type": "application/json",
                },
              });
              
              return {
                content: [
                  {
                    type: "text",
                    text: `Successfully authenticated with Spotify as ${testResponse.data.display_name}!`,
                  },
                ],
              };
            }
          } catch (testError) {
          }
          
          return {
            content: [
              {
                type: "text",
                text: `Another instance is already running on port ${error.port}. If you're having authentication issues, please restart Claude or close any other applications using port ${error.port}.`,
              },
            ],
          };
        }
        
        console.error(`Authentication error: ${error.message}`);
        return {
          content: [
            {
              type: "text",
              text: `Authentication failed: ${error.message}`,
            },
          ],
        };
      }
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. 'Authenticate with Spotify' implies a state-changing operation (likely obtaining or refreshing tokens), but it doesn't disclose behavioral traits like whether it's interactive, requires user input, stores credentials, has side effects, or handles errors. This leaves critical gaps for an agent to understand how to invoke it safely.

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 extremely concise with just three words, front-loading the core action ('Authenticate') and target ('Spotify'). There's zero waste or redundancy, 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 the complexity of authentication (often involving tokens, scopes, or user interaction), no annotations, no output schema, and sibling tools that likely depend on auth, the description is incomplete. It doesn't explain what authentication entails, what it returns, or how it integrates with other tools, leaving significant gaps for an agent.

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 doesn't add parameter details, which is appropriate here. A baseline of 4 is given since the schema fully covers the absence of parameters, and the description doesn't need to compensate.

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

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Authenticate with Spotify' states the general purpose (authentication) and target service (Spotify), but it's vague about what authentication means in this context. It doesn't specify whether this initiates OAuth flow, validates existing tokens, or manages credentials, nor does it distinguish from other authentication-related operations that might exist.

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., needing authentication before using other Spotify tools), timing considerations, or whether it's required for sibling tools like 'add-tracks-to-playlist' or 'search-spotify'. Without this, an agent might misuse it.

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