Help us shape the future of Go! Take the 2026 Go Developer Survey

discovery

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

internal/discovery/connection_manager.go

internal/discovery/service_discovery.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionStatus

type ConnectionStatus struct {
	Connected     bool      `json:"connected"`
	LastConnected time.Time `json:"lastConnected"`
	ErrorCount    int       `json:"errorCount"`
	LastError     string    `json:"lastError"`
}

ConnectionStatus represents the status of a connection

type DynamicConnectionManager

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

DynamicConnectionManager manages connections to MCP servers discovered via Kubernetes

func NewDynamicConnectionManager

func NewDynamicConnectionManager(serviceDiscovery *K8sServiceDiscovery, logger *logging.Logger) *DynamicConnectionManager

NewDynamicConnectionManager creates a new dynamic connection manager

func (*DynamicConnectionManager) AddConnection

func (dcm *DynamicConnectionManager) AddConnection(conn *MCPConnection) error

AddConnection adds a new connection to the manager

func (*DynamicConnectionManager) CleanupStaleConnections

func (dcm *DynamicConnectionManager) CleanupStaleConnections(maxAge time.Duration) error

CleanupStaleConnections removes connections that haven't been seen recently

func (*DynamicConnectionManager) GetAllConnections

func (dcm *DynamicConnectionManager) GetAllConnections() map[string]*MCPConnection

GetAllConnections returns all active connections

func (*DynamicConnectionManager) GetConnection

func (dcm *DynamicConnectionManager) GetConnection(serviceName string) (*MCPConnection, error)

GetConnection returns a connection for the specified service

func (*DynamicConnectionManager) GetConnectionStatus

func (dcm *DynamicConnectionManager) GetConnectionStatus() map[string]ConnectionStatus

GetConnectionStatus returns the status of all connections

func (*DynamicConnectionManager) GetConnections

func (dcm *DynamicConnectionManager) GetConnections() []*MCPConnection

GetConnections returns all connections as a slice

func (*DynamicConnectionManager) GetHealthyConnections

func (dcm *DynamicConnectionManager) GetHealthyConnections(maxAge time.Duration) []*MCPConnection

GetHealthyConnections returns connections that are healthy within the given time window

func (*DynamicConnectionManager) OnServiceAdded

func (dcm *DynamicConnectionManager) OnServiceAdded(endpoint ServiceEndpoint)

OnServiceAdded handles service discovery events when a new service is added

func (*DynamicConnectionManager) OnServiceDeleted

func (dcm *DynamicConnectionManager) OnServiceDeleted(serviceName, namespace string)

OnServiceDeleted handles service discovery events when a service is deleted

func (*DynamicConnectionManager) OnServiceModified

func (dcm *DynamicConnectionManager) OnServiceModified(endpoint ServiceEndpoint)

OnServiceModified handles service discovery events when a service is modified

func (*DynamicConnectionManager) RemoveConnection

func (dcm *DynamicConnectionManager) RemoveConnection(name string) error

RemoveConnection removes a connection from the manager

func (*DynamicConnectionManager) Start

func (dcm *DynamicConnectionManager) Start() error

Start begins the connection manager

func (*DynamicConnectionManager) Stop

func (dcm *DynamicConnectionManager) Stop()

Stop stops the connection manager

func (*DynamicConnectionManager) UpdateConnectionStatus

func (dcm *DynamicConnectionManager) UpdateConnectionStatus(name, status string) error

UpdateConnectionStatus updates the status of a connection

type K8sServiceDiscovery

type K8sServiceDiscovery struct {
	Client    kubernetes.Interface // Public for testing
	Namespace string               // Public for testing
	Logger    *logging.Logger      // Public for testing
	// contains filtered or unexported fields
}

K8sServiceDiscovery provides system service discovery for MCP servers

func NewK8sServiceDiscovery

func NewK8sServiceDiscovery(namespace string, logger *logging.Logger) (*K8sServiceDiscovery, error)

NewK8sServiceDiscovery creates a new Kubernetes service discovery instance

func (*K8sServiceDiscovery) AddHandler

func (sd *K8sServiceDiscovery) AddHandler(handler ServiceDiscoveryHandler)

AddHandler adds a service discovery event handler

func (*K8sServiceDiscovery) DiscoverMCPServers

func (sd *K8sServiceDiscovery) DiscoverMCPServers() ([]ServiceEndpoint, error)

DiscoverMCPServers performs an immediate discovery of all MCP servers

func (*K8sServiceDiscovery) DiscoverMCPServices

func (sd *K8sServiceDiscovery) DiscoverMCPServices(ctx context.Context) ([]ServiceEndpoint, error)

DiscoverMCPServices performs an immediate discovery of all MCP services This is an alias for DiscoverMCPServers for API compatibility

func (*K8sServiceDiscovery) DiscoverMCPServicesByCapability

func (sd *K8sServiceDiscovery) DiscoverMCPServicesByCapability(ctx context.Context, capability string) ([]ServiceEndpoint, error)

DiscoverMCPServicesByCapability discovers MCP services filtered by capability

func (*K8sServiceDiscovery) DiscoverMCPServicesByProtocol

func (sd *K8sServiceDiscovery) DiscoverMCPServicesByProtocol(ctx context.Context, protocol string) ([]ServiceEndpoint, error)

DiscoverMCPServicesByProtocol discovers MCP services filtered by protocol

func (*K8sServiceDiscovery) GetService

func (sd *K8sServiceDiscovery) GetService(name string) (ServiceEndpoint, bool)

GetService returns a specific service by name

func (*K8sServiceDiscovery) GetServices

func (sd *K8sServiceDiscovery) GetServices() []ServiceEndpoint

GetServices returns all currently discovered services

func (*K8sServiceDiscovery) Start

func (sd *K8sServiceDiscovery) Start() error

Start begins the service discovery process

func (*K8sServiceDiscovery) Stop

func (sd *K8sServiceDiscovery) Stop()

Stop stops the service discovery process

type MCPConnection

type MCPConnection struct {
	Name            string
	Endpoint        string
	Protocol        string
	Port            int32
	Capabilities    []string
	Status          string
	LastSeen        time.Time
	HTTPConnection  *MCPHTTPConnection
	SSEConnection   *MCPSSEConnection
	StdioConnection *MCPSTDIOConnection
	LastUsed        time.Time
	ErrorCount      int
	// contains filtered or unexported fields
}

MCPConnection represents a connection to an MCP server

type MCPHTTPConnection

type MCPHTTPConnection struct {
	BaseURL  string
	Client   *http.Client
	LastUsed time.Time
}

MCPHTTPConnection represents an HTTP connection

type MCPSSEConnection

type MCPSSEConnection struct {
	BaseURL  string
	Client   *http.Client
	LastUsed time.Time
}

MCPSSEConnection represents an SSE connection

type MCPSTDIOConnection

type MCPSTDIOConnection struct {
	Process  *http.Client // Placeholder
	LastUsed time.Time
}

MCPSTDIOConnection represents a STDIO connection

type ServiceDiscoveryEvent

type ServiceDiscoveryEvent struct {
	Type    string          `json:"type"` // "ADDED", "MODIFIED", "DELETED"
	Service ServiceEndpoint `json:"service"`
}

ServiceDiscoveryEvent represents a service discovery event

type ServiceDiscoveryHandler

type ServiceDiscoveryHandler interface {
	OnServiceAdded(endpoint ServiceEndpoint)
	OnServiceModified(endpoint ServiceEndpoint)
	OnServiceDeleted(serviceName, namespace string)
}

ServiceDiscoveryHandler handles service discovery events

type ServiceEndpoint

type ServiceEndpoint struct {
	Name           string            `json:"name"`
	Namespace      string            `json:"namespace"`
	URL            string            `json:"url"`
	Endpoint       string            `json:"endpoint"` // For compatibility with tests
	Protocol       string            `json:"protocol"`
	Port           int32             `json:"port"`
	Capabilities   []string          `json:"capabilities"`
	Labels         map[string]string `json:"labels"`
	LastDiscovered time.Time         `json:"lastDiscovered"`
	HealthStatus   string            `json:"healthStatus"`
	ServiceType    string            `json:"serviceType"`
}

ServiceEndpoint represents a discovered MCP service endpoint

Jump to

Keyboard shortcuts

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