fix(spotify): pin mcp<2 and set writable HOME for credentials

This commit is contained in:
Moritz Graf
2026-09-11 21:37:50 +02:00
parent 24e788ba6b
commit e2944efb3e
+25 -6
View File
@@ -1,7 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
Spotify MCP Server Launcher for OpenClaw. Spotify MCP Server Launcher for OpenClaw.
Ensures credentials.json is configured from SPOTIFY_REFRESH_TOKEN, then executes uvx mcp-server-spotify. Ensures credentials.json is configured from SPOTIFY_REFRESH_TOKEN in a writable HOME,
pins mcp<2 to avoid FastMCP renaming breakage in mcp 2.x, then executes uvx mcp-server-spotify.
""" """
import json import json
@@ -10,12 +11,30 @@ import sys
from pathlib import Path from pathlib import Path
def get_writable_home() -> Path:
candidates = [
Path("/home/node/.openclaw/spotify-home"),
Path("/tmp/spotify-home"),
]
for p in candidates:
try:
p.mkdir(parents=True, exist_ok=True)
test_file = p / ".write_test"
test_file.write_text("ok")
test_file.unlink()
return p
except Exception:
continue
return Path("/tmp")
def main(): def main():
refresh_token = os.environ.get("SPOTIFY_REFRESH_TOKEN") refresh_token = os.environ.get("SPOTIFY_REFRESH_TOKEN")
client_id = os.environ.get("SPOTIFY_CLIENT_ID")
client_secret = os.environ.get("SPOTIFY_CLIENT_SECRET")
creds_dir = Path.home() / ".spotify-mcp" spotify_home = get_writable_home()
os.environ["HOME"] = str(spotify_home)
creds_dir = spotify_home / ".spotify-mcp"
creds_file = creds_dir / "credentials.json" creds_file = creds_dir / "credentials.json"
if refresh_token: if refresh_token:
@@ -34,8 +53,8 @@ def main():
except Exception as e: except Exception as e:
print(f"[run_spotify_mcp] Warning: Could not write credentials file: {e}", file=sys.stderr) print(f"[run_spotify_mcp] Warning: Could not write credentials file: {e}", file=sys.stderr)
# Launch mcp-server-spotify via uvx # Launch mcp-server-spotify via uvx with pinned mcp<2
os.execvp("uvx", ["uvx", "mcp-server-spotify"]) os.execvp("uvx", ["uvx", "--with", "mcp<2", "mcp-server-spotify"])
if __name__ == "__main__": if __name__ == "__main__":