Documentation
¶
Overview ¶
pkg/tools/func.go
Index ¶
- func NewMCPClientFromStdio(reader io.Reader, writer io.Writer, options MCPClientOptions) (*client.Client, error)
- func RegisterMCPTools(registry *Registry, mcpClient *client.Client) 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 MCPClientOptions
- 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 Registry
- type Tool
- type ToolFunc
- type ToolType
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.
Types ¶
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 MCPClientOptions ¶
MCPClientOptions contains configuration options for creating an MCP client.
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 Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages a collection of tools and provides methods for registration, retrieval, and invocation. It safely handles concurrent access to tools.
func (*Registry) Call ¶
func (r *Registry) Call(ctx context.Context, name string, args map[string]interface{}) (*models.CallToolResult, error)
Call invokes a tool by name with the given arguments. This provides a convenient way to call tools without retrieving them first.
func (*Registry) Register ¶
Register adds a tool to the registry. Returns an error if a tool with the same name already exists.
func (*Registry) Unregister ¶
Unregister removes a tool from the registry. Returns an error if the tool doesn't exist.
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.