Labsco
imprvhub logo

MCP Claude Spotify

β˜… 41

from imprvhub

An integration for Claude Desktop to interact with Spotify using the Model Context Protocol (MCP).

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

MCP Claude Spotify

Trust Score Verified on MseeP smithery badge

<table style="border-collapse: collapse; width: 100%;"> <tr> <td style="padding: 15px; vertical-align: middle; border: none; text-align: center;"> <a href="https://mseep.ai/app/imprvhub-mcp-claude-spotify"> <img src="https://mseep.net/pr/imprvhub-mcp-claude-spotify-badge.png" alt="MseeP.ai Security Assessment Badge" /> </a> </td> <td style="width: 50%; padding: 15px; vertical-align: middle; border: none;">An integration that allows Claude Desktop to interact with Spotify using the Model Context Protocol (MCP).</td> <td style="width: 50%; padding: 0; vertical-align: middle; border: none;"><a href="https://glama.ai/mcp/servers/@imprvhub/mcp-claude-spotify"><img src="https://glama.ai/mcp/servers/@imprvhub/mcp-claude-spotify/badge" alt="Claude Spotify MCP server" style="max-width: 100%;" /></a></td> </tr> </table>

Features

  • Spotify authentication
  • Search for tracks, albums, artists, and playlists
  • Playback control (play, pause, next, previous)
  • Full playlist management (create, update, delete, reorder tracks, manage cover images)
  • Get personalized recommendations
  • Access user's top played tracks over different time periods
  • View recently played tracks

Demo

<p> <a href="https://www.youtube.com/watch?v=WNw5H9epZfc"> <img src="public/assets/preview.png" width="600" alt="Claude Spotify Integration Demo"> </a> </p>

Setting up Spotify Credentials

To use this MCP, you need to obtain Spotify API credentials:

  1. Go to Spotify Developer Dashboard
  2. Log in with your Spotify account
  3. Click "Create App"
  4. Fill in your app information:
    • App name: "MCP Claude Spotify" (or whatever you prefer)
    • App description: "Spotify integration for Claude Desktop"
    • Website: You can leave this blank or put any URL
    • Redirect URI: Important - Add http://127.0.0.1:8888/callback
  5. Accept the terms and conditions and click "Create"
  6. In your app dashboard, you'll see the "Client ID"
  7. Click "Show Client Secret" to reveal your "Client Secret"

Save these credentials as you'll need them for configuration.

Available Tools

Authentication

auth-spotify

Initiates the Spotify authentication process.

Search

search-spotify

Searches for tracks, albums, artists, or playlists.

Parameters:

  • query: Search text
  • type: Type of search (track, album, artist, playlist)
  • limit: Number of results (1-10, default: 5)

Playback Control

get-current-playback

Gets information about the current playback state.

play-track

Plays a specific track on an active device.

Parameters:

  • trackId: Spotify track ID
  • deviceId: (Optional) Spotify device ID to play on

pause-playback

Pauses the current playback.

next-track

Skips to the next track.

previous-track

Returns to the previous track.

Playlist Management

get-user-playlists

Gets a list of the user's playlists.

Parameters:

  • limit: (Optional) Number of playlists to return (1-50, default: 20)
  • offset: (Optional) Index of the first playlist to return (default: 0)

create-playlist

Creates a new playlist for the current user.

Parameters:

  • name: Playlist name
  • description: (Optional) Description
  • public: (Optional) Whether it's public or private

update-playlist

Updates a playlist's name, description, public/private status, or collaborative setting.

Parameters:

  • playlistId: Spotify ID of the playlist
  • name: (Optional) New name for the playlist
  • description: (Optional) New description for the playlist
  • public: (Optional) Whether the playlist should be public
  • collaborative: (Optional) Whether the playlist should be collaborative (must set public to false first)

delete-playlist

Unfollows (removes) a playlist from your library. The playlist still exists on Spotify but is no longer in your library.

Parameters:

  • playlistId: Spotify ID of the playlist

get-playlist-tracks

Gets the tracks in a playlist with pagination support.

Parameters:

  • playlistId: Spotify ID of the playlist
  • limit: (Optional) Number of tracks to return (1-50, default: 20)
  • offset: (Optional) Index of the first track to return (default: 0)

add-tracks-to-playlist

Adds tracks to a playlist.

Parameters:

  • playlistId: Playlist ID
  • trackIds: Array of track IDs

remove-tracks-from-playlist

Removes tracks from a playlist.

Parameters:

  • playlistId: Spotify ID of the playlist
  • trackIds: Array of Spotify track IDs to remove

reorder-playlist-tracks

Reorders tracks in a playlist by moving a range of tracks to a new position.

Parameters:

  • playlistId: Spotify ID of the playlist
  • rangeStart: Position of the first track to move
  • insertBefore: Position where the tracks should be inserted
  • rangeLength: (Optional) Number of tracks to move (default: 1)

get-playlist-cover

Gets the cover image of a playlist.

Parameters:

  • playlistId: Spotify ID of the playlist

upload-playlist-cover

Uploads a custom cover image for a playlist (base64 encoded JPEG, max 256KB).

Parameters:

  • playlistId: Spotify ID of the playlist
  • imageBase64: Base64 encoded JPEG image

Discovery & History

get-recommendations

Gets track recommendations based on seed tracks, artists, or genres.

Parameters:

  • seedTracks: (Optional) Array of Spotify track IDs
  • seedArtists: (Optional) Array of Spotify artist IDs
  • seedGenres: (Optional) Array of genre names
  • limit: (Optional) Number of recommendations (1-100, default: 20)

get-top-tracks

Gets the user's most played tracks over a specified time range.

Parameters:

  • limit: (Optional) Number of tracks to return (1-50, default: 20)
  • offset: (Optional) Index of the first track to return (default: 0)
  • time_range: (Optional) Time frame for calculating affinity:
    • short_term: Approximately last 4 weeks
    • medium_term: Approximately last 6 months (default)
    • long_term: Several years of data

get-recently-played

Gets the user's recently played tracks.

Parameters:

  • limit: (Optional) Maximum number of tracks to return (1-50, default: 20)
  • before: (Optional) Unix timestamp in milliseconds. Returns tracks played before this time
  • after: (Optional) Unix timestamp in milliseconds. Returns tracks played after this time

Testing

This project includes automated tests to ensure code quality and functionality. The test suite uses Jest with TypeScript support and covers:

  • Zod schema validation - verifies all input schemas correctly validate data
  • Spotify API interactions - tests API request handling and error handling
  • MCP server functionality - ensures proper registration and execution of tools

Running Tests

First, make sure all development dependencies are installed:

Copy & paste β€” that's it
npm install

To run all tests:

Copy & paste β€” that's it
npm test

To run a specific test file:

Copy & paste β€” that's it
npm test -- --testMatch="**/tests/schemas.test.ts"

If you encounter issues with ESM modules, make sure you're using Node.js v16 or higher and that the NODE_OPTIONS environment variable includes the --experimental-vm-modules flag as configured in the package.json.

Test Structure

  • tests/schemas.test.ts: Tests for input validation schemas
  • tests/spotify-api.test.ts: Tests for Spotify API interactions
  • tests/server.test.ts: Tests for MCP server functionality

Adding New Tests

When adding new functionality, please include corresponding tests:

  1. For new schemas, add validation tests in schemas.test.ts
  2. For Spotify API functions, add tests in spotify-api.test.ts
  3. For MCP tools, add tests in server.test.ts

All tests should be written using Jest and the ESM module format with TypeScript.

Security Notes

  • Never share your Client ID and Client Secret
  • Access token is now stored in the user's home directory at ~/.spotify-mcp/tokens.json to enable persistence between sessions and multiple instances
  • No user data is stored on disk

Revoking Application Access

For security reasons, you may want to revoke the application's access to your Spotify account when:

  • You no longer use this integration
  • You suspect unauthorized access
  • You're troubleshooting authentication issues

To revoke access:

  1. Go to your Spotify Account page
  2. Navigate to "Apps" in the menu
  3. Find "MCP Claude Spotify" (or the name you chose for your app)
  4. Click "REMOVE ACCESS"

This immediately invalidates all access and refresh tokens. The next time you use the auth-spotify command, you'll need to authorize the application again.

Contributing

Contributions are welcome! Here are some guidelines to follow:

Development Workflow

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests to ensure they pass (npm test)
  5. Commit your changes (git commit -m 'Add some amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Code Style Guidelines

This project follows these coding standards:

  • Use TypeScript with strict type checking
  • Follow ESM module format
  • Use 2 spaces for indentation
  • Use camelCase for variables and functions
  • Use PascalCase for classes and interfaces
  • Document functions with JSDoc comments
  • Keep line length under 100 characters

Project Structure

The project follows this structure:

Copy & paste β€” that's it
mcp-claude-spotify/
β”œβ”€β”€ src/               # Source code
β”œβ”€β”€ build/             # Compiled JavaScript
β”œβ”€β”€ tests/             # Test files
β”œβ”€β”€ public/            # Public assets
└── ...

Pull Request Process

  1. Ensure your code follows the style guidelines
  2. Update documentation if needed
  3. Add tests for new functionality
  4. Make sure all tests pass
  5. Your PR will be reviewed by maintainers

Related Links

License

This project is licensed under the Mozilla Public License 2.0 - see the LICENSE file for details.