fix: sync agent MCP payloads and query runtime state

This commit is contained in:
kyaring
2026-09-28 13:20:42 +08:00
parent 0c8ac02f82
commit 3ad7faba3b
3 changed files with 57 additions and 4 deletions
+2
View File
@@ -138,6 +138,8 @@ func run(hub, name, token string, insecure bool) error {
func handle(writeJSON func(cluster.Message) error, exec executor.Local, mcpRuntime *cluster.MCPRuntime, msg cluster.Message) error {
switch msg.Action {
case "mcp_list":
return writeJSON(cluster.Message{ID: msg.ID, Status: "success", Payload: mcpRuntime.List()})
case "mcp_call":
var p struct {
Server string `json:"server"`
+29
View File
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"
"time"
@@ -147,3 +148,31 @@ func main() {
os.Stdout.WriteString("\n")
}
}
func (h *HubRemoteBackend) ListAgentMCP(ctx context.Context, device string) (any, error) {
var res any
err := h.get(ctx, "/api/v1/mcp/list?device="+url.QueryEscape(device), &res)
return res, err
}
func (h *HubRemoteBackend) CallAgentMCP(ctx context.Context, clientIP, device, server, tool string, args any) (any, error) {
payload := map[string]any{"device": device, "server": server, "tool": tool, "arguments": args}
var res any
return res, h.post("/api/v1/mcp/call", payload, &res)
}
func (h *HubRemoteBackend) get(ctx context.Context, path string, out any) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(h.BaseURL, "/")+path, nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+h.APIKey)
resp, err := h.HTTPClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode >= 400 {
b, _ := io.ReadAll(resp.Body)
return fmt.Errorf("HTTP %d: %s", resp.StatusCode, string(b))
}
return json.NewDecoder(resp.Body).Decode(out)
}