client

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeSSEMessage

func EncodeSSEMessage(event string, data []byte) ([]byte, error)

func MarshalJSONEvent

func MarshalJSONEvent(v any) ([]byte, error)

func ParseJSON

func ParseJSON(data []byte) json.RawMessage

func ParseSSE

func ParseSSE(r io.Reader, out chan<- SSEEvent) error

Types

type BackendConfig

type BackendConfig struct {
	Name        string             `yaml:"name"`
	Type        BackendType        `yaml:"type"`
	Command     string             `yaml:"command,omitempty"`
	Args        []string           `yaml:"args,omitempty"`
	Env         map[string]string  `yaml:"env,omitempty"`
	URL         string             `yaml:"url,omitempty"`
	Timeout     time.Duration      `yaml:"timeout,omitempty"`
	MaxRetries  int                `yaml:"maxRetries,omitempty"`
	HealthCheck *HealthCheckConfig `yaml:"healthCheck,omitempty"`
}

type BackendInfo

type BackendInfo struct {
	Config      BackendConfig
	Status      BackendStatus
	Tools       []protocol.ToolDefinition
	Resources   []protocol.Resource
	Prompts     []protocol.Prompt
	Latency     time.Duration
	ConnectedAt time.Time
	ErrorCount  int
}

type BackendStatus

type BackendStatus string
const (
	StatusConnected    BackendStatus = "connected"
	StatusDisconnected BackendStatus = "disconnected"
	StatusError        BackendStatus = "error"
	StatusDraining     BackendStatus = "draining"
)

type BackendType

type BackendType string
const (
	BackendTypeStdio BackendType = "stdio"
	BackendTypeSSE   BackendType = "sse"
)

type ClientConfig

type ClientConfig struct {
	MaxRetries     int
	RetryDelay     time.Duration
	RequestTimeout time.Duration
	BufferSize     int
}

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

type ClientOption

type ClientOption func(*ClientConfig)

func WithBufferSize

func WithBufferSize(n int) ClientOption

func WithMaxRetries

func WithMaxRetries(n int) ClientOption

func WithRequestTimeout

func WithRequestTimeout(d time.Duration) ClientOption

type HealthCheckConfig

type HealthCheckConfig struct {
	Interval    time.Duration `yaml:"interval,omitempty"`
	Timeout     time.Duration `yaml:"timeout,omitempty"`
	MaxFailures int           `yaml:"maxFailures,omitempty"`
}

type MCPClient

type MCPClient struct {
	// contains filtered or unexported fields
}

func NewMCPClient

func NewMCPClient(backend BackendConfig, opts ...ClientOption) *MCPClient

func (*MCPClient) CallTool

func (c *MCPClient) CallTool(ctx context.Context, name string, args json.RawMessage) (*protocol.ToolResult, error)

func (*MCPClient) Close

func (c *MCPClient) Close() error

func (*MCPClient) Connect

func (c *MCPClient) Connect(ctx context.Context) error

func (*MCPClient) Info

func (c *MCPClient) Info() BackendInfo

func (*MCPClient) ListTools

func (c *MCPClient) ListTools(ctx context.Context) ([]protocol.ToolDefinition, error)

func (*MCPClient) SendRequest

func (c *MCPClient) SendRequest(ctx context.Context, req *protocol.Request) (*protocol.Response, error)

type MessageWriter

type MessageWriter struct {
	// contains filtered or unexported fields
}

func NewMessageWriter

func NewMessageWriter(endpoint string) *MessageWriter

func (*MessageWriter) WriteMessage

func (w *MessageWriter) WriteMessage(data []byte) error

type MultiClient

type MultiClient struct {
	// contains filtered or unexported fields
}

func NewMultiClient

func NewMultiClient() *MultiClient

func (*MultiClient) All

func (mc *MultiClient) All() []*MCPClient

func (*MultiClient) CloseAll

func (mc *MultiClient) CloseAll()

func (*MultiClient) Get

func (mc *MultiClient) Get(name string) (*MCPClient, bool)

func (*MultiClient) Register

func (mc *MultiClient) Register(name string, client *MCPClient)

type SSEClient

type SSEClient struct {
	// contains filtered or unexported fields
}

func NewSSEClient

func NewSSEClient(url string) *SSEClient

func (*SSEClient) Close

func (s *SSEClient) Close()

func (*SSEClient) Connect

func (s *SSEClient) Connect() error

func (*SSEClient) Done

func (s *SSEClient) Done() <-chan struct{}

func (*SSEClient) Events

func (s *SSEClient) Events() <-chan SSEEvent

type SSEEvent

type SSEEvent struct {
	Event string
	Data  string
	ID    string
}

func DecodeSSEMessage

func DecodeSSEMessage(raw []byte) (*SSEEvent, error)

type SSEStream

type SSEStream struct {
	// contains filtered or unexported fields
}

func NewSSEStream

func NewSSEStream() *SSEStream

func (*SSEStream) Close

func (s *SSEStream) Close()

func (*SSEStream) Done

func (s *SSEStream) Done() <-chan struct{}

func (*SSEStream) Events

func (s *SSEStream) Events() <-chan SSEEvent

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL