Documentation
¶
Index ¶
- type Client
- func (c *Client) AddServer(ctx context.Context, name string, config *pb.ServerConfig) (*pb.ServerInfo, error)
- func (c *Client) Close() error
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) DisableServer(ctx context.Context, name string) (*pb.ServerInfo, error)
- func (c *Client) EnableServer(ctx context.Context, name string) (*pb.ServerInfo, error)
- func (c *Client) GetAutoSyncStatus(ctx context.Context) (*pb.AutoSyncStatus, error)
- func (c *Client) GetConfig(ctx context.Context) (*pb.Config, error)
- func (c *Client) GetServer(ctx context.Context, name string) (*pb.ServerInfo, error)
- func (c *Client) GetStatus(ctx context.Context) (*pb.DaemonStatus, error)
- func (c *Client) IsConnected() bool
- func (c *Client) ListDestinations(ctx context.Context) (map[string]*pb.DestinationInfo, error)
- func (c *Client) ListServers(ctx context.Context, filter *pb.ServerFilter) ([]*pb.ServerInfo, error)
- func (c *Client) LoadConfig(ctx context.Context, path string) error
- func (c *Client) PreviewSync(ctx context.Context, destination string) (*pb.SyncPreview, error)
- func (c *Client) RegisterDestination(ctx context.Context, name string, destType pb.DestinationType, path string, ...) error
- func (c *Client) RemoveDestination(ctx context.Context, name string) error
- func (c *Client) RemoveServer(ctx context.Context, name string) error
- func (c *Client) SaveConfig(ctx context.Context) error
- func (c *Client) SetConfig(ctx context.Context, config *pb.Config) error
- func (c *Client) Shutdown(ctx context.Context) error
- func (c *Client) StartAutoSync(ctx context.Context, config *pb.AutoSyncConfig) error
- func (c *Client) StopAutoSync(ctx context.Context) error
- func (c *Client) Subscribe(ctx context.Context, eventTypes []pb.EventType, handler EventHandler) error
- func (c *Client) SyncTo(ctx context.Context, destination string, options *pb.SyncOptions) (*pb.SyncResult, error)
- func (c *Client) SyncToMultiple(ctx context.Context, destinations []string, options *pb.SyncOptions) (*pb.MultiSyncResult, error)
- func (c *Client) UpdateServer(ctx context.Context, name string, config *pb.ServerConfig) (*pb.ServerInfo, error)
- type ClientOptions
- type ConnectionType
- type EventHandler
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the gRPC connection and provides simplified methods
Example (Tcp) ¶
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/b-open-io/agent-master-engine/daemon/client"
pb "github.com/b-open-io/agent-master-engine/daemon/proto"
)
func main() {
// Create a client with default TCP options
c := client.NewClient(&client.ClientOptions{
Type: client.ConnectionTCP,
Address: "localhost:50051",
RequestTimeout: 10 * time.Second,
})
// Connect to the daemon
ctx := context.Background()
if err := c.Connect(ctx); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer c.Close()
// Add a new server
serverConfig := &pb.ServerConfig{
Transport: "stdio",
Command: "node",
Args: []string{"/path/to/server.js"},
Enabled: true,
Metadata: map[string]string{
"version": "1.0.0",
},
}
serverInfo, err := c.AddServer(ctx, "my-mcp-server", serverConfig)
if err != nil {
log.Fatalf("Failed to add server: %v", err)
}
fmt.Printf("Added server: %s\n", serverInfo.Name)
// List all servers
servers, err := c.ListServers(ctx, nil)
if err != nil {
log.Fatalf("Failed to list servers: %v", err)
}
fmt.Printf("Found %d servers\n", len(servers))
// Sync to Claude
syncResult, err := c.SyncTo(ctx, "claude", &pb.SyncOptions{
Force: false,
Backup: true,
})
if err != nil {
log.Fatalf("Failed to sync: %v", err)
}
fmt.Printf("Synced %d servers successfully\n", syncResult.ServersSynced)
}
Output:
Example (UnixSocket) ¶
package main
import (
"context"
"fmt"
"log"
"github.com/b-open-io/agent-master-engine/daemon/client"
)
func main() {
// Create a client for Unix socket connection
c := client.NewClient(&client.ClientOptions{
Type: client.ConnectionUnix,
Address: "/tmp/agent-master.sock",
})
ctx := context.Background()
if err := c.Connect(ctx); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer c.Close()
// Get daemon status
status, err := c.GetStatus(ctx)
if err != nil {
log.Fatalf("Failed to get status: %v", err)
}
fmt.Printf("Daemon version: %s\n", status.Version)
fmt.Printf("Uptime: %d seconds\n", status.UptimeSeconds)
fmt.Printf("Auto-sync running: %v\n", status.AutoSyncRunning)
}
Output:
func NewClient ¶
func NewClient(opts *ClientOptions) *Client
NewClient creates a new client with the given options
func (*Client) AddServer ¶
func (c *Client) AddServer(ctx context.Context, name string, config *pb.ServerConfig) (*pb.ServerInfo, error)
AddServer adds a new server configuration
func (*Client) DisableServer ¶
DisableServer disables a server
func (*Client) EnableServer ¶
EnableServer enables a server
func (*Client) GetAutoSyncStatus ¶
GetAutoSyncStatus gets the current auto-sync status
func (*Client) IsConnected ¶
IsConnected returns true if the client is connected
func (*Client) ListDestinations ¶
ListDestinations lists all available destinations
func (*Client) ListServers ¶
func (c *Client) ListServers(ctx context.Context, filter *pb.ServerFilter) ([]*pb.ServerInfo, error)
ListServers lists all server configurations
func (*Client) LoadConfig ¶
LoadConfig loads configuration from a file
func (*Client) PreviewSync ¶
PreviewSync previews what would be synced to a destination
func (*Client) RegisterDestination ¶
func (c *Client) RegisterDestination(ctx context.Context, name string, destType pb.DestinationType, path string, options map[string]string) error
RegisterDestination registers a new destination
func (*Client) RemoveDestination ¶
RemoveDestination removes a destination
func (*Client) RemoveServer ¶
RemoveServer removes a server configuration
func (*Client) SaveConfig ¶
SaveConfig saves the current configuration
func (*Client) StartAutoSync ¶
StartAutoSync starts the auto-sync feature
func (*Client) StopAutoSync ¶
StopAutoSync stops the auto-sync feature
func (*Client) Subscribe ¶
func (c *Client) Subscribe(ctx context.Context, eventTypes []pb.EventType, handler EventHandler) error
Subscribe subscribes to events from the daemon
Example ¶
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/b-open-io/agent-master-engine/daemon/client"
pb "github.com/b-open-io/agent-master-engine/daemon/proto"
)
func main() {
c := client.NewClient(client.DefaultOptions())
ctx := context.Background()
if err := c.Connect(ctx); err != nil {
log.Fatalf("Failed to connect: %v", err)
}
defer c.Close()
// Subscribe to all event types
eventTypes := []pb.EventType{
pb.EventType_CONFIG_CHANGE,
pb.EventType_SYNC_COMPLETE,
pb.EventType_ERROR,
pb.EventType_AUTO_SYNC_STATUS,
}
err := c.Subscribe(ctx, eventTypes, func(event *pb.Event) error {
fmt.Printf("Received event: %s at %s\n",
event.Type.String(),
event.Timestamp.AsTime().Format(time.RFC3339))
// Handle specific event types
switch event.Type {
case pb.EventType_CONFIG_CHANGE:
if cfg := event.GetConfigChange(); cfg != nil {
fmt.Printf("Config changed: %s\n", cfg.ChangeType)
}
case pb.EventType_SYNC_COMPLETE:
if sync := event.GetSyncComplete(); sync != nil {
fmt.Printf("Sync completed to %s: success=%v\n",
sync.Destination, sync.Success)
}
case pb.EventType_ERROR:
if err := event.GetError(); err != nil {
fmt.Printf("Error in %s: %s\n", err.Component, err.Message)
}
}
return nil
})
if err != nil {
log.Fatalf("Failed to subscribe: %v", err)
}
// Keep listening for events
select {}
}
Output:
func (*Client) SyncTo ¶
func (c *Client) SyncTo(ctx context.Context, destination string, options *pb.SyncOptions) (*pb.SyncResult, error)
SyncTo syncs configuration to a specific destination
func (*Client) SyncToMultiple ¶
func (c *Client) SyncToMultiple(ctx context.Context, destinations []string, options *pb.SyncOptions) (*pb.MultiSyncResult, error)
SyncToMultiple syncs configuration to multiple destinations
func (*Client) UpdateServer ¶
func (c *Client) UpdateServer(ctx context.Context, name string, config *pb.ServerConfig) (*pb.ServerInfo, error)
UpdateServer updates an existing server configuration
type ClientOptions ¶
type ClientOptions struct {
// Connection settings
Type ConnectionType
Address string
// Retry settings
MaxRetries int
RetryDelay time.Duration
RetryBackoffMultiplier float64
// Keepalive settings
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
// Request timeout
RequestTimeout time.Duration
}
ClientOptions contains configuration options for the client
func DefaultOptions ¶
func DefaultOptions() *ClientOptions
DefaultOptions returns sensible default options
type ConnectionType ¶
type ConnectionType int
ConnectionType represents the type of connection (TCP or Unix socket)
const ( ConnectionTCP ConnectionType = iota ConnectionUnix )
type EventHandler ¶
EventHandler is a function that handles events