Skip to main content
Glama

search-spotify

Search Spotify for tracks, albums, artists, or playlists by specifying a query and item type. Retrieve up to 50 results, ideal for finding music content quickly.

Instructions

Search for tracks, albums, artists, or playlists on Spotify

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of results to return (1-50, default: 10)
queryYesSearch query
typeNoType of item to search for (default: track)

Implementation Reference

  • Handler for 'search-spotify' tool: validates input with SearchSchema, calls Spotify /search API, formats and returns search results for tracks, albums, artists, or playlists.
          if (name === "search-spotify") {
            const { query, type, limit } = SearchSchema.parse(args);
            
            const results = await spotifyApiRequest(
              `/search?${querystring.stringify({
                q: query,
                type,
                limit,
              })}`
            );
            
            let formattedResults = "";
            
            if (type === "track" && results.tracks) {
              formattedResults = results.tracks.items
                .map(
                  (track: any) => `
    Track: ${track.name}
    Artist: ${track.artists.map((a: any) => a.name).join(", ")}
    Album: ${track.album.name}
    ID: ${track.id}
    Duration: ${Math.floor(track.duration_ms / 1000 / 60)}:${(
                    Math.floor(track.duration_ms / 1000) % 60
                  )
                    .toString()
                    .padStart(2, "0")}
    URL: ${track.external_urls.spotify}
    ---`
                )
                .join("\n");
            } else if (type === "album" && results.albums) {
              formattedResults = results.albums.items
                .map(
                  (album: any) => `
    Album: ${album.name}
    Artist: ${album.artists.map((a: any) => a.name).join(", ")}
    ID: ${album.id}
    Release Date: ${album.release_date}
    Tracks: ${album.total_tracks}
    URL: ${album.external_urls.spotify}
    ---`
                )
                .join("\n");
            } else if (type === "artist" && results.artists) {
              formattedResults = results.artists.items
                .map(
                  (artist: any) => `
    Artist: ${artist.name}
    ID: ${artist.id}
    Popularity: ${artist.popularity}/100
    Followers: ${artist.followers?.total || "N/A"}
    Genres: ${artist.genres?.join(", ") || "None"}
    URL: ${artist.external_urls.spotify}
    ---`
                )
                .join("\n");
            } else if (type === "playlist" && results.playlists) {
              formattedResults = results.playlists.items
                .map(
                  (playlist: any) => `
    Playlist: ${playlist.name}
    Creator: ${playlist.owner.display_name}
    ID: ${playlist.id}
    Tracks: ${playlist.tracks.total}
    Description: ${playlist.description || "None"}
    URL: ${playlist.external_urls.spotify}
    ---`
                )
                .join("\n");
            }
            
            return {
              content: [
                {
                  type: "text",
                  text:
                    formattedResults ||
                    `No ${type}s found matching your search.`,
                },
              ],
            };
  • Zod schema for validating input parameters of search-spotify tool: query (required), type (default track), limit (1-50, default 10). Used in handler.
    const SearchSchema = z.object({
      query: z.string(),
      type: z.enum(["track", "album", "artist", "playlist"]).default("track"),
      limit: z.number().min(1).max(50).default(10),
    });
  • index.ts:639-661 (registration)
    Tool registration in ListTools response: defines name, description, and MCP inputSchema matching the zod SearchSchema.
    {
      name: "search-spotify",
      description: "Search for tracks, albums, artists, or playlists on Spotify",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query",
          },
          type: {
            type: "string",
            enum: ["track", "album", "artist", "playlist"],
            description: "Type of item to search for (default: track)",
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return (1-50, default: 10)",
          },
        },
        required: ["query"],
      },
    },
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 but offers minimal information. It doesn't describe rate limits, authentication requirements (implied by sibling 'auth-spotify'), response format, or error handling. The description is functional but lacks critical operational context 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 function without unnecessary words. It is front-loaded with the core purpose and appropriately sized for its informational content, 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 tool's moderate complexity (3 parameters, no output schema, no annotations), the description is insufficiently complete. It omits essential details like authentication needs, rate limits, response structure, and how results are ordered or filtered. Without annotations or output schema, the description should provide more operational context to guide effective use.

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?

The description mentions the searchable item types ('tracks, albums, artists, or playlists'), which aligns with the 'type' parameter enum, but adds no additional semantic context beyond what the schema provides. With 100% schema description coverage, the baseline is 3, as the schema already documents parameters like 'limit' and 'query' effectively.

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 ('Search for') and the resources ('tracks, albums, artists, or playlists on Spotify'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-recommendations' or 'get-top-tracks', which also retrieve music content but through different mechanisms.

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., authentication via 'auth-spotify'), contrast with similar tools like 'get-recommendations' (which suggests music based on preferences), or specify scenarios where search is appropriate over other retrieval methods.

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