Skip to main content
Glama
leehave
by leehave

get_recommendations

Generate personalized music recommendations based on user preferences such as genre, mood, and desired number of tracks to discover tailored playlists.

Instructions

根据用户喜好获取音乐推荐

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
genreNo音乐风格
limitNo推荐数量
moodNo心情/氛围

Implementation Reference

  • The primary handler function for the 'get_recommendations' tool. It parses input arguments, calls the MusicDatabase's getRecommendations method, and formats the results into a text response.
    private async handleGetRecommendations(args: any) { const { genre, mood, limit = 10 } = args; const recommendations = await this.musicDb.getRecommendations(genre, mood, limit); return { content: [ { type: 'text', text: `🎯 音乐推荐${genre ? ` (${genre})` : ''}${mood ? ` - ${mood}心情` : ''}:\n\n${recommendations.map(song => `🎵 ${song.title}\n👤 ${song.artist}\n💿 ${song.album}\n⭐ ${song.rating}/5\n🆔 ${song.id}\n` ).join('\n')}`, }, ], }; }
  • Input schema definition for the 'get_recommendations' tool, specifying parameters for genre, mood, and limit.
    inputSchema: { type: 'object', properties: { genre: { type: 'string', description: '音乐风格', }, mood: { type: 'string', description: '心情/氛围', }, limit: { type: 'number', description: '推荐数量', default: 10, }, }, },
  • src/index.ts:137-158 (registration)
    Registration of the 'get_recommendations' tool in the ListTools response, including name, description, and input schema.
    { name: 'get_recommendations', description: '根据用户喜好获取音乐推荐', inputSchema: { type: 'object', properties: { genre: { type: 'string', description: '音乐风格', }, mood: { type: 'string', description: '心情/氛围', }, limit: { type: 'number', description: '推荐数量', default: 10, }, }, }, },
  • Supporting method in MusicDatabase class that implements the recommendation logic by filtering songs based on genre and mood, sorting by rating and play count, and limiting results.
    async getRecommendations(genre?: string, mood?: string, limit: number = 10): Promise<Song[]> { let filtered = [...this.songs]; if (genre) { filtered = filtered.filter(song => song.genre.toLowerCase().includes(genre.toLowerCase()) ); } // 根据心情推荐(简单的逻辑示例) if (mood) { const moodLower = mood.toLowerCase(); if (moodLower.includes('快乐') || moodLower.includes('开心')) { filtered = filtered.filter(song => song.genre === 'Pop'); } else if (moodLower.includes('安静') || moodLower.includes('放松')) { filtered = filtered.filter(song => song.rating >= 4); } } // 按评分和播放次数排序 filtered.sort((a, b) => (b.rating * b.playCount) - (a.rating * a.playCount)); return filtered.slice(0, limit); }
  • src/index.ts:181-182 (registration)
    Dispatch case in the CallToolRequest handler that routes 'get_recommendations' calls to the specific handler method.
    case 'get_recommendations': return await this.handleGetRecommendations(args);

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/leehave/Claude-Music-Mcp'

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