Hermes runs in CoreDesktop's sandbox, with its own network, so it can't reach 127.0.0.1:8470. The app now also serves MCP on a Unix socket in its data folder (/data/mcp.sock), which Hermes reaches with socat. HTTP /mcp with the bearer token remains for other agents. hermes/setup.sh asks for the user's own hub token (the Core now issues per-user tokens), checks it with the hub, and stores it in Hermes' .env. The hub only speaks SSE, and Hermes' Streamable HTTP attempt can use up its connect time, so the setup sets transport: sse. It also warns when Hermes' gateway is still running with the old servers. Check-ins store the hub's own tool names, without Hermes' mcp__mcphub__ prefix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.3 KiB
Go
95 lines
2.3 KiB
Go
package mcpserver
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
"log/slog"
|
|
"net"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
|
|
"supermarket/internal/bridge"
|
|
"supermarket/internal/db"
|
|
)
|
|
|
|
// Hermes reaches the app through the socket with `socat STDIO UNIX-CONNECT:`,
|
|
// which is a plain stdio MCP session over the connection.
|
|
func TestServeSocket(t *testing.T) {
|
|
dir := t.TempDir()
|
|
d, err := db.Open(filepath.Join(dir, "app.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer d.Close()
|
|
|
|
path := filepath.Join(dir, "mcp.sock")
|
|
// A socket left over from the last run must not stop the next one.
|
|
if err := os.WriteFile(path, nil, 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
done := make(chan error, 1)
|
|
go func() {
|
|
done <- ServeSocket(ctx, d, "test", path, slog.New(slog.NewTextHandler(io.Discard, nil)))
|
|
}()
|
|
|
|
var conn net.Conn
|
|
for i := 0; i < 100; i++ {
|
|
if conn, err = net.Dial("unix", path); err == nil {
|
|
break
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if fi, err := os.Stat(path); err != nil || fi.Mode().Perm() != 0o600 {
|
|
t.Errorf("socket mode = %v, %v; want 0600", fi.Mode().Perm(), err)
|
|
}
|
|
|
|
client := mcp.NewClient(&mcp.Implementation{Name: "test"}, nil)
|
|
session, err := client.Connect(ctx, &mcp.IOTransport{Reader: conn, Writer: conn}, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tools, err := session.ListTools(ctx, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
found := false
|
|
for _, tool := range tools.Tools {
|
|
found = found || tool.Name == "bridge_checkin"
|
|
}
|
|
if !found {
|
|
t.Fatalf("bridge_checkin not among %d tools", len(tools.Tools))
|
|
}
|
|
|
|
res, err := session.CallTool(ctx, &mcp.CallToolParams{
|
|
Name: "bridge_checkin",
|
|
Arguments: map[string]any{"agent": "hermes", "mcphub_tools": []string{"espocrm_search"}},
|
|
})
|
|
if err != nil || res.IsError {
|
|
t.Fatalf("bridge_checkin: %v %+v", err, res)
|
|
}
|
|
last, err := bridge.Last(d)
|
|
if err != nil || last == nil || last.Agent != "hermes" || len(last.MCPHubTools) != 1 {
|
|
t.Fatalf("last check-in = %+v, %v", last, err)
|
|
}
|
|
|
|
session.Close()
|
|
cancel()
|
|
select {
|
|
case err := <-done:
|
|
if err != nil {
|
|
t.Fatalf("ServeSocket: %v", err)
|
|
}
|
|
case <-time.After(5 * time.Second):
|
|
t.Fatal("ServeSocket didn't stop")
|
|
}
|
|
}
|