Skip to main content
Glama
leehave
by leehave

search_music

Find music by searching for songs, artists, or albums using keywords. Streamline music discovery with customizable search filters and result limits.

Instructions

搜索音乐,支持按歌曲名、艺术家、专辑搜索

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo返回结果数量限制
queryYes搜索关键词
typeNo搜索类型all

Implementation Reference

  • The main handler function for the 'search_music' tool. It destructures the input arguments, performs the search using MusicDatabase, and formats the results into a text response for the MCP protocol.
    private async handleSearchMusic(args: any) { const { query, type = 'all', limit = 10 } = args; const results = await this.musicDb.search(query, type, limit); return { content: [ { type: 'text', text: `搜索结果 "${query}":\n\n${results.map(song => `🎵 ${song.title}\n👤 艺术家: ${song.artist}\n💿 专辑: ${song.album}\n⏱️ 时长: ${song.duration}\n🆔 ID: ${song.id}\n` ).join('\n')}`, }, ], }; }
  • The input schema definition for the 'search_music' tool, specifying parameters like query (required), type, and limit.
    inputSchema: { type: 'object', properties: { query: { type: 'string', description: '搜索关键词', }, type: { type: 'string', enum: ['song', 'artist', 'album', 'all'], description: '搜索类型', default: 'all', }, limit: { type: 'number', description: '返回结果数量限制', default: 10, }, }, required: ['query'], },
  • src/index.ts:40-64 (registration)
    Registration of the 'search_music' tool in the ListTools response, including name, description, and input schema.
    { name: 'search_music', description: '搜索音乐,支持按歌曲名、艺术家、专辑搜索', inputSchema: { type: 'object', properties: { query: { type: 'string', description: '搜索关键词', }, type: { type: 'string', enum: ['song', 'artist', 'album', 'all'], description: '搜索类型', default: 'all', }, limit: { type: 'number', description: '返回结果数量限制', default: 10, }, }, required: ['query'], }, },
  • Supporting utility method in MusicDatabase that implements the core search logic by filtering an in-memory array of songs based on query, type, and limit.
    async search(query: string, type: string = 'all', limit: number = 10): Promise<Song[]> { const lowerQuery = query.toLowerCase(); let filtered = this.songs.filter(song => { switch (type) { case 'song': return song.title.toLowerCase().includes(lowerQuery); case 'artist': return song.artist.toLowerCase().includes(lowerQuery); case 'album': return song.album.toLowerCase().includes(lowerQuery); case 'all': default: return ( song.title.toLowerCase().includes(lowerQuery) || song.artist.toLowerCase().includes(lowerQuery) || song.album.toLowerCase().includes(lowerQuery) ); } }); return filtered.slice(0, limit); }
  • Type definition for Song objects used in search results.
    export interface Song { id: string; title: string; artist: string; album: string; year: number; duration: string; genre: string; playCount: number; rating: number; }

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