Files
coder/testutil/json.go
Cian Johnston 057cbd4d80 feat(cli): add coder exp mcp command (#17066)
Adds a `coder exp mcp` command which will start a local MCP server
listening on stdio with the following capabilities:
* Show logged in user (`coder whoami`)
* List workspaces (`coder list`)
* List templates (`coder templates list`)
* Start a workspace (`coder start`)
* Stop a workspace (`coder stop`)
* Fetch a single workspace (no direct CLI analogue)
* Execute a command inside a workspace (`coder exp rpty`)
* Report the status of a task (currently a no-op, pending task support)

This can be tested as follows:

```
# Start a local Coder server.
./scripts/develop.sh
# Start a workspace. Currently, creating workspaces is not supported.
./scripts/coder-dev.sh create -t docker --yes
# Add the MCP to your Claude config.
claude mcp add coder ./scripts/coder-dev.sh exp mcp
# Tell Claude to do something Coder-related. You may need to nudge it to use the tools.
claude 'start a docker workspace and tell me what version of python is installed'
```
2025-03-31 18:52:09 +01:00

28 lines
745 B
Go

package testutil
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
// RequireJSONEq is like assert.RequireJSONEq, but it's actually readable.
// Note that this calls t.Fatalf under the hood, so it should never
// be called in a goroutine.
func RequireJSONEq(t *testing.T, expected, actual string) {
t.Helper()
var expectedJSON, actualJSON any
if err := json.Unmarshal([]byte(expected), &expectedJSON); err != nil {
t.Fatalf("failed to unmarshal expected JSON: %s", err)
}
if err := json.Unmarshal([]byte(actual), &actualJSON); err != nil {
t.Fatalf("failed to unmarshal actual JSON: %s", err)
}
if diff := cmp.Diff(expectedJSON, actualJSON); diff != "" {
t.Fatalf("JSON diff (-want +got):\n%s", diff)
}
}