Skip to content

Commit a0ed7e5

Browse files
committed
fix up for go-buttplug v0.0.8 changes
also converted existing resources into tools calls for opencode/crush support. see anomalyco/opencode#806.
1 parent 8d83a7e commit a0ed7e5

9 files changed

Lines changed: 564 additions & 295 deletions

File tree

‎.env‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GOEXPERIMENT=jsonv2

‎Taskfile.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: '3'
22

3+
dotenv:
4+
- .env
5+
36
tasks:
47
default:
58
desc: 'Default task is to "build"'

‎cmd/buttplug-mcp/main.go‎

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
package main
44

55
import (
6+
"context"
67
"fmt"
8+
"log"
79
"log/slog"
810
"os"
11+
"os/signal"
12+
"sync"
913

1014
"github.com/ConAcademy/buttplug-mcp/internal/bp"
1115
"github.com/ConAcademy/buttplug-mcp/internal/mcp"
@@ -18,7 +22,7 @@ const (
1822
mcpServerVersion = "0.0.1"
1923

2024
defaultSSEHostPort = ":8889"
21-
defaultLogDest = "buttplug-mcp.log"
25+
defaultLogDest = "butplug-mcp.log"
2226
)
2327

2428
type Config struct {
@@ -33,24 +37,23 @@ type Config struct {
3337

3438
func main() {
3539
var config Config
36-
var showHelp bool
3740
var logFilename string
3841

3942
pflag.StringVarP(&logFilename, "log-file", "l", "", "Log file destination (or MCP_LOG_FILE envvar). Default is stderr")
4043
pflag.BoolVarP(&config.LogJSON, "log-json", "j", false, "Log in JSON (default is plaintext)")
4144
pflag.StringVarP(&config.MCPConfig.SSEHostPort, "sse-host", "", "", "host:port to listen to SSE connections")
42-
pflag.BoolVarP(&config.MCPConfig.UseSSE, "sse", "", false, "Use SSE Transport (default is STDIO transport)")
43-
pflag.IntVarP(&config.BPConfig.WsPort, "ws-port", "", 0, "port to connect to the Buttplug Websocket server")
44-
pflag.DurationVarP(&config.BPConfig.DebounceDuration, "debounce", "d", bp.DefaultDebounceDuration, "duration for debounce (default is 20Hz = '50ms')")
45+
pflag.BoolVarP(&config.MCPConfig.UseSSE, "sse", "", false, "Use SSE Transport (default is stdio transport)")
46+
pflag.StringVarP(&config.MCPConfig.ToolDescriptionsFile, "tool-descriptions", "", "", "Path to YAML file with tool descriptions to override defaults (run `tool-descriptions' to see current descriptions in YAML)")
47+
pflag.StringVarP(&config.BPConfig.WebsocketHost, "ws-host", "", "localhost", "host to connect to the Buttplug Websocket server")
48+
pflag.IntVarP(&config.BPConfig.WebsocketPort, "ws-port", "", 12345, "port to connect to the Buttplug Websocket server")
4549
pflag.BoolVarP(&config.Verbose, "verbose", "v", false, "Verbose logging")
46-
pflag.BoolVarP(&showHelp, "help", "h", false, "Show help")
47-
pflag.Parse()
48-
49-
if showHelp {
50-
fmt.Fprintf(os.Stdout, "usage: %s [opts]\n\n", os.Args[0])
50+
pflag.Usage = func() {
51+
o := pflag.CommandLine.Output()
52+
fmt.Fprintf(o, "usage: %s [|start|tool-descriptions] [flags]\n", os.Args[0])
53+
fmt.Fprintf(o, "flags:\n")
5154
pflag.PrintDefaults()
52-
os.Exit(0)
5355
}
56+
pflag.Parse()
5457

5558
if config.MCPConfig.SSEHostPort == "" {
5659
config.MCPConfig.SSEHostPort = defaultSSEHostPort
@@ -67,8 +70,7 @@ func main() {
6770
if logFilename != "" {
6871
logFile, err := os.OpenFile(logFilename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
6972
if err != nil {
70-
fmt.Fprintf(os.Stderr, "failed to open log file: %s\n", err.Error())
71-
os.Exit(1)
73+
log.Fatal("failed to open log file:", err)
7274
}
7375
logWriter = logFile
7476
defer logFile.Close()
@@ -86,26 +88,49 @@ func main() {
8688
logger = slog.New(slog.NewTextHandler(logWriter, &slog.HandlerOptions{Level: logLevel}))
8789
}
8890

89-
// Run our Buttplug manager
90-
var err error
91-
bpManager, err := bp.NewManager(config.BPConfig, logger)
91+
bpm, err := bp.NewManager(config.BPConfig, logger)
9292
if err != nil {
93-
fmt.Fprintf(os.Stderr, "failed to start Buttplug manager: %s\n", err.Error())
94-
os.Exit(1)
93+
log.Fatal("failed to create Buttplug manager:", err)
9594
}
96-
go func() {
97-
err := bpManager.Run()
95+
96+
mcps, err := mcp.New(config.MCPConfig, bpm, logger)
97+
if err != nil {
98+
log.Fatal("failed to create MCP server:", err)
99+
}
100+
101+
switch pflag.Arg(0) {
102+
case "tool-descriptions":
103+
yaml, err := mcp.FormatToolDescriptionsAsYAML(mcps.ToolDescriptions())
98104
if err != nil {
99-
fmt.Fprintf(os.Stderr, "bpm failed: %s\n", err.Error())
100-
os.Exit(1)
105+
log.Fatal("failed to format tool descriptions as YAML:", err)
101106
}
102-
}()
107+
fmt.Println(string(yaml))
108+
return
103109

104-
// Run our MCP server
105-
if err := mcp.RunRouter(config.MCPConfig, bpManager, logger); err != nil {
106-
logger.Error("mcp router error", "error", err.Error())
107-
os.Exit(1)
110+
case "start", "":
111+
// continue to starting the server
112+
113+
default:
114+
log.Fatalf("unknown command: %s", pflag.Arg(0))
108115
}
109116

110-
// TODO: I guess we should clean up the buttplug?
117+
var wg sync.WaitGroup
118+
defer wg.Wait()
119+
120+
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
121+
defer cancel()
122+
123+
wg.Go(func() {
124+
if err := bpm.Run(ctx); err != nil {
125+
logger.Error(
126+
"buttplug manager error, program is useless now",
127+
"error", err.Error())
128+
}
129+
})
130+
131+
if err := mcps.Start(); err != nil {
132+
logger.Error(
133+
"failed to start MCP server:",
134+
"error", err.Error())
135+
}
111136
}

‎go.mod‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
module github.com/ConAcademy/buttplug-mcp
22

3-
go 1.24.1
3+
go 1.25.0
44

55
require (
6-
github.com/diamondburned/go-buttplug v0.0.3
6+
github.com/goccy/go-yaml v1.19.0
77
github.com/mark3labs/mcp-go v0.31.0
88
github.com/spf13/pflag v1.0.6
9+
libdb.so/go-buttplug v0.0.8
910
)
1011

1112
require (
13+
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
14+
github.com/coder/websocket v1.8.14 // indirect
1215
github.com/google/uuid v1.6.0 // indirect
13-
github.com/gorilla/websocket v1.5.3 // indirect
14-
github.com/pkg/errors v0.9.1 // indirect
1516
github.com/spf13/cast v1.7.1 // indirect
1617
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
1718
)

‎go.sum‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/alecthomas/assert/v2 v2.8.1 h1:YCxnYR6jjpfnEK5AK5SysALKdUEBPGH4Y7As6tBnDw0=
2+
github.com/alecthomas/assert/v2 v2.8.1/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
3+
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
4+
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
5+
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
6+
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
7+
github.com/coder/websocket v1.8.14 h1:9L0p0iKiNOibykf283eHkKUHHrpG7f65OE3BhhO7v9g=
8+
github.com/coder/websocket v1.8.14/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
29
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
310
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4-
github.com/diamondburned/go-buttplug v0.0.3 h1:tBRkOMm2GXKWVUOvwnszAGUM4tCF9CUsJyE/PKzlQFY=
5-
github.com/diamondburned/go-buttplug v0.0.3/go.mod h1:2WnC+qL7dg3vB6Hiv9HuITG/eYFsCQ1CETh1qmLUq1s=
611
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
712
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
13+
github.com/goccy/go-yaml v1.19.0 h1:EmkZ9RIsX+Uq4DYFowegAuJo8+xdX3T/2dwNPXbxEYE=
14+
github.com/goccy/go-yaml v1.19.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
815
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
916
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1017
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1118
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
12-
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
13-
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
14-
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
19+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
20+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
1521
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
1622
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
1723
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1824
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1925
github.com/mark3labs/mcp-go v0.31.0 h1:4UxSV8aM770OPmTvaVe/b1rA2oZAjBMhGBfUgOGut+4=
2026
github.com/mark3labs/mcp-go v0.31.0/go.mod h1:rXqOudj/djTORU/ThxYx8fqEVj/5pvTuuebQ2RC7uk4=
21-
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
22-
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
27+
github.com/neilotoole/slogt v1.1.0 h1:c7qE92sq+V0yvCuaxph+RQ2jOKL61c4hqS1Bv9W7FZE=
28+
github.com/neilotoole/slogt v1.1.0/go.mod h1:RCrGXkPc/hYybNulqQrMHRtvlQ7F6NktNVLuLwk6V+w=
2329
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2430
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25-
github.com/qri-io/jsonpointer v0.1.1/go.mod h1:DnJPaYgiKu56EuDp8TU5wFLdZIcAnb/uH9v37ZaMV64=
26-
github.com/qri-io/jsonschema v0.2.1/go.mod h1:g7DPkiOsK1xv6T/Ao5scXRkd+yTFygcANPBaaqW+VrI=
2731
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
2832
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
29-
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
3033
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
3134
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
3235
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
3336
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
34-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
35-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3637
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
3738
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3839
github.com/yosida95/uritemplate/v3 v3.0.2 h1:Ed3Oyj9yrmi9087+NczuL5BwkIc4wvTb5zIM+UJPGz4=
3940
github.com/yosida95/uritemplate/v3 v3.0.2/go.mod h1:ILOh0sOhIJR3+L/8afwt/kE++YT040gmv5BQTMR2HP4=
4041
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4142
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
43+
libdb.so/go-buttplug v0.0.8 h1:icQrfxEShgQ9l6NouOULq2C1WF/AY/1hKujOSVb7uiY=
44+
libdb.so/go-buttplug v0.0.8/go.mod h1:IxRlJOOshEEHMky0lL+f1kSB94Ccqu7PhvGu6VqUXSo=

0 commit comments

Comments
 (0)