diff --git a/README.md b/README.md index 3224c44..43b4a20 100644 --- a/README.md +++ b/README.md @@ -52,13 +52,20 @@ Add the MCP server to your Claude Code configuration by editing `~/.claude/setti "mcpServers": { "spotify": { "command": "/absolute/path/to/mcp-spotify/.venv/bin/python", - "args": ["/absolute/path/to/mcp-spotify/server.py"] + "args": ["/absolute/path/to/mcp-spotify/server.py"], + "env": { + "SPOTIPY_CLIENT_ID": "your_client_id_here", + "SPOTIPY_CLIENT_SECRET": "your_client_secret_here", + "SPOTIPY_REDIRECT_URI": "http://localhost:8888/callback" + } } } } ```` -**Note:** Replace `/absolute/path/to/mcp-spotify` with the actual path to your project. To find it, run `pwd` in the project directory: +**Note:** Replace the path and fill in the env values with your actual Spotify app credentials. The `env` block is required because Claude Code launches the server as a subprocess from a different working directory where `load_dotenv()` may not find your `.env` file. + +Replace `/absolute/path/to/mcp-spotify` with the actual path to your project. To find it, run `pwd` in the project directory: ```bash cd /path/to/mcp-spotify diff --git a/spotify_client.py b/spotify_client.py index 704bb1e..27ef6dc 100644 --- a/spotify_client.py +++ b/spotify_client.py @@ -46,6 +46,8 @@ def get_client() -> spotipy.Spotify: def _format_duration(ms: int) -> str: + if ms is None: + return "unknown" seconds = ms // 1000 minutes, seconds = divmod(seconds, 60) return f"{minutes}:{seconds:02d}" @@ -154,6 +156,8 @@ def create_playlist(name: str, description: str = "", public: bool = False) -> d def add_tracks_to_playlist(playlist_id: str, track_uris: list[str]) -> dict: + if not track_uris: + raise ValueError("track_uris must not be empty") sp = get_client() for i in range(0, len(track_uris), 100): sp.playlist_add_items(playlist_id, track_uris[i : i + 100])