fix: empty track_uris guard, None duration handling, README env block

This commit is contained in:
2026-05-22 22:41:13 +02:00
parent 3f1181989e
commit 29d13b6974
2 changed files with 13 additions and 2 deletions

View File

@@ -52,13 +52,20 @@ Add the MCP server to your Claude Code configuration by editing `~/.claude/setti
"mcpServers": { "mcpServers": {
"spotify": { "spotify": {
"command": "/absolute/path/to/mcp-spotify/.venv/bin/python", "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 ```bash
cd /path/to/mcp-spotify cd /path/to/mcp-spotify

View File

@@ -46,6 +46,8 @@ def get_client() -> spotipy.Spotify:
def _format_duration(ms: int) -> str: def _format_duration(ms: int) -> str:
if ms is None:
return "unknown"
seconds = ms // 1000 seconds = ms // 1000
minutes, seconds = divmod(seconds, 60) minutes, seconds = divmod(seconds, 60)
return f"{minutes}:{seconds:02d}" 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: 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() sp = get_client()
for i in range(0, len(track_uris), 100): for i in range(0, len(track_uris), 100):
sp.playlist_add_items(playlist_id, track_uris[i : i + 100]) sp.playlist_add_items(playlist_id, track_uris[i : i + 100])