getAvailableDevices
Retrieve a list of Spotify Connect devices available for playback, enabling users to select where to stream music.
Instructions
Get information about the user's available Spotify Connect devices
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/read.ts:551-601 (handler)The handler function that executes the tool logic: fetches available Spotify devices using the Spotify API, handles errors, and formats a list of devices with status, volume, and ID.handler: async (_args, _extra: SpotifyHandlerExtra) => { try { const devices = await handleSpotifyRequest(async (spotifyApi) => { return await spotifyApi.player.getAvailableDevices(); }); if (!devices.devices || devices.devices.length === 0) { return { content: [ { type: 'text', text: 'No available devices found. Make sure Spotify is open on at least one device.', }, ], }; } const formattedDevices = devices.devices .map((device, i) => { const status = device.is_active ? '▶ Active' : '○ Inactive'; const volume = device.volume_percent !== null ? `${device.volume_percent}%` : 'N/A'; const restricted = device.is_restricted ? ' (Restricted)' : ''; return `${i + 1}. ${device.name} (${device.type})${restricted}\n Status: ${status} | Volume: ${volume} | ID: ${device.id}`; }) .join('\n\n'); return { content: [ { type: 'text', text: `# Available Spotify Devices\n\n${formattedDevices}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error getting available devices: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }, };
- src/read.ts:546-550 (schema)Schema definition for the getAvailableDevices tool, using tool<Record<string, never>> type indicating no input parameters, with empty schema object.const getAvailableDevices: tool<Record<string, never>> = { name: 'getAvailableDevices', description: "Get information about the user's available Spotify Connect devices", schema: {},
- src/read.ts:603-612 (registration)Includes the getAvailableDevices tool in the exported readTools array, which is later used for registration.export const readTools = [ searchSpotify, getNowPlaying, getMyPlaylists, getPlaylistTracks, getRecentlyPlayed, getUsersSavedTracks, getQueue, getAvailableDevices, ];
- src/index.ts:12-14 (registration)Final registration of all tools including getAvailableDevices from readTools by calling server.tool() on the MCP server instance.[...readTools, ...playTools, ...albumTools].forEach((tool) => { server.tool(tool.name, tool.description, tool.schema, tool.handler); });