Documentation
ΒΆ
Overview ΒΆ
pkg/tools/func.go
Index ΒΆ
- func NewMCPClientFromStdio(reader io.Reader, writer io.Writer, options MCPClientOptions) (*client.Client, error)
- func RegisterMCPTools(registry core.ToolRegistry, mcpClient MCPClientInterface) error
- type BayesianToolSelector
- func (s *BayesianToolSelector) ScoreTools(ctx context.Context, intent string, tools []core.Tool) ([]ToolScore, error)
- func (s *BayesianToolSelector) SelectBest(ctx context.Context, intent string, candidates []ToolScore) (core.Tool, error)
- func (s *BayesianToolSelector) UpdatePriorProbabilities(toolUsageStats map[string]int)
- type DefaultMCPDiscoveryService
- func (d *DefaultMCPDiscoveryService) AddServer(server MCPServer) error
- func (d *DefaultMCPDiscoveryService) DiscoverTools(ctx context.Context) ([]core.Tool, error)
- func (d *DefaultMCPDiscoveryService) GetConnectedServers() []string
- func (d *DefaultMCPDiscoveryService) IsRunning() bool
- func (d *DefaultMCPDiscoveryService) RemoveServer(serverName string) error
- func (d *DefaultMCPDiscoveryService) Stop()
- func (d *DefaultMCPDiscoveryService) Subscribe(callback func(tools []core.Tool)) error
- type FuncTool
- func (t *FuncTool) Call(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
- func (t *FuncTool) CanHandle(ctx context.Context, intent string) bool
- func (t *FuncTool) Description() string
- func (t *FuncTool) Execute(ctx context.Context, params map[string]interface{}) (core.ToolResult, error)
- func (t *FuncTool) InputSchema() models.InputSchema
- func (t *FuncTool) Metadata() *core.ToolMetadata
- func (t *FuncTool) Name() string
- func (t *FuncTool) Type() ToolType
- func (t *FuncTool) Validate(params map[string]interface{}) error
- type InMemoryToolRegistry
- type MCPClientInterface
- type MCPClientOptions
- type MCPDiscoveryConfig
- type MCPDiscoveryService
- type MCPServer
- type MCPTool
- func (t *MCPTool) Call(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
- func (t *MCPTool) CanHandle(ctx context.Context, intent string) bool
- func (t *MCPTool) Description() string
- func (t *MCPTool) Execute(ctx context.Context, params map[string]interface{}) (core.ToolResult, error)
- func (t *MCPTool) InputSchema() models.InputSchema
- func (t *MCPTool) Metadata() *core.ToolMetadata
- func (t *MCPTool) Name() string
- func (t *MCPTool) Type() ToolType
- func (t *MCPTool) Validate(params map[string]interface{}) error
- type PerformanceMetrics
- type SmartToolRegistry
- func (r *SmartToolRegistry) AddFallback(intent string, fallbackToolName string) error
- func (r *SmartToolRegistry) ExecuteWithTracking(ctx context.Context, toolName string, params map[string]interface{}) (core.ToolResult, error)
- func (r *SmartToolRegistry) Get(name string) (core.Tool, error)
- func (r *SmartToolRegistry) GetCapabilities(toolName string) ([]ToolCapability, error)
- func (r *SmartToolRegistry) GetPerformanceMetrics(toolName string) (*PerformanceMetrics, error)
- func (r *SmartToolRegistry) List() []core.Tool
- func (r *SmartToolRegistry) Match(intent string) []core.Tool
- func (r *SmartToolRegistry) Register(tool core.Tool) error
- func (r *SmartToolRegistry) SelectBest(ctx context.Context, intent string) (core.Tool, error)
- type SmartToolRegistryConfig
- type Tool
- type ToolCapability
- type ToolFunc
- type ToolScore
- type ToolSelector
- type ToolType
- type XMLAction
- type XMLArgument
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func NewMCPClientFromStdio ΒΆ
func NewMCPClientFromStdio(reader io.Reader, writer io.Writer, options MCPClientOptions) (*client.Client, error)
NewMCPClientFromStdio creates a new MCP client using standard I/O for communication. This is useful for connecting to an MCP server launched as a subprocess.
func RegisterMCPTools ΒΆ
func RegisterMCPTools(registry core.ToolRegistry, mcpClient MCPClientInterface) error
RegisterMCPTools dynamically discovers tools from an MCP client and registers them into a core.ToolRegistry, wrapping them to conform to the core.Tool interface.
Types ΒΆ
type BayesianToolSelector ΒΆ added in v0.33.0
type BayesianToolSelector struct {
// Weights for different scoring components
MatchWeight float64 `json:"match_weight"`
PerformanceWeight float64 `json:"performance_weight"`
CapabilityWeight float64 `json:"capability_weight"`
// Prior probabilities for tool selection
PriorProbabilities map[string]float64 `json:"prior_probabilities"`
}
BayesianToolSelector implements intelligent tool selection using Bayesian scoring.
func NewBayesianToolSelector ΒΆ added in v0.33.0
func NewBayesianToolSelector() *BayesianToolSelector
NewBayesianToolSelector creates a new Bayesian tool selector with default weights.
func (*BayesianToolSelector) ScoreTools ΒΆ added in v0.33.0
func (s *BayesianToolSelector) ScoreTools(ctx context.Context, intent string, tools []core.Tool) ([]ToolScore, error)
ScoreTools scores all tools for a given intent using Bayesian inference.
func (*BayesianToolSelector) SelectBest ΒΆ added in v0.33.0
func (s *BayesianToolSelector) SelectBest(ctx context.Context, intent string, candidates []ToolScore) (core.Tool, error)
SelectBest selects the best tool from scored candidates.
func (*BayesianToolSelector) UpdatePriorProbabilities ΒΆ added in v0.33.0
func (s *BayesianToolSelector) UpdatePriorProbabilities(toolUsageStats map[string]int)
UpdatePriorProbabilities updates the prior probabilities based on tool usage.
type DefaultMCPDiscoveryService ΒΆ added in v0.33.0
type DefaultMCPDiscoveryService struct {
// contains filtered or unexported fields
}
DefaultMCPDiscoveryService provides automatic tool discovery from MCP servers.
func NewDefaultMCPDiscoveryService ΒΆ added in v0.33.0
func NewDefaultMCPDiscoveryService(config *MCPDiscoveryConfig) *DefaultMCPDiscoveryService
NewDefaultMCPDiscoveryService creates a new MCP discovery service.
func (*DefaultMCPDiscoveryService) AddServer ΒΆ added in v0.33.0
func (d *DefaultMCPDiscoveryService) AddServer(server MCPServer) error
AddServer adds an MCP server to the discovery service.
func (*DefaultMCPDiscoveryService) DiscoverTools ΒΆ added in v0.33.0
DiscoverTools discovers tools from all connected MCP servers.
func (*DefaultMCPDiscoveryService) GetConnectedServers ΒΆ added in v0.33.0
func (d *DefaultMCPDiscoveryService) GetConnectedServers() []string
GetConnectedServers returns the list of connected servers.
func (*DefaultMCPDiscoveryService) IsRunning ΒΆ added in v0.33.0
func (d *DefaultMCPDiscoveryService) IsRunning() bool
IsRunning returns true if the discovery service is currently running.
func (*DefaultMCPDiscoveryService) RemoveServer ΒΆ added in v0.33.0
func (d *DefaultMCPDiscoveryService) RemoveServer(serverName string) error
RemoveServer removes an MCP server from the discovery service.
func (*DefaultMCPDiscoveryService) Stop ΒΆ added in v0.33.0
func (d *DefaultMCPDiscoveryService) Stop()
Stop stops the discovery service.
type FuncTool ΒΆ
type FuncTool struct {
// contains filtered or unexported fields
}
FuncTool wraps a Go function as a Tool implementation.
func NewFuncTool ΒΆ
func NewFuncTool(name, description string, schema models.InputSchema, fn ToolFunc) *FuncTool
NewFuncTool creates a new function-based tool.
func (*FuncTool) Call ΒΆ
func (t *FuncTool) Call(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
Call executes the wrapped function with the provided arguments.
func (*FuncTool) Description ΒΆ
Description returns human-readable explanation of the tool.
func (*FuncTool) Execute ΒΆ
func (t *FuncTool) Execute(ctx context.Context, params map[string]interface{}) (core.ToolResult, error)
Execute runs the tool with provided parameters and adapts the result to the core interface.
func (*FuncTool) InputSchema ΒΆ
func (t *FuncTool) InputSchema() models.InputSchema
InputSchema returns the expected parameter structure.
func (*FuncTool) Metadata ΒΆ
func (t *FuncTool) Metadata() *core.ToolMetadata
Metadata returns the tool's metadata for intent matching.
type InMemoryToolRegistry ΒΆ added in v0.27.0
type InMemoryToolRegistry struct {
// contains filtered or unexported fields
}
InMemoryToolRegistry provides a basic in-memory implementation of the ToolRegistry interface.
func NewInMemoryToolRegistry ΒΆ added in v0.27.0
func NewInMemoryToolRegistry() *InMemoryToolRegistry
NewInMemoryToolRegistry creates a new, empty InMemoryToolRegistry.
func (*InMemoryToolRegistry) Get ΒΆ added in v0.27.0
func (r *InMemoryToolRegistry) Get(name string) (core.Tool, error)
Get retrieves a tool by its name. It returns an error if the tool is not found.
func (*InMemoryToolRegistry) List ΒΆ added in v0.27.0
func (r *InMemoryToolRegistry) List() []core.Tool
List returns a slice of all registered tools. The order is not guaranteed.
func (*InMemoryToolRegistry) Match ΒΆ added in v0.27.0
func (r *InMemoryToolRegistry) Match(intent string) []core.Tool
Match finds tools that might match a given intent string. This basic implementation checks if the intent contains the tool name (case-insensitive). More sophisticated matching (e.g., using descriptions or CanHandle) could be added.
type MCPClientInterface ΒΆ added in v0.27.0
type MCPClientInterface interface {
ListTools(ctx context.Context, cursor *models.Cursor) (*models.ListToolsResult, error)
// Add CallTool if the wrapper's Execute needs it indirectly via the interface
CallTool(ctx context.Context, name string, args map[string]interface{}) (*models.CallToolResult, error)
}
This improves testability by allowing mocks.
type MCPClientOptions ΒΆ
MCPClientOptions contains configuration options for creating an MCP client.
type MCPDiscoveryConfig ΒΆ added in v0.33.0
MCPDiscoveryConfig configures the MCP discovery service.
type MCPDiscoveryService ΒΆ added in v0.33.0
type MCPDiscoveryService interface {
DiscoverTools(ctx context.Context) ([]core.Tool, error)
Subscribe(callback func(tools []core.Tool)) error
}
MCPDiscoveryService handles automatic tool discovery from MCP servers.
type MCPServer ΒΆ added in v0.33.0
type MCPServer interface {
Name() string
IsConnected() bool
ListTools(ctx context.Context) ([]core.Tool, error)
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
}
MCPServer represents an MCP server connection.
type MCPTool ΒΆ
type MCPTool struct {
// contains filtered or unexported fields
}
MCPTool represents a tool that delegates to an MCP server.
func NewMCPTool ΒΆ
func NewMCPTool(name, description string, schema models.InputSchema, client *client.Client, toolName string) *MCPTool
NewMCPTool creates a new MCP-based tool.
func (*MCPTool) Call ΒΆ
func (t *MCPTool) Call(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
Call forwards the call to the MCP server and returns the result.
func (*MCPTool) Description ΒΆ
Description returns human-readable explanation of the tool.
func (*MCPTool) Execute ΒΆ
func (t *MCPTool) Execute(ctx context.Context, params map[string]interface{}) (core.ToolResult, error)
Execute runs the tool with provided parameters and adapts the result to the core interface.
func (*MCPTool) InputSchema ΒΆ
func (t *MCPTool) InputSchema() models.InputSchema
InputSchema returns the expected parameter structure.
func (*MCPTool) Metadata ΒΆ
func (t *MCPTool) Metadata() *core.ToolMetadata
Metadata returns the tool's metadata for intent matching.
type PerformanceMetrics ΒΆ added in v0.33.0
type PerformanceMetrics struct {
ExecutionCount int64 `json:"execution_count"`
SuccessCount int64 `json:"success_count"`
FailureCount int64 `json:"failure_count"`
AverageLatency time.Duration `json:"average_latency"`
LastExecutionTime time.Time `json:"last_execution_time"`
SuccessRate float64 `json:"success_rate"`
ReliabilityScore float64 `json:"reliability_score"` // 0.0 to 1.0
}
PerformanceMetrics tracks tool execution statistics.
type SmartToolRegistry ΒΆ added in v0.33.0
type SmartToolRegistry struct {
// contains filtered or unexported fields
}
SmartToolRegistry provides intelligent tool selection and management.
func NewSmartToolRegistry ΒΆ added in v0.33.0
func NewSmartToolRegistry(config *SmartToolRegistryConfig) *SmartToolRegistry
NewSmartToolRegistry creates a new smart tool registry.
func (*SmartToolRegistry) AddFallback ΒΆ added in v0.33.0
func (r *SmartToolRegistry) AddFallback(intent string, fallbackToolName string) error
AddFallback adds a fallback tool for a specific intent.
func (*SmartToolRegistry) ExecuteWithTracking ΒΆ added in v0.33.0
func (r *SmartToolRegistry) ExecuteWithTracking(ctx context.Context, toolName string, params map[string]interface{}) (core.ToolResult, error)
ExecuteWithTracking executes a tool and tracks performance metrics.
func (*SmartToolRegistry) Get ΒΆ added in v0.33.0
func (r *SmartToolRegistry) Get(name string) (core.Tool, error)
Get retrieves a tool by name.
func (*SmartToolRegistry) GetCapabilities ΒΆ added in v0.33.0
func (r *SmartToolRegistry) GetCapabilities(toolName string) ([]ToolCapability, error)
GetCapabilities returns the capabilities for a tool.
func (*SmartToolRegistry) GetPerformanceMetrics ΒΆ added in v0.33.0
func (r *SmartToolRegistry) GetPerformanceMetrics(toolName string) (*PerformanceMetrics, error)
GetPerformanceMetrics returns performance metrics for a tool.
func (*SmartToolRegistry) List ΒΆ added in v0.33.0
func (r *SmartToolRegistry) List() []core.Tool
List returns all registered tools.
func (*SmartToolRegistry) Match ΒΆ added in v0.33.0
func (r *SmartToolRegistry) Match(intent string) []core.Tool
Match finds and ranks tools for a given intent using intelligent selection.
func (*SmartToolRegistry) Register ΒΆ added in v0.33.0
func (r *SmartToolRegistry) Register(tool core.Tool) error
Register adds a tool to the registry with capability analysis.
func (*SmartToolRegistry) SelectBest ΒΆ added in v0.33.0
SelectBest selects the best tool for a given intent.
type SmartToolRegistryConfig ΒΆ added in v0.33.0
type SmartToolRegistryConfig struct {
Selector ToolSelector
MCPDiscovery MCPDiscoveryService
AutoDiscoveryEnabled bool
PerformanceTrackingEnabled bool
FallbackEnabled bool
}
SmartToolRegistryConfig configures the smart registry.
type Tool ΒΆ
type Tool interface {
// Name returns the tool's identifier
Name() string
// Description returns human-readable explanation of the tool's purpose
Description() string
// InputSchema returns the expected parameter structure
InputSchema() models.InputSchema
// Call executes the tool with the provided arguments
Call(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
}
Tool defines a callable tool interface that abstracts both local functions and remote MCP tools. This provides a unified way to interact with tools regardless of their implementation details.
type ToolCapability ΒΆ added in v0.33.0
type ToolCapability struct {
Name string `json:"name"`
Confidence float64 `json:"confidence"` // 0.0 to 1.0
Description string `json:"description"`
}
ToolCapability represents a specific capability a tool can handle.
type ToolFunc ΒΆ
type ToolFunc func(ctx context.Context, args map[string]interface{}) (*models.CallToolResult, error)
ToolFunc represents a function that can be called as a tool.
type ToolScore ΒΆ added in v0.33.0
type ToolScore struct {
Tool core.Tool `json:"-"`
MatchScore float64 `json:"match_score"` // How well it matches the intent
PerformanceScore float64 `json:"performance_score"` // Based on historical performance
CapabilityScore float64 `json:"capability_score"` // Based on capability match
FinalScore float64 `json:"final_score"` // Weighted combination
}
ToolScore represents the computed score for tool selection.
type ToolSelector ΒΆ added in v0.33.0
type ToolSelector interface {
SelectBest(ctx context.Context, intent string, candidates []ToolScore) (core.Tool, error)
ScoreTools(ctx context.Context, intent string, tools []core.Tool) ([]ToolScore, error)
}
ToolSelector defines the interface for tool selection algorithms.
type XMLAction ΒΆ added in v0.26.0
type XMLAction struct {
XMLName xml.Name `xml:"action"`
ToolName string `xml:"tool_name,omitempty"`
Arguments []XMLArgument `xml:"arguments>arg,omitempty"`
Content string `xml:",chardata"`
}
func (*XMLAction) GetArgumentsMap ΒΆ added in v0.26.0
Helper to convert XML arguments to map[string]interface{} Note: This currently stores all values as strings. More sophisticated type inference or checking could be added later if needed based on tool schemas.