Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Part of Gandzs, a personal MCP gateway. One repository per connector.

## Tools

The full definitions, with input schemas, are in [`api/mcp-tools.json`](api/mcp-tools.json).

| Tool | What it does |
| :--- | :--- |
| `play` | Play a Spotify URI, or the first search result for a query. Without either, resume. Optional `device`. |
Expand Down Expand Up @@ -121,6 +123,7 @@ flowchart LR
- `internal/playback` and `internal/account` are the domain: each has a `Service` with the use cases, the rules, and the ports (interfaces) it needs. Values and entities (`URI`, `DeviceID`, `ProfileID`, `InviteCode`, `Token`, …) are exported interfaces with unexported implementations, created only through constructors that validate (`ParseX`, `NewX`, `RestoreX` for stored data). The time comes from an injected `Clock`.
- `internal/spotify` (Web API + OAuth) and `internal/filestore` (JSON files) implement the ports. Wire and file formats stay unexported in them.
- `internal/mcpserver` and `internal/web` are the transports. Each depends on a small interface it defines itself.
- `api/mcp-tools.json` is the `tools/list` result: every tool's name, description, annotations and input schema. It is the API definition the lab catalog shows. `TestToolsMatchSnapshot` fails when the tools change without it; after an intended change, run `go test ./internal/mcpserver -run TestToolsMatchSnapshot -update` and review the diff.

```bash
go test -race ./...
Expand Down
200 changes: 200 additions & 0 deletions api/mcp-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
[
{
"annotations": {
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": true
},
"description": "List the Spotify Connect devices (phone, computer, speakers) that Spotify currently sees, and which one is active.",
"inputSchema": {
"additionalProperties": false,
"type": "object"
},
"name": "devices"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Skip to the next track.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Device name (e.g. 'Pixel 8'), type (e.g. 'smartphone') or ID from the devices tool. Empty: the active device.",
"type": "string"
}
},
"type": "object"
},
"name": "next"
},
{
"annotations": {
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": true
},
"description": "Show what is playing on Spotify right now, on which device, and whether it is paused.",
"inputSchema": {
"additionalProperties": false,
"type": "object"
},
"name": "now_playing"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": true,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Pause Spotify playback.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Device name (e.g. 'Pixel 8'), type (e.g. 'smartphone') or ID from the devices tool. Empty: the active device.",
"type": "string"
}
},
"type": "object"
},
"name": "pause"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Play a Spotify URI, or the first search result for a query, on a device (default: the active one). Without uri and query it resumes playback.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Device name, type or ID. Empty: the active device.",
"type": "string"
},
"query": {
"description": "Search text; the first result of the given type is played, e.g. 'Bohemian Rhapsody Queen'.",
"type": "string"
},
"type": {
"description": "What the query searches for: track (default), album, artist, playlist, show or episode.",
"type": "string"
},
"uri": {
"description": "Spotify URI to play, e.g. spotify:track:..., spotify:album:..., spotify:playlist:... Takes precedence over query.",
"type": "string"
}
},
"type": "object"
},
"name": "play"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Go back to the previous track.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Device name (e.g. 'Pixel 8'), type (e.g. 'smartphone') or ID from the devices tool. Empty: the active device.",
"type": "string"
}
},
"type": "object"
},
"name": "previous"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": true,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Resume Spotify playback where it was paused.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Device name (e.g. 'Pixel 8'), type (e.g. 'smartphone') or ID from the devices tool. Empty: the active device.",
"type": "string"
}
},
"type": "object"
},
"name": "resume"
},
{
"annotations": {
"idempotentHint": false,
"openWorldHint": true,
"readOnlyHint": true
},
"description": "Search Spotify. Returns up to 10 results with their URIs, which the play tool accepts.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"limit": {
"description": "Number of results, 1-10 (Spotify development mode allows at most 10). Default 5.",
"type": "integer"
},
"query": {
"description": "Search text, e.g. an artist, song or album name.",
"type": "string"
},
"type": {
"description": "track (default), album, artist, playlist, show or episode.",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
},
"name": "search"
},
{
"annotations": {
"destructiveHint": false,
"idempotentHint": true,
"openWorldHint": true,
"readOnlyHint": false
},
"description": "Move playback to another device, e.g. from the computer to the phone.",
"inputSchema": {
"additionalProperties": false,
"properties": {
"device": {
"description": "Target device name (e.g. 'Pixel 8'), type or ID from the devices tool.",
"type": "string"
},
"play": {
"description": "Start playing on the new device. Default true.",
"type": [
"null",
"boolean"
]
}
},
"required": [
"device"
],
"type": "object"
},
"name": "transfer"
}
]
36 changes: 28 additions & 8 deletions internal/mcpserver/mcpserver_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package mcpserver

import (
"bytes"
"context"
"encoding/json"
"errors"
"slices"
"flag"
"os"
"path/filepath"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -103,18 +107,34 @@ func call(t *testing.T, cs *mcp.ClientSession, name string, args map[string]any)
return b.String(), res.IsError
}

func TestToolList(t *testing.T) {
// update rewrites the tools/list snapshot instead of comparing against it.
var update = flag.Bool("update", false, "rewrite api/mcp-tools.json from the registered tools")

// TestToolsMatchSnapshot keeps api/mcp-tools.json equal to what tools/list
// returns. The file is the API definition the lab catalog shows, so a change
// to a tool's name, description or schema shows up as a diff in review.
func TestToolsMatchSnapshot(t *testing.T) {
res, err := session(t, &fakePlayer{}).ListTools(context.Background(), nil)
if err != nil {
t.Fatal(err)
}
var names []string
for _, tl := range res.Tools {
names = append(names, tl.Name)
got, err := json.MarshalIndent(res.Tools, "", " ")
if err != nil {
t.Fatal(err)
}
got = append(got, '\n')
path := filepath.Join("..", "..", "api", "mcp-tools.json")
if *update {
if err := os.WriteFile(path, got, 0o644); err != nil {
t.Fatal(err)
}
}
want, err := os.ReadFile(path)
if err != nil {
t.Fatal(err)
}
slices.Sort(names)
if got := strings.Join(names, ","); got != "devices,next,now_playing,pause,play,previous,resume,search,transfer" {
t.Fatalf("tools %s", got)
if !bytes.Equal(got, want) {
t.Fatalf("tools/list differs from %s. If the change is intended, run\n\tgo test ./internal/mcpserver -run TestToolsMatchSnapshot -update\nand review the diff.\ngot:\n%s", path, got)
}
}

Expand Down