Skip to main content
Glama
fborello

MCP Spotify Server

by fborello

spotify_add_tracks_to_playlist

Add tracks to an existing Spotify playlist by providing the playlist ID and track IDs. This tool enables playlist management through the MCP Spotify Server.

Instructions

Adiciona músicas a uma playlist existente

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYesID da playlist no Spotify
track_idsYesArray com os IDs das músicas para adicionar

Implementation Reference

  • The handler function that executes the tool logic: adds specified tracks to a Spotify playlist using a direct POST request to the Spotify API.
    async addTracksToPlaylist(playlistId: string, trackIds: string[]) {
      try {
        await this.spotifyAuth.ensureValidToken();
        const accessToken = await this.spotifyAuth.ensureValidToken();
    
        // Adicionar músicas à playlist
        const response = await fetch(`https://api.spotify.com/v1/playlists/${playlistId}/tracks`, {
          method: 'POST',
          headers: {
            'Authorization': `Bearer ${accessToken}`,
            'Content-Type': 'application/json'
          },
          body: JSON.stringify({
            uris: trackIds.map(id => `spotify:track:${id}`)
          })
        });
    
        if (!response.ok) {
          const errorData = await response.json();
          throw new Error(`Erro ao adicionar músicas: ${response.status} - ${errorData.error?.message || 'Erro desconhecido'}`);
        }
    
        const result = await response.json();
    
        return {
          content: [
            {
              type: 'text',
              text: `✅ ${trackIds.length} música(s) adicionada(s) à playlist com sucesso!\n\n**Detalhes:**\n- Playlist ID: ${playlistId}\n- Músicas adicionadas: ${trackIds.length}\n- Snapshot ID: ${result.snapshot_id}`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `❌ Erro ao adicionar músicas à playlist: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        };
      }
    }
  • Input schema definition for the tool, specifying playlist_id (string) and track_ids (array of strings) as required parameters.
    {
      name: 'spotify_add_tracks_to_playlist',
      description: 'Adiciona músicas a uma playlist existente',
      inputSchema: {
        type: 'object',
        properties: {
          playlist_id: {
            type: 'string',
            description: 'ID da playlist no Spotify',
          },
          track_ids: {
            type: 'array',
            items: {
              type: 'string',
            },
            description: 'Array com os IDs das músicas para adicionar',
          },
        },
        required: ['playlist_id', 'track_ids'],
      },
    },
  • src/index.ts:301-303 (registration)
    Registers the tool handler in the CallToolRequest switch statement, mapping the tool name to the SpotifyTools.addTracksToPlaylist method.
    case 'spotify_add_tracks_to_playlist':
      return await spotifyTools.addTracksToPlaylist(args.playlist_id, args.track_ids);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'adiciona' implies a write/mutation operation, the description doesn't disclose important behavioral traits: whether authentication is required, rate limits, what happens if tracks already exist in the playlist, error conditions, or what the response looks like. It provides only the basic action without operational context.

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 - a single Portuguese sentence that directly states the tool's purpose. There's zero waste or redundancy, and it's front-loaded with the essential information. Every word earns its place.

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 a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't address authentication requirements (critical given the sibling 'spotify_auth' tool), doesn't explain what happens on success/failure, and provides no context about the Spotify API's behavior. The description should do more to compensate for the lack of structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already documents both parameters thoroughly. The description doesn't add any meaningful semantic context beyond what's in the schema - it doesn't explain format requirements, constraints, or provide examples. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 action ('Adiciona' - adds) and target resource ('músicas a uma playlist existente' - tracks to an existing playlist), providing a specific verb+resource combination. However, it doesn't distinguish this tool from potential alternatives like 'spotify_create_playlist' which might also add tracks during creation, or clarify if this is the only way to add tracks versus other methods.

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 (like authentication), doesn't specify when to use this versus 'spotify_create_playlist' for new playlists, and offers no context about limitations or best practices for adding tracks.

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/fborello/MCPSpotify'

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