Skip to main content
Glama

search

Find tracks, albums, artists, or playlists in Spotify's music catalog using specific search queries and filters.

Instructions

Search for tracks, albums, artists, or playlists

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
typeYesType of item to search for
limitNoMaximum number of results (1-50)

Implementation Reference

  • The SearchHandler class provides the core implementation of the 'search' tool, handling input validation and making an API request to Spotify's search endpoint.
    export class SearchHandler { constructor(private api: SpotifyApi) {} async search(args: SearchArgs) { const { query, type, limit = 20 } = args; if (limit < 1 || limit > 50) { throw new McpError( ErrorCode.InvalidParams, 'Limit must be between 1 and 50' ); } const params = { q: encodeURIComponent(query), type, limit }; return this.api.makeRequest(`/search${this.api.buildQueryString(params)}`); } }
  • TypeScript interfaces defining the input (SearchArgs) and output (SearchResponse) structures for the 'search' tool.
    export interface SearchArgs { query: string; type: 'track' | 'album' | 'artist' | 'playlist'; limit?: number; } export interface SearchResponse { tracks?: { items: any[]; limit: number; next: string | null; offset: number; previous: string | null; total: number; }; albums?: { items: any[]; limit: number; next: string | null; offset: number; previous: string | null; total: number; }; artists?: { items: any[]; limit: number; next: string | null; offset: number; previous: string | null; total: number; }; playlists?: { items: any[]; limit: number; next: string | null; offset: number; previous: string | null; total: number; }; }
  • src/index.ts:116-140 (registration)
    Registration of the 'search' tool in the ListTools response, including name, description, and input schema.
    name: 'search', description: 'Search for tracks, albums, artists, or playlists', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query' }, type: { type: 'string', description: 'Type of item to search for', enum: ['track', 'album', 'artist', 'playlist'] }, limit: { type: 'number', description: 'Maximum number of results (1-50)', minimum: 1, maximum: 50, default: 20 } }, required: ['query', 'type'] }, },
  • src/index.ts:702-708 (registration)
    Handler for CallTool requests named 'search', which validates arguments and delegates to SearchHandler.search().
    case 'search': { const args = this.validateArgs<SearchArgsType>(request.params.arguments, ['query', 'type']); const result = await this.searchHandler.search(args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
  • src/index.ts:87-87 (registration)
    Instantiation of the SearchHandler instance used by the MCP server.
    this.searchHandler = new SearchHandler(this.api);

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/superseoworld/mcp-spotify'

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