mcp

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMCPNotInitialized MCP manager not initialized
	ErrMCPNotInitialized = errors.New("MCP manager not initialized")

	// ErrServerNotFound MCP server not found
	ErrServerNotFound = errors.New("MCP server not found")

	// ErrToolNotFound MCP tool not found
	ErrToolNotFound = errors.New("MCP tool not found")

	// ErrInvalidConfig Invalid MCP configuration
	ErrInvalidConfig = errors.New("Invalid MCP configuration")

	// ErrConnectionFailed MCP connection failed
	ErrConnectionFailed = errors.New("MCP connection failed")
)

MCP related error definitions

Functions

func CloseGlobalManager

func CloseGlobalManager() error

CloseGlobalManager closes the global MCP manager

func GetAgentMCPServers

func GetAgentMCPServers(cfg *config.Config, agentName string) ([]string, error)

GetAgentMCPServers gets MCP server list for specified agent

func GetServerConfig

func GetServerConfig(cfg *config.Config, serverName string) (*config.MCPServer, error)

GetServerConfig gets configuration for specified server

func InitializeGlobalManager

func InitializeGlobalManager(ctx context.Context, cfg *config.Config) error

InitializeGlobalManager initializes the global MCP manager

func IsConfigError

func IsConfigError(err error) bool

IsConfigError checks if it's a configuration error

func IsConnectionError

func IsConnectionError(err error) bool

IsConnectionError checks if it's a connection error

func ShortError added in v0.5.1

func ShortError(err error) string

ShortError renders the innermost cause of an error chain on a single line.

MCP wraps failures several layers deep ("MCP error [initialize] server:grep - failed to discover ... : net/http: TLS handshake timeout"); a user-facing notice only needs the part that says what actually went wrong, and a TUI transcript needs it without embedded newlines.

func ValidateConfig

func ValidateConfig(cfg *config.Config) error

ValidateConfig validates a complete MCP configuration, including every server's own settings. It answers "is this configuration correct?".

Runtime initialization deliberately does not use it: Client.Initialize validates per server so one broken or unreachable entry cannot block the servers that work. Use ValidateConfig for diagnostics and configuration editing, not as a gate in front of connecting.

Types

type Client

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

Client MCP client structure

func NewClient

func NewClient(cfg *config.Config) *Client

NewClient creates a new MCP client

func (*Client) Close

func (c *Client) Close() error

Close closes all MCP client connections

func (*Client) GetTools

func (c *Client) GetTools() map[string]tool.InvokableTool

GetTools gets all available MCP tools

func (*Client) GetToolsForServers

func (c *Client) GetToolsForServers(serverNames []string) map[string]tool.InvokableTool

GetToolsForServers gets tools from specified MCP servers

func (*Client) Initialize

func (c *Client) Initialize(ctx context.Context) error

Initialize initializes the MCP client.

Servers are set up one by one. A server that cannot be reached (a dead endpoint, a TLS handshake timeout, a missing command) is recorded in ServerErrors and skipped, so its failure never removes the tools of the servers that do work. An error is returned only when nothing is left to use, which keeps a fully broken configuration visible.

func (*Client) ServerErrors added in v0.5.1

func (c *Client) ServerErrors() map[string]error

ServerErrors returns the servers that could not be initialized, mapped to the reason. An empty map means every configured server is usable.

func (*Client) ToolCountsByServer added in v0.2.0

func (c *Client) ToolCountsByServer() map[string]int

ToolCountsByServer returns the number of discovered tools per server.

type MCPError

type MCPError struct {
	Op     string // Operation name
	Server string // Server name
	Tool   string // Tool name
	Err    error  // Original error
}

MCPError MCP error wrapper

func NewMCPError

func NewMCPError(op, server, tool string, err error) *MCPError

NewMCPError creates new MCP error

func (*MCPError) Error

func (e *MCPError) Error() string

Error implements error interface

func (*MCPError) Unwrap

func (e *MCPError) Unwrap() error

Unwrap returns original error

type Manager

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

Manager MCP manager, responsible for managing all MCP clients and tools

func GetGlobalManager

func GetGlobalManager() *Manager

GetGlobalManager gets the global MCP manager

func NewManager

func NewManager(cfg *config.Config) *Manager

NewManager creates a new MCP manager

func WaitGlobalManager added in v0.5.1

func WaitGlobalManager(ctx context.Context) *Manager

WaitGlobalManager waits until the global manager exists and its background initialization finished, then returns it. It returns nil when ctx ends first, which lets a front-end proceed with built-in tools only.

Callers surface the result through their own interface: while a TUI owns the terminal, writing the outcome to stderr would paint over the frame.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the MCP manager

func (*Manager) Done added in v0.5.1

func (m *Manager) Done() <-chan struct{}

Done is closed when initialization finished, successfully or not.

func (*Manager) GetAllTools

func (m *Manager) GetAllTools() map[string]tool.InvokableTool

GetAllTools gets all MCP tools

func (*Manager) GetToolsForAgent

func (m *Manager) GetToolsForAgent(agentName string) ([]tool.InvokableTool, error)

GetToolsForAgent gets MCP tools for specified agent

func (*Manager) Initialize

func (m *Manager) Initialize(ctx context.Context) error

Initialize initializes the MCP manager

func (*Manager) ServerErrors added in v0.5.1

func (m *Manager) ServerErrors() map[string]error

ServerErrors returns the servers that could not be initialized and why. An empty map means every configured server is usable this session.

func (*Manager) ToolCountsByServer added in v0.2.0

func (m *Manager) ToolCountsByServer() map[string]int

ToolCountsByServer returns the number of discovered tools per server. It reports an empty map when the manager has not been initialized.

Directories

Path Synopsis
Package mcpserver exposes Oni3 agent tools through the Model Context Protocol.
Package mcpserver exposes Oni3 agent tools through the Model Context Protocol.

Jump to

Keyboard shortcuts

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