Skip to main content
Glama
makesh-kumar

Spotify MCP Server

by makesh-kumar

searchSpotify

Search for tracks, albums, artists, or playlists on Spotify to find specific music content using queries and filters.

Instructions

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

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query
typeYesThe type of item to search for either track, album, artist, or playlist
limitNoMaximum number of results to return (10-50)

Implementation Reference

  • The handler function for the searchSpotify tool. Performs Spotify API search based on query, type (track/album/artist/playlist), and limit. Formats and returns results as markdown text or handles errors.
    handler: async (args, _extra: SpotifyHandlerExtra) => {
      const { query, type, limit } = args;
      const limitValue = limit ?? 10;
    
      try {
        const results = await handleSpotifyRequest(async (spotifyApi) => {
          return await spotifyApi.search(
            query,
            [type],
            undefined,
            limitValue as MaxInt<50>,
          );
        });
    
        let formattedResults = '';
    
        if (type === 'track' && results.tracks) {
          formattedResults = results.tracks.items
            .map((track, i) => {
              const artists = track.artists.map((a) => a.name).join(', ');
              const duration = formatDuration(track.duration_ms);
              return `${i + 1}. "${
                track.name
              }" by ${artists} (${duration}) - ID: ${track.id}`;
            })
            .join('\n');
        } else if (type === 'album' && results.albums) {
          formattedResults = results.albums.items
            .map((album, i) => {
              const artists = album.artists.map((a) => a.name).join(', ');
              return `${i + 1}. "${album.name}" by ${artists} - ID: ${album.id}`;
            })
            .join('\n');
        } else if (type === 'artist' && results.artists) {
          formattedResults = results.artists.items
            .map((artist, i) => {
              return `${i + 1}. ${artist.name} - ID: ${artist.id}`;
            })
            .join('\n');
        } else if (type === 'playlist' && results.playlists) {
          formattedResults = results.playlists.items
            .map((playlist, i) => {
              return `${i + 1}. "${playlist?.name ?? 'Unknown Playlist'} (${
                playlist?.description ?? 'No description'
              } tracks)" by ${playlist?.owner?.display_name} - ID: ${
                playlist?.id
              }`;
            })
            .join('\n');
        }
    
        return {
          content: [
            {
              type: 'text',
              text:
                formattedResults.length > 0
                  ? `# Search results for "${query}" (type: ${type})\n\n${formattedResults}`
                  : `No ${type} results found for "${query}"`,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `Error searching for ${type}s: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    },
  • Name, description, and Zod input schema definition for the searchSpotify tool.
    name: 'searchSpotify',
    description: 'Search for tracks, albums, artists, or playlists on Spotify',
    schema: {
      query: z.string().describe('The search query'),
      type: z
        .enum(['track', 'album', 'artist', 'playlist'])
        .describe(
          'The type of item to search for either track, album, artist, or playlist',
        ),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .describe('Maximum number of results to return (10-50)'),
    },
  • src/read.ts:531-539 (registration)
    The searchSpotify tool is registered in the readTools array alongside other read operations.
    export const readTools = [
      searchSpotify,
      getNowPlaying,
      getMyPlaylists,
      getPlaylistTracks,
      getRecentlyPlayed,
      getUsersSavedTracks,
      getQueue,
    ];
  • src/index.ts:12-14 (registration)
    The MCP server registers all tools (including searchSpotify via readTools) by calling server.tool for each.
    [...readTools, ...playTools, ...albumTools].forEach((tool) => {
      server.tool(tool.name, tool.description, tool.schema, tool.handler);
    });
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the search functionality but does not cover critical aspects like authentication requirements, rate limits, pagination, error handling, or the format of search results. For a tool with no annotation coverage, this leaves significant gaps in understanding its operational behavior.

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 any unnecessary words. It is front-loaded with the core action ('Search') and resource, making it highly concise and well-structured for quick comprehension.

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, and no annotations), the description is incomplete. It lacks details on authentication, result formatting, error handling, and usage context relative to siblings. Without annotations or an output schema, the description should provide more behavioral and operational context to be fully helpful for an AI agent.

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 searching for 'tracks, albums, artists, or playlists', which aligns with the 'type' parameter's enum values, adding some context. However, with 100% schema description coverage, the input schema already fully documents all parameters (query, type, limit), so the description does not add substantial meaning beyond what the schema provides. The baseline score of 3 reflects adequate but minimal additional value.

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 ('Search') and resource ('tracks, albums, artists, or playlists on Spotify'), making it immediately understandable. However, it does not explicitly distinguish this search function from potential sibling tools like 'getAlbums' or 'getMyPlaylists', which might also retrieve similar 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 does not mention any prerequisites, exclusions, or comparisons to sibling tools such as 'getAlbums' (which might fetch specific albums without search) or 'getMyPlaylists' (which retrieves user-specific playlists). Usage is implied but not explicitly defined.

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/makesh-kumar/spotify-mcp-server'

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