Documentation
¶
Index ¶
- func IsMCPToolName(name string) bool
- func NormalizeToolName(sourceID, toolName string) string
- func ParseNormalizedToolName(name string) (string, string, bool)
- func RegisterBuiltinTools(getConfig func() *typ.MCPRuntimeConfig, ...) error
- type BaseToolSource
- func (b *BaseToolSource) DisableHealthCheck(ctx context.Context)
- func (b *BaseToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
- func (b *BaseToolSource) GetConnectionState() ConnectionState
- func (b *BaseToolSource) GetConnectionStatus() ConnectionStatus
- func (b *BaseToolSource) GetSourceID() string
- func (b *BaseToolSource) GetType() TransportType
- func (b *BaseToolSource) HealthCheck(ctx context.Context) error
- type ConnectionError
- type ConnectionState
- type ConnectionStatus
- type DefaultErrorClassifier
- type ErrorClassifier
- type ExponentialBackoffStrategy
- type HTTPError
- type HTTPToolSource
- func (s *HTTPToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
- func (s *HTTPToolSource) Connect(ctx context.Context) error
- func (s *HTTPToolSource) DisableHealthCheck(ctx context.Context)
- func (s *HTTPToolSource) Disconnect(ctx context.Context) error
- func (s *HTTPToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
- func (s *HTTPToolSource) GetSourceConfig() interface{}
- func (s *HTTPToolSource) HealthCheck(ctx context.Context) error
- func (s *HTTPToolSource) IsConnected() bool
- func (s *HTTPToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
- func (s *HTTPToolSource) Reconnect(ctx context.Context) error
- type HealthMonitor
- type InvalidToolNameError
- type ReconnectableSource
- type Runtime
- func (r *Runtime) CallTool(ctx context.Context, normalizedName string, arguments string) (string, error)
- func (r *Runtime) Close()
- func (r *Runtime) GetConfig() *typ.MCPRuntimeConfig
- func (r *Runtime) HasServerTools() bool
- func (r *Runtime) ListEnabledServerToolNames(ctx context.Context) map[string]struct{}
- func (r *Runtime) ListOpenAITools(ctx context.Context) []openai.ChatCompletionToolUnionParam
- func (r *Runtime) ListSourceTools(ctx context.Context) (map[string][]SourceTool, error)
- type SSEToolSource
- func (s *SSEToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
- func (s *SSEToolSource) Connect(ctx context.Context) error
- func (s *SSEToolSource) DisableHealthCheck(ctx context.Context)
- func (s *SSEToolSource) Disconnect(ctx context.Context) error
- func (s *SSEToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
- func (s *SSEToolSource) GetSourceConfig() interface{}
- func (s *SSEToolSource) HealthCheck(ctx context.Context) error
- func (s *SSEToolSource) IsConnected() bool
- func (s *SSEToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
- func (s *SSEToolSource) Reconnect(ctx context.Context) error
- type SourceNotFoundError
- type SourceTool
- type StdioToolSource
- func (s *StdioToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
- func (s *StdioToolSource) Connect(ctx context.Context) error
- func (s *StdioToolSource) DisableHealthCheck(ctx context.Context)
- func (s *StdioToolSource) Disconnect(ctx context.Context) error
- func (s *StdioToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
- func (s *StdioToolSource) GetSourceConfig() interface{}
- func (s *StdioToolSource) HealthCheck(ctx context.Context) error
- func (s *StdioToolSource) IsConnected() bool
- func (s *StdioToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
- type ToolDefinition
- type ToolExecutionError
- type ToolSource
- type ToolSourceFactory
- type TransportType
- type UnsupportedTransportError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsMCPToolName ¶
IsMCPToolName checks whether a tool name is a normalized MCP tool.
func NormalizeToolName ¶
NormalizeToolName converts source/tool pair to normalized tool name.
func ParseNormalizedToolName ¶
ParseNormalizedToolName parses normalized name and returns sourceID/toolName.
func RegisterBuiltinTools ¶
func RegisterBuiltinTools(getConfig func() *typ.MCPRuntimeConfig, setConfig func(toolType string, config interface{}) error) error
RegisterBuiltinTools ensures built-in tools are registered in the MCP configuration. If webtools already exists, it updates the command path to use the current binary's absolute path.
Types ¶
type BaseToolSource ¶
type BaseToolSource struct {
// contains filtered or unexported fields
}
BaseToolSource provides common functionality for all tool source implementations.
func NewBaseToolSource ¶
func NewBaseToolSource(sourceID string, transport TransportType) *BaseToolSource
NewBaseToolSource creates a new base tool source.
func (*BaseToolSource) DisableHealthCheck ¶
func (b *BaseToolSource) DisableHealthCheck(ctx context.Context)
DisableHealthCheck provides a default no-op implementation for on-demand connections.
func (*BaseToolSource) EnableHealthCheck ¶
func (b *BaseToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
EnableHealthCheck provides a default no-op implementation for on-demand connections.
func (*BaseToolSource) GetConnectionState ¶
func (b *BaseToolSource) GetConnectionState() ConnectionState
GetConnectionState returns the current connection state.
func (*BaseToolSource) GetConnectionStatus ¶
func (b *BaseToolSource) GetConnectionStatus() ConnectionStatus
GetConnectionStatus returns the current connection status.
func (*BaseToolSource) GetSourceID ¶
func (b *BaseToolSource) GetSourceID() string
GetSourceID returns the source ID.
func (*BaseToolSource) GetType ¶
func (b *BaseToolSource) GetType() TransportType
GetType returns the transport type.
func (*BaseToolSource) HealthCheck ¶
func (b *BaseToolSource) HealthCheck(ctx context.Context) error
HealthCheck provides a default no-op health check for on-demand connections.
type ConnectionError ¶
ConnectionError represents a connection-related error.
func (*ConnectionError) Error ¶
func (e *ConnectionError) Error() string
type ConnectionState ¶
type ConnectionState string
ConnectionState represents the current state of a tool source connection.
const ( StateDisconnected ConnectionState = "disconnected" StateConnecting ConnectionState = "connecting" StateConnected ConnectionState = "connected" StateError ConnectionState = "error" )
type ConnectionStatus ¶
type ConnectionStatus struct {
State ConnectionState `json:"state"`
LastConnected time.Time `json:"last_connected,omitempty"`
LastError error `json:"last_error,omitempty"`
RetryCount int `json:"retry_count,omitempty"`
}
ConnectionStatus represents the current status of a tool source connection.
type DefaultErrorClassifier ¶
type DefaultErrorClassifier struct{}
DefaultErrorClassifier provides default error classification.
func (*DefaultErrorClassifier) IsPermanent ¶
func (c *DefaultErrorClassifier) IsPermanent(err error) bool
IsPermanent checks if an error is permanent (auth failures, not found, etc.).
func (*DefaultErrorClassifier) IsTransient ¶
func (c *DefaultErrorClassifier) IsTransient(err error) bool
IsTransient checks if an error is transient (temporary network issues, timeouts, etc.).
type ErrorClassifier ¶
ErrorClassifier classifies errors as transient or permanent.
type ExponentialBackoffStrategy ¶
type ExponentialBackoffStrategy struct {
InitialInterval time.Duration
MaxInterval time.Duration
Multiplier float64
MaxRetries int
}
ExponentialBackoffStrategy implements exponential backoff with jitter.
func NewExponentialBackoffStrategy ¶
func NewExponentialBackoffStrategy() *ExponentialBackoffStrategy
NewExponentialBackoffStrategy creates a new exponential backoff strategy.
func (*ExponentialBackoffStrategy) NextRetry ¶
func (s *ExponentialBackoffStrategy) NextRetry(retryCount int) time.Duration
NextRetry returns the duration to wait before the next retry.
func (*ExponentialBackoffStrategy) ShouldRetry ¶
func (s *ExponentialBackoffStrategy) ShouldRetry(retryCount int) bool
ShouldRetry determines if another retry should be attempted.
type HTTPToolSource ¶
type HTTPToolSource struct {
*BaseToolSource
// contains filtered or unexported fields
}
HTTPToolSource implements ToolSource for HTTP-based MCP servers. This is a persistent connection type with health monitoring.
func NewHTTPToolSource ¶
func NewHTTPToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*HTTPToolSource, error)
NewHTTPToolSource creates a new HTTP tool source.
func (*HTTPToolSource) CallTool ¶
func (s *HTTPToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
CallTool executes a tool from the HTTP MCP server.
func (*HTTPToolSource) Connect ¶
func (s *HTTPToolSource) Connect(ctx context.Context) error
Connect establishes an HTTP connection to the MCP server.
func (*HTTPToolSource) DisableHealthCheck ¶
func (s *HTTPToolSource) DisableHealthCheck(ctx context.Context)
DisableHealthCheck stops health monitoring.
func (*HTTPToolSource) Disconnect ¶
func (s *HTTPToolSource) Disconnect(ctx context.Context) error
Disconnect closes the HTTP connection.
func (*HTTPToolSource) EnableHealthCheck ¶
func (s *HTTPToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
EnableHealthCheck starts periodic health monitoring.
func (*HTTPToolSource) GetSourceConfig ¶
func (s *HTTPToolSource) GetSourceConfig() interface{}
GetSourceConfig returns the source configuration.
func (*HTTPToolSource) HealthCheck ¶
func (s *HTTPToolSource) HealthCheck(ctx context.Context) error
HealthCheck verifies the HTTP connection is still active.
func (*HTTPToolSource) IsConnected ¶
func (s *HTTPToolSource) IsConnected() bool
IsConnected returns whether the HTTP connection is active.
func (*HTTPToolSource) ListTools ¶
func (s *HTTPToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
ListTools returns all tools from the HTTP MCP server.
type HealthMonitor ¶
type HealthMonitor struct {
// contains filtered or unexported fields
}
HealthMonitor provides health monitoring for persistent connections.
func NewHealthMonitor ¶
func NewHealthMonitor(source ToolSource, errorClassifier ErrorClassifier) *HealthMonitor
NewHealthMonitor creates a new health monitor.
func (*HealthMonitor) Start ¶
func (h *HealthMonitor) Start(ctx context.Context, interval time.Duration)
Start begins health monitoring with the specified interval.
func (*HealthMonitor) Stop ¶
func (h *HealthMonitor) Stop(ctx context.Context)
Stop stops health monitoring.
type InvalidToolNameError ¶
type InvalidToolNameError struct {
Name string
}
InvalidToolNameError indicates an invalid tool name.
func (*InvalidToolNameError) Error ¶
func (e *InvalidToolNameError) Error() string
type ReconnectableSource ¶
type ReconnectableSource interface {
ToolSource
Reconnect(ctx context.Context) error
}
ReconnectableSource extends ToolSource with reconnection capability.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime handles MCP tool source discovery and tool execution.
func NewRuntime ¶
func NewRuntime(getConfig configProvider) *Runtime
NewRuntime creates a new MCP runtime.
func (*Runtime) CallTool ¶
func (r *Runtime) CallTool(ctx context.Context, normalizedName string, arguments string) (string, error)
CallTool executes a normalized MCP tool call and returns serialized result.
func (*Runtime) Close ¶
func (r *Runtime) Close()
Close releases all MCP sessions and tool source connections.
func (*Runtime) GetConfig ¶
func (r *Runtime) GetConfig() *typ.MCPRuntimeConfig
GetConfig returns the current MCP runtime configuration.
func (*Runtime) HasServerTools ¶
HasServerTools returns true if there are any server tools configured
func (*Runtime) ListEnabledServerToolNames ¶
ListEnabledServerToolNames returns normalized MCP tool names from enabled server-tool sources. Results are cached with a short TTL to avoid repeated full source enumeration.
func (*Runtime) ListOpenAITools ¶
func (r *Runtime) ListOpenAITools(ctx context.Context) []openai.ChatCompletionToolUnionParam
ListOpenAITools returns all MCP tools in normalized OpenAI function-tool format.
func (*Runtime) ListSourceTools ¶
ListSourceTools returns all MCP tools grouped by source with their original names. This is used by local mode to expose tools to external MCP clients.
type SSEToolSource ¶
type SSEToolSource struct {
*BaseToolSource
// contains filtered or unexported fields
}
SSEToolSource implements ToolSource for SSE-based MCP servers. This is a persistent connection type with health monitoring.
func NewSSEToolSource ¶
func NewSSEToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*SSEToolSource, error)
NewSSEToolSource creates a new SSE tool source.
func (*SSEToolSource) CallTool ¶
func (s *SSEToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
CallTool executes a tool from the SSE MCP server.
func (*SSEToolSource) Connect ¶
func (s *SSEToolSource) Connect(ctx context.Context) error
Connect establishes an SSE connection to the MCP server.
func (*SSEToolSource) DisableHealthCheck ¶
func (s *SSEToolSource) DisableHealthCheck(ctx context.Context)
DisableHealthCheck stops health monitoring.
func (*SSEToolSource) Disconnect ¶
func (s *SSEToolSource) Disconnect(ctx context.Context) error
Disconnect closes the SSE connection.
func (*SSEToolSource) EnableHealthCheck ¶
func (s *SSEToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
EnableHealthCheck starts periodic health monitoring.
func (*SSEToolSource) GetSourceConfig ¶
func (s *SSEToolSource) GetSourceConfig() interface{}
GetSourceConfig returns the source configuration.
func (*SSEToolSource) HealthCheck ¶
func (s *SSEToolSource) HealthCheck(ctx context.Context) error
HealthCheck verifies the SSE connection is still active.
func (*SSEToolSource) IsConnected ¶
func (s *SSEToolSource) IsConnected() bool
IsConnected returns whether the SSE connection is active.
func (*SSEToolSource) ListTools ¶
func (s *SSEToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
ListTools returns all tools from the SSE MCP server.
type SourceNotFoundError ¶
type SourceNotFoundError struct {
ID string
}
SourceNotFoundError indicates that a source was not found.
func (*SourceNotFoundError) Error ¶
func (e *SourceNotFoundError) Error() string
type SourceTool ¶
type SourceTool struct {
SourceID string
SourceName string
Name string
Description string
InputSchema json.RawMessage
}
SourceTool represents a tool from a specific MCP source with its original name.
type StdioToolSource ¶
type StdioToolSource struct {
*BaseToolSource
// contains filtered or unexported fields
}
StdioToolSource implements ToolSource for stdio-based MCP servers. This is an on-demand connection type - the subprocess is started when needed.
func NewStdioToolSource ¶
func NewStdioToolSource(sourceConfig typ.MCPSourceConfig, sc *sessionCache) (*StdioToolSource, error)
NewStdioToolSource creates a new stdio tool source.
func (*StdioToolSource) CallTool ¶
func (s *StdioToolSource) CallTool(ctx context.Context, toolName string, arguments string) (string, error)
CallTool executes a tool from the stdio MCP server.
func (*StdioToolSource) Connect ¶
func (s *StdioToolSource) Connect(ctx context.Context) error
Connect establishes a stdio connection to the MCP server.
func (*StdioToolSource) DisableHealthCheck ¶
func (s *StdioToolSource) DisableHealthCheck(ctx context.Context)
DisableHealthCheck is a no-op for on-demand connections.
func (*StdioToolSource) Disconnect ¶
func (s *StdioToolSource) Disconnect(ctx context.Context) error
Disconnect closes the stdio connection. For stdio, this terminates the subprocess.
func (*StdioToolSource) EnableHealthCheck ¶
func (s *StdioToolSource) EnableHealthCheck(ctx context.Context, interval time.Duration)
EnableHealthCheck is a no-op for on-demand connections.
func (*StdioToolSource) GetSourceConfig ¶
func (s *StdioToolSource) GetSourceConfig() interface{}
GetSourceConfig returns the source configuration.
func (*StdioToolSource) HealthCheck ¶
func (s *StdioToolSource) HealthCheck(ctx context.Context) error
HealthCheck verifies the stdio connection is still active.
func (*StdioToolSource) IsConnected ¶
func (s *StdioToolSource) IsConnected() bool
IsConnected returns whether the stdio connection is active.
func (*StdioToolSource) ListTools ¶
func (s *StdioToolSource) ListTools(ctx context.Context) ([]ToolDefinition, error)
ListTools returns all tools from the stdio MCP server.
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema,omitempty"`
}
ToolDefinition represents a tool's metadata and schema.
type ToolExecutionError ¶
ToolExecutionError represents an error during tool execution.
func (*ToolExecutionError) Error ¶
func (e *ToolExecutionError) Error() string
type ToolSource ¶
type ToolSource interface {
// Connection management
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
IsConnected() bool
GetConnectionState() ConnectionState
GetConnectionStatus() ConnectionStatus
// Tool operations
ListTools(ctx context.Context) ([]ToolDefinition, error)
CallTool(ctx context.Context, toolName string, arguments string) (string, error)
// Health monitoring (for persistent connections)
HealthCheck(ctx context.Context) error
EnableHealthCheck(ctx context.Context, interval time.Duration)
DisableHealthCheck(ctx context.Context)
// Metadata
GetType() TransportType
GetSourceID() string
GetSourceConfig() interface{} // Returns source-specific config
}
ToolSource is the unified interface for all MCP tool sources. All transport types (stdio, http, sse, builtin) implement this interface.
type ToolSourceFactory ¶
type ToolSourceFactory struct {
// contains filtered or unexported fields
}
ToolSourceFactory creates tool sources based on configuration.
func NewToolSourceFactory ¶
func NewToolSourceFactory(sc *sessionCache) *ToolSourceFactory
NewToolSourceFactory creates a new tool source factory.
func (*ToolSourceFactory) CreateToolSource ¶
func (f *ToolSourceFactory) CreateToolSource(sourceConfig typ.MCPSourceConfig) (ToolSource, error)
CreateToolSource creates a tool source based on the transport type.
type TransportType ¶
type TransportType string
TransportType represents the type of transport for a tool source.
const ( TransportStdio TransportType = "stdio" TransportHTTP TransportType = "http" TransportSSE TransportType = "sse" )
type UnsupportedTransportError ¶
type UnsupportedTransportError struct {
Transport string
}
UnsupportedTransportError indicates an unsupported transport type.
func (*UnsupportedTransportError) Error ¶
func (e *UnsupportedTransportError) Error() string