search_music
Search for music by song title, artist name, or album title to find specific tracks or discover new music within the Claude Music MCP server.
Instructions
搜索音乐,支持按歌曲名、艺术家、专辑搜索
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 搜索关键词 | |
| type | No | 搜索类型 | all |
| limit | No | 返回结果数量限制 |
Implementation Reference
- src/index.ts:199-213 (handler)The handler function that implements the core logic of the 'search_music' tool: parses input arguments, performs the search using MusicDatabase, and returns formatted results in MCP content format.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')}`, }, ], }; }
- src/index.ts:43-63 (schema)JSON schema defining the input parameters for the 'search_music' tool: query (required), type (song/artist/album/all), 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 ListToolsRequestHandler response, providing 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'], }, },
- src/index.ts:168-170 (registration)Dispatch case in CallToolRequestHandler that routes 'search_music' calls to the specific handler.switch (name) { case 'search_music': return await this.handleSearchMusic(args);
- src/music-database.ts:72-94 (helper)Supporting search method in MusicDatabase class that performs the actual filtering of songs based on query, type, and limit from the hardcoded database.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); }