Skip to main content
Glama

add_to_playlist

Add Spotify tracks to playlists using track URIs and playlist IDs for music organization and management.

Instructions

Add tracks to a playlist

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
playlist_idYesSpotify playlist ID
track_urisYesArray of Spotify track URIs to add

Implementation Reference

  • Handler for add_to_playlist tool - makes POST request to Spotify API to add tracks to a playlist using playlist_id and track_uris parameters
    case "add_to_playlist": {
      await spotifyRequest(
        `/playlists/${args.playlist_id}/tracks`,
        "POST",
        {
          uris: args.track_uris,
        }
      );
    
      return {
        content: [
          {
            type: "text",
            text: `➕ Added ${(args.track_uris as string[]).length} track(s) to playlist!`,
          },
        ],
      };
    }
  • Schema definition for add_to_playlist tool - defines input parameters: playlist_id (string, required) and track_uris (array of strings, required)
      name: "add_to_playlist",
      description: "Add tracks to a playlist",
      inputSchema: {
        type: "object",
        properties: {
          playlist_id: {
            type: "string",
            description: "Spotify playlist ID",
          },
          track_uris: {
            type: "array",
            items: {
              type: "string",
            },
            description: "Array of Spotify track URIs to add",
          },
        },
        required: ["playlist_id", "track_uris"],
      },
    },
  • Helper function spotifyRequest that handles authentication and makes HTTP requests to Spotify API endpoints
    async function spotifyRequest(endpoint: string, method = "GET", data?: any) {
      const token = await getAccessToken();
      
      try {
        const response = await axios({
          method,
          url: `https://api.spotify.com/v1${endpoint}`,
          headers: {
            Authorization: `Bearer ${token}`,
            "Content-Type": "application/json",
          },
          data,
        });
        return response.data;
      } catch (error: any) {
        if (error.response) {
          throw new Error(`Spotify API Error: ${error.response.data.error?.message || error.response.statusText}`);
        }
        throw new Error(`Network Error: ${error.message}`);
      }
    }
  • Helper function getAccessToken that manages OAuth token refresh for Spotify API authentication
    async function getAccessToken(): Promise<string> {
      if (accessToken && Date.now() < tokenExpiresAt) {
        return accessToken;
      }
    
      try {
        const params = new URLSearchParams();
        params.append("grant_type", "refresh_token");
        params.append("refresh_token", REFRESH_TOKEN!);
    
        const response = await axios.post(
          "https://accounts.spotify.com/api/token",
          params,
          {
            headers: {
              "Content-Type": "application/x-www-form-urlencoded",
              Authorization: `Basic ${Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`).toString("base64")}`,
            },
          }
        );
    
        accessToken = response.data.access_token;
        tokenExpiresAt = Date.now() + response.data.expires_in * 1000;
        return accessToken;
      } catch (error: any) {
        throw new Error(`Failed to get access token: ${error.message}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Add tracks') but doesn't cover critical aspects like required permissions (e.g., user authorization), rate limits, whether the operation is idempotent, or what happens on failure (e.g., partial adds). This leaves significant gaps for safe and effective use.

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 fluff or redundancy. It's front-loaded with the core action, making it easy to parse quickly, which is ideal for conciseness.

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 a write operation (adding tracks to a playlist) with no annotations and no output schema, the description is insufficient. It lacks details on behavioral traits (e.g., error handling, side effects), usage context, and expected outcomes, making it incomplete for reliable agent invocation.

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?

Schema description coverage is 100%, with both parameters ('playlist_id' and 'track_uris') clearly documented in the schema. The description adds no additional semantic context beyond implying the parameters are used for adding tracks, so it meets the baseline of 3 without compensating for any schema gaps.

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 ('Add tracks') and the target resource ('to a playlist'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'like_track' or 'play_track' which also involve track manipulation, leaving room for confusion about when to use each.

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 a playlist ID from 'create_playlist'), exclusions (e.g., not for removing tracks), or comparisons to siblings like 'like_track' for favoriting versus adding to playlists.

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/MadhurToshniwal/Spotify-MCP-Server'

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