Problem
In internal/mcpserver/server.go, handleListDevices builds its output with an intermediate []string slice and then a second loop concatenating strings:
var lines []string
for _, d := range devices {
lines = append(lines, fmt.Sprintf("[%s] %s — %s", d.Status, d.Name, d.ID))
}
out := ""
for _, l := range lines {
out += l + "\n"
}
This is two passes, an extra allocation, and less idiomatic Go.
Fix
Use strings.Builder or collapse into a single loop:
var b strings.Builder
for _, d := range devices {
fmt.Fprintf(&b, "[%s] %s — %s\n", d.Status, d.Name, d.ID)
}
return mcp.NewToolResultText(b.String()), nil
Problem
In
internal/mcpserver/server.go,handleListDevicesbuilds its output with an intermediate[]stringslice and then a second loop concatenating strings:This is two passes, an extra allocation, and less idiomatic Go.
Fix
Use
strings.Builderor collapse into a single loop: