client

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package client provides utilities for managing client configurations and interacting with MCP servers.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrConfigFileNotFound is returned when a client configuration file is not found
	ErrConfigFileNotFound = fmt.Errorf("client config file not found")
	// ErrUnsupportedClientType is returned when an unsupported client type is provided
	ErrUnsupportedClientType = fmt.Errorf("unsupported client type")
)

Functions

func CheckAndPerformAutoDiscoveryMigration added in v0.1.0

func CheckAndPerformAutoDiscoveryMigration()

CheckAndPerformAutoDiscoveryMigration checks if auto-discovery migration is needed and performs it This is called once at application startup

func GetClientDescription added in v0.9.2

func GetClientDescription(clientType MCPClient) string

GetClientDescription returns the description for a given client type. Returns an empty string if the client type is not found.

func GetClientListCSV added in v0.9.2

func GetClientListCSV() string

GetClientListCSV returns a comma-separated list of all supported client types, sorted alphabetically. This is suitable for use in error messages.

func GetClientListFormatted added in v0.9.2

func GetClientListFormatted() string

GetClientListFormatted returns a formatted multi-line string listing all supported clients with their descriptions, sorted alphabetically. This is suitable for use in CLI help text.

func IsValidClient added in v0.9.2

func IsValidClient(clientType string) bool

IsValidClient checks if the provided client type is supported.

func Upsert added in v0.0.32

func Upsert(cf ConfigFile, name string, url string, transportType string) error

Upsert updates/inserts an MCP server in a client configuration file It is a wrapper around the ConfigUpdater.Upsert method. Because the ConfigUpdater is different for each client type, we need to handle the different types of McpServer objects. For example, VSCode and ClaudeCode allows for a `type` field, but Cursor and others do not. This allows us to build up more complex MCP server configurations for different clients without leaking them into the CMD layer.

Types

type Client added in v0.0.43

type Client struct {
	Name MCPClient `json:"name"`
}

Client represents a registered ToolHive client.

type ClientManager added in v0.2.14

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

ClientManager encapsulates dependencies for client operations

func NewClientManager added in v0.2.14

func NewClientManager() (*ClientManager, error)

NewClientManager creates a new ClientManager with default dependencies

func NewTestClientManager added in v0.2.14

func NewTestClientManager(
	homeDir string,
	groupManager groups.Manager,
	clientIntegrations []mcpClientConfig,
	configProvider config.Provider,
) *ClientManager

NewTestClientManager creates a new ClientManager with test dependencies

func (*ClientManager) CreateClientConfig added in v0.2.14

func (cm *ClientManager) CreateClientConfig(clientType MCPClient) (*ConfigFile, error)

CreateClientConfig creates a new client configuration file for a given client type using this manager's dependencies.

func (*ClientManager) FindClientConfig added in v0.2.14

func (cm *ClientManager) FindClientConfig(clientType MCPClient) (*ConfigFile, error)

FindClientConfig returns the client configuration file for a given client type using this manager's dependencies.

func (*ClientManager) FindRegisteredClientConfigs added in v0.2.14

func (cm *ClientManager) FindRegisteredClientConfigs(ctx context.Context) ([]ConfigFile, error)

FindRegisteredClientConfigs finds all registered client configs using this manager's dependencies

func (*ClientManager) GetClientStatus added in v0.2.14

func (cm *ClientManager) GetClientStatus(ctx context.Context) ([]MCPClientStatus, error)

GetClientStatus returns the status of all supported MCP clients using this manager's dependencies

func (*ClientManager) Upsert added in v0.2.14

func (cm *ClientManager) Upsert(cf ConfigFile, name string, url string, transportType string) error

Upsert updates/inserts an MCP server in a client configuration file using this manager's dependencies.

type ConfigFile

type ConfigFile struct {
	Path          string
	ClientType    MCPClient
	ConfigUpdater ConfigUpdater
	Extension     Extension
}

ConfigFile represents a client configuration file

func CreateClientConfig added in v0.1.0

func CreateClientConfig(clientType MCPClient) (*ConfigFile, error)

CreateClientConfig creates a new client configuration file for a given client type.

func FindClientConfig added in v0.0.43

func FindClientConfig(clientType MCPClient) (*ConfigFile, error)

FindClientConfig returns the client configuration file for a given client type.

func FindRegisteredClientConfigs added in v0.1.3

func FindRegisteredClientConfigs(ctx context.Context) ([]ConfigFile, error)

FindRegisteredClientConfigs finds all registered client configs and creates them if they don't exist.

type ConfigUpdater added in v0.0.32

type ConfigUpdater interface {
	// Upsert inserts or updates an MCP server configuration.
	// Returns an error if the operation fails (file read/write, parsing, marshaling).
	Upsert(serverName string, data MCPServer) error

	// Remove removes an MCP server configuration.
	// Returns nil if the server doesn't exist (idempotent).
	// Returns an error only for actual failures (file read/write, parsing).
	Remove(serverName string) error
}

ConfigUpdater defines the interface for types which can edit MCP client config files. All methods return errors rather than handling them internally, allowing callers to determine the appropriate response (fatal error, warning, or ignore) based on context. See the package-level documentation for details on error handling patterns.

type Extension added in v0.0.32

type Extension string

Extension is extension of the client config file.

const (
	// JSON represents a JSON extension.
	JSON Extension = "json"
	// YAML represents a YAML extension.
	YAML Extension = "yaml"
	// TOML represents a TOML extension.
	TOML Extension = "toml"
)

type GenericYAMLConverter added in v0.4.0

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

GenericYAMLConverter implements YAMLConverter using configuration from mcpClientConfig

func NewGenericYAMLConverter added in v0.4.0

func NewGenericYAMLConverter(cfg *mcpClientConfig) *GenericYAMLConverter

NewGenericYAMLConverter creates a converter from mcpClientConfig

func (*GenericYAMLConverter) ConvertFromMCPServer added in v0.4.0

func (g *GenericYAMLConverter) ConvertFromMCPServer(serverName string, server MCPServer) (interface{}, error)

ConvertFromMCPServer converts an MCPServer to the appropriate format based on configuration

func (*GenericYAMLConverter) RemoveEntry added in v0.4.0

func (g *GenericYAMLConverter) RemoveEntry(config interface{}, serverName string) error

RemoveEntry removes an entry based on storage type

func (*GenericYAMLConverter) UpsertEntry added in v0.4.0

func (g *GenericYAMLConverter) UpsertEntry(config interface{}, serverName string, entry interface{}) error

UpsertEntry adds or updates an entry based on storage type (map or array)

type JSONConfigUpdater added in v0.0.32

type JSONConfigUpdater struct {
	Path                 string
	MCPServersPathPrefix string
}

JSONConfigUpdater is a ConfigUpdater that is responsible for updating JSON config files.

func (*JSONConfigUpdater) Remove added in v0.0.32

func (jcu *JSONConfigUpdater) Remove(serverName string) error

Remove removes an MCP server from the MCP client config file

func (*JSONConfigUpdater) Upsert added in v0.0.32

func (jcu *JSONConfigUpdater) Upsert(serverName string, data MCPServer) error

Upsert inserts or updates an MCP server in the MCP client config file

type MCPClient

type MCPClient string

MCPClient is an enum of supported MCP clients.

const (
	// RooCode represents the Roo Code extension for VS Code.
	RooCode MCPClient = "roo-code"
	// Cline represents the Cline extension for VS Code.
	Cline MCPClient = "cline"
	// Cursor represents the Cursor editor.
	Cursor MCPClient = "cursor"
	// VSCodeInsider represents the VS Code Insiders editor.
	VSCodeInsider MCPClient = "vscode-insider"
	// VSCode represents the standard VS Code editor.
	VSCode MCPClient = "vscode"
	// ClaudeCode represents the Claude Code CLI.
	ClaudeCode MCPClient = "claude-code"
	// Windsurf represents the Windsurf IDE.
	Windsurf MCPClient = "windsurf"
	// WindsurfJetBrains represents the Windsurf plugin for JetBrains.
	WindsurfJetBrains MCPClient = "windsurf-jetbrains"
	// AmpCli represents the Sourcegraph Amp CLI.
	AmpCli MCPClient = "amp-cli"
	// AmpVSCode represents the Sourcegraph Amp extension for VS Code.
	AmpVSCode MCPClient = "amp-vscode"
	// AmpCursor represents the Sourcegraph Amp extension for Cursor.
	AmpCursor MCPClient = "amp-cursor"
	// AmpVSCodeInsider represents the Sourcegraph Amp extension for VS Code Insiders.
	AmpVSCodeInsider MCPClient = "amp-vscode-insider"
	// AmpWindsurf represents the Sourcegraph Amp extension for Windsurf.
	AmpWindsurf MCPClient = "amp-windsurf"
	// LMStudio represents the LM Studio application.
	LMStudio MCPClient = "lm-studio"
	// Goose represents the Goose AI agent.
	Goose MCPClient = "goose"
	// Trae represents the Trae IDE.
	Trae MCPClient = "trae"
	// Continue represents the Continue.dev IDE plugins.
	Continue MCPClient = "continue"
	// OpenCode represents the OpenCode editor.
	OpenCode MCPClient = "opencode"
	// Kiro represents the Kiro AI IDE.
	Kiro MCPClient = "kiro"
	// Antigravity represents the Google Antigravity IDE.
	Antigravity MCPClient = "antigravity"
	// Zed represents the Zed editor.
	Zed MCPClient = "zed"
	// GeminiCli represents the Google Gemini CLI.
	GeminiCli MCPClient = "gemini-cli"
	// VSCodeServer represents Microsoft's VS Code Server (remote development).
	VSCodeServer MCPClient = "vscode-server"
	// MistralVibe represents the Mistral Vibe IDE.
	MistralVibe MCPClient = "mistral-vibe"
	// Codex represents the OpenAI Codex CLI.
	Codex MCPClient = "codex"
)

func GetAllClients added in v0.9.2

func GetAllClients() []MCPClient

GetAllClients returns a slice of all supported MCP client types, sorted alphabetically. This is the single source of truth for valid client types.

type MCPClientStatus added in v0.0.41

type MCPClientStatus struct {
	// ClientType is the type of MCP client
	ClientType MCPClient `json:"client_type"`

	// Installed indicates whether the client is installed on the system
	Installed bool `json:"installed"`

	// Registered indicates whether the client is registered in the ToolHive configuration
	Registered bool `json:"registered"`
}

MCPClientStatus represents the status of a supported MCP client

func GetClientStatus added in v0.0.41

func GetClientStatus(ctx context.Context) ([]MCPClientStatus, error)

GetClientStatus returns the status of all supported MCP clients using the default config provider

type MCPServer added in v0.0.32

type MCPServer struct {
	Url       string `json:"url,omitempty"`
	ServerUrl string `json:"serverUrl,omitempty"`
	HttpUrl   string `json:"httpUrl,omitempty"`
	Uri       string `json:"uri,omitempty"`
	Type      string `json:"type,omitempty"`
}

MCPServer represents an MCP server in a MCP client config file

type MCPServerConfig

type MCPServerConfig struct {
	URL string `json:"url,omitempty"`
}

MCPServerConfig represents an MCP server configuration in a client config file

type Manager added in v0.0.43

type Manager interface {
	// ListClients returns a list of all registered clients with their group information.
	ListClients(ctx context.Context) ([]RegisteredClient, error)
	// RegisterClients registers multiple clients with ToolHive for the specified workloads.
	RegisterClients(clients []Client, workloads []core.Workload) error
	// UnregisterClients unregisters multiple clients from ToolHive for the specified workloads.
	UnregisterClients(ctx context.Context, clients []Client, workloads []core.Workload) error
	// AddServerToClients adds an MCP server to the appropriate client configurations.
	AddServerToClients(ctx context.Context, serverName, serverURL, transportType, group string) error
	// RemoveServerFromClients removes an MCP server from the appropriate client configurations.
	RemoveServerFromClients(ctx context.Context, serverName, group string) error
}

Manager is the interface for managing registered ToolHive clients.

func NewManager added in v0.0.43

func NewManager(ctx context.Context) (Manager, error)

NewManager creates a new client manager instance.

func NewManagerWithProvider added in v0.2.16

func NewManagerWithProvider(ctx context.Context, configProvider config.Provider) (Manager, error)

NewManagerWithProvider creates a new client manager instance with a custom config provider. This is useful for testing to avoid using the singleton config.

type RegisteredClient added in v0.2.8

type RegisteredClient struct {
	Name   MCPClient `json:"name"`
	Groups []string  `json:"groups"`
}

RegisteredClient represents a registered client with its associated groups.

type TOMLConfigUpdater added in v0.9.2

type TOMLConfigUpdater struct {
	Path            string
	ServersKey      string // The TOML array key (e.g., "mcp_servers")
	IdentifierField string // The field name used to identify servers (e.g., "name")
	URLField        string // The field name for URL (e.g., "url")
}

TOMLConfigUpdater is a ConfigUpdater that is responsible for updating TOML config files with array-of-tables format (used by Mistral Vibe).

func (*TOMLConfigUpdater) Remove added in v0.9.2

func (tcu *TOMLConfigUpdater) Remove(serverName string) error

Remove removes an MCP server from the TOML config file

func (*TOMLConfigUpdater) Upsert added in v0.9.2

func (tcu *TOMLConfigUpdater) Upsert(serverName string, data MCPServer) error

Upsert inserts or updates an MCP server in the TOML config file

type TOMLMapConfigUpdater added in v0.9.2

type TOMLMapConfigUpdater struct {
	Path       string
	ServersKey string // The TOML section key (e.g., "mcp_servers")
	URLField   string // The field name for URL (e.g., "url")
}

TOMLMapConfigUpdater is a ConfigUpdater that is responsible for updating TOML config files with nested tables format [section.servername] (used by Codex).

func (*TOMLMapConfigUpdater) Remove added in v0.9.2

func (tmu *TOMLMapConfigUpdater) Remove(serverName string) error

Remove removes an MCP server from the TOML config file

func (*TOMLMapConfigUpdater) Upsert added in v0.9.2

func (tmu *TOMLMapConfigUpdater) Upsert(serverName string, data MCPServer) error

Upsert inserts or updates an MCP server in the TOML config file using map format

type TOMLStorageType added in v0.9.2

type TOMLStorageType string

TOMLStorageType represents how servers are stored in TOML configuration files.

const (
	// TOMLStorageTypeMap represents servers stored as nested tables [section.servername].
	// Example: [mcp_servers.myserver]
	TOMLStorageTypeMap TOMLStorageType = "map"
	// TOMLStorageTypeArray represents servers stored as array of tables [[section]].
	// Example: [[mcp_servers]]
	TOMLStorageTypeArray TOMLStorageType = "array"
)

type YAMLConfigUpdater added in v0.2.16

type YAMLConfigUpdater struct {
	Path      string
	Converter YAMLConverter
}

YAMLConfigUpdater is a ConfigUpdater that is responsible for updating YAML config files using a converter interface for flexibility.

func (*YAMLConfigUpdater) Remove added in v0.2.16

func (ycu *YAMLConfigUpdater) Remove(serverName string) error

Remove removes an entry from the config.yaml file using the converter

func (*YAMLConfigUpdater) Upsert added in v0.2.16

func (ycu *YAMLConfigUpdater) Upsert(serverName string, data MCPServer) error

Upsert inserts or updates an MCP server in the config.yaml file using the converter

type YAMLConverter added in v0.2.16

type YAMLConverter interface {
	ConvertFromMCPServer(serverName string, server MCPServer) (interface{}, error)
	UpsertEntry(config interface{}, serverName string, entry interface{}) error
	RemoveEntry(config interface{}, serverName string) error
}

YAMLConverter defines an interface for converting MCPServer data to different YAML config formats

type YAMLStorageType added in v0.4.0

type YAMLStorageType string

YAMLStorageType represents how servers are stored in YAML configuration files.

const (
	// YAMLStorageTypeMap represents servers stored as a map with server names as keys.
	YAMLStorageTypeMap YAMLStorageType = "map"
	// YAMLStorageTypeArray represents servers stored as an array of objects.
	YAMLStorageTypeArray YAMLStorageType = "array"
)

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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