get_my_playlists
Retrieve your Spotify playlists to view, manage, or organize your music collections directly within your workflow.
Instructions
FastMCP tool to get user playlists using SpotifyClient.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_my_playlists"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- spotify.py:47-68 (handler)The core handler method in SpotifyClient class that fetches the current user's playlists from Spotify API using spotipy, formats them, and returns as a string.
async def get_my_playlists(self) -> str: """ Get all playlists for the current user. """ try: results = self.sp.current_user_playlists() if not results["items"]: return "No playlists found." playlists = [] for item in results["items"]: name = item["name"].encode("ascii", "ignore").decode() playlist = ( f"Name: {name}\n" f"Tracks: {item['tracks']['total']}\n" f"ID: {item['id']}" ) playlists.append(playlist) return "\n---\n".join(playlists) except Exception as e: return f"Error fetching playlists: {str(e)}" - main.py:8-13 (registration)Registers the MCP tool 'get_my_playlists' using FastMCP decorator, which calls the SpotifyClient's get_my_playlists method.
@mcp.tool() async def get_my_playlists() -> str: """ FastMCP tool to get user playlists using SpotifyClient. """ return await client.get_my_playlists()