search_music
Search for music tracks by keyword using the MCP QQ Music Test Server. Find songs and retrieve song information with pagination controls.
Instructions
Search for music tracks
Args: keyword: Search keyword or phrase page: Page number for pagination (default: 1) num: Maximum number of results to return (default: 20)
Returns: List of music tracks matching the search criteria
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | ||
| page | No | ||
| num | No |
Implementation Reference
- main.py:9-41 (handler)The handler function for the 'search_music' tool. It is decorated with @mcp.tool() which registers it with the MCP server. The function searches for music tracks using the qqmusic_api, processes the results to extract relevant song information, and returns a list of song details.@mcp.tool() async def search_music(keyword: str, page: int = 1, num: int = 20): """ Search for music tracks Args: keyword: Search keyword or phrase page: Page number for pagination (default: 1) num: Maximum number of results to return (default: 20) Returns: List of music tracks matching the search criteria """ result = await search.search_by_type(keyword=keyword, page=page, num=num) # 提取指定字段 # json.dumps(result, ensure_ascii=False) - 这行代码没有实际作用,因为结果没有被使用 if isinstance(result, list): filtered_list = [] for item in result: # 提取歌曲信息而不是专辑信息 song_info = { "id": item.get("id"), "mid": item.get("mid"), "name": item.get("name"), "pmid": item.get("pmid", ""), "subtitle": item.get("subtitle", ""), "time_public": item.get("time_public", ""), "title": item.get("title", item.get("name", "")) } filtered_list.append(song_info) return filtered_list