manager

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package manager provides the ConnectionManager implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

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

ConnectionManager handles the lifecycle of remote MCP connections. It maintains two types of state:

1. Runtime State (in memory):

  • Active connections to remote servers
  • Currently available tools and their handlers
  • Connection health states

2. Persistent State (in database through events):

  • Configured server list
  • Tool registrations
  • Server health status

func New

func New(
	cfg config.ServerConfig,
	logger log.Logger,
	eventBus events.Bus,
	mcpServer *server.MCPServer,
	connectionsTotal *prometheus.GaugeVec,
	toolsTotal *prometheus.GaugeVec,
	toolSyncLatency *prometheus.HistogramVec,
) *ConnectionManager

New creates a new ConnectionManager instance

func (*ConnectionManager) ConnectWithRetry

func (cm *ConnectionManager) ConnectWithRetry(remote config.RemoteMCPServer)

ConnectWithRetry attempts to connect to a remote server with exponential backoff

func (*ConnectionManager) GetConnectionState

func (cm *ConnectionManager) GetConnectionState(url string) models.ConnectionState

GetConnectionState gets the current state of a connection

func (*ConnectionManager) GetToolHandlers

func (cm *ConnectionManager) GetToolHandlers() map[string]*tools.RemoteToolInfo

GetToolHandlers returns the tool handlers map (used by function closures)

func (*ConnectionManager) HandleServerAdded

func (cm *ConnectionManager) HandleServerAdded(event events.Event)

HandleServerAdded handles the ServerAdded event

func (*ConnectionManager) HandleServerRemoved

func (cm *ConnectionManager) HandleServerRemoved(event events.Event)

HandleServerRemoved handles the ServerRemoved event

func (*ConnectionManager) HandleToolsProcessed

func (cm *ConnectionManager) HandleToolsProcessed(event events.Event)

HandleToolsProcessed handles the ToolsProcessedInDB event

func (*ConnectionManager) RefreshMCPServerTools

func (cm *ConnectionManager) RefreshMCPServerTools()

RefreshMCPServerTools rebuilds the runtime tool state. IMPORTANT: This function assumes the caller holds the cm.mu lock.

func (*ConnectionManager) SetConnectionState

func (cm *ConnectionManager) SetConnectionState(url string, state models.ConnectionState)

SetConnectionState updates both runtime and persistent connection state

func (*ConnectionManager) Start

func (cm *ConnectionManager) Start()

Start begins managing connections and health checks

func (*ConnectionManager) Stop

func (cm *ConnectionManager) Stop()

Stop gracefully shuts down all connections

func (*ConnectionManager) UpdateServerTools

func (cm *ConnectionManager) UpdateServerTools(serverURL string, fetchedTools interface{})

UpdateServerTools synchronizes tool state between runtime and persistent storage

Jump to

Keyboard shortcuts

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