tools

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrToolNotFound is returned when a tool is not registered
	ErrToolNotFound = errors.New("tool not found")

	// ErrToolAlreadyRegistered is returned when trying to register a duplicate tool name.
	ErrToolAlreadyRegistered = errors.New("tool already registered")
)

Standard errors

Functions

func RegisterEmailTool

func RegisterEmailTool(t *Tools)

RegisterEmailTool registers the send_email built-in tool. SMTP configuration is read from environment variables at call time:

  • SMTP_HOST (required)
  • SMTP_PORT (default 587)
  • SMTP_USER (required)
  • SMTP_PASS (required)
  • SMTP_FROM (defaults to SMTP_USER)

Types

type DynamicParamDef

type DynamicParamDef struct {
	Name        string   `yaml:"name"`
	Type        string   `yaml:"type"`
	Description string   `yaml:"description"`
	Required    bool     `yaml:"required"`
	Default     any      `yaml:"default"`
	Enum        []string `yaml:"enum"`
}

DynamicParamDef is a YAML parameter definition.

type DynamicToolDef

type DynamicToolDef struct {
	Name           string            `yaml:"name"`
	Description    string            `yaml:"description"`
	Params         []DynamicParamDef `yaml:"params"`
	Implementation DynamicToolImpl   `yaml:"implementation"`
}

DynamicToolDef is a YAML tool definition.

type DynamicToolImpl

type DynamicToolImpl struct {
	Type    string            `yaml:"type"` // http, exec, file_read, file_write, builtin
	Method  string            `yaml:"method"`
	URL     string            `yaml:"url"`
	Headers map[string]string `yaml:"headers"`
	Query   map[string]string `yaml:"query"`
	Body    any               `yaml:"body"`
	Command string            `yaml:"command"`
	Path    string            `yaml:"path"`
	Timeout string            `yaml:"timeout"`
}

DynamicToolImpl is a YAML implementation definition.

type MCPServerOption

type MCPServerOption func(*mcpServerOptions)

MCPServerOption configures MCP server behavior.

func WithMCPAutoConnect

func WithMCPAutoConnect(enabled bool) MCPServerOption

WithMCPAutoConnect enables automatic connection on first tool call.

func WithMCPTimeout

func WithMCPTimeout(d time.Duration) MCPServerOption

WithMCPTimeout sets the timeout for MCP operations.

type MCPServerStatus

type MCPServerStatus struct {
	Name      string   `json:"name"`
	Connected bool     `json:"connected"`
	Transport string   `json:"transport,omitempty"`
	URL       string   `json:"url,omitempty"`
	Command   string   `json:"command,omitempty"`
	Tools     []string `json:"tools"`
}

MCPServerStatus describes the status of a connected MCP server.

type ParamDef

type ParamDef struct {
	Type        string   `json:"type" yaml:"type"`
	Description string   `json:"description" yaml:"description"`
	Required    bool     `json:"required" yaml:"required"`
	Default     any      `json:"default,omitempty" yaml:"default,omitempty"`
	Enum        []string `json:"enum,omitempty" yaml:"enum,omitempty"`
}

ParamDef defines a tool parameter.

type SkillsRef

type SkillsRef interface {
	GetMatchedSkills() []skills.SkillMatch
}

SkillsRef is a narrow interface for skill-based tool augmentation. *vega.SkillsPrompt satisfies this interface.

type ToolDef

type ToolDef struct {
	Description string
	Fn          any
	Params      map[string]ParamDef
}

ToolDef allows explicit tool definition with schema.

type ToolError

type ToolError struct {
	ToolName string
	Err      error
}

ToolError wraps errors with tool context.

func (*ToolError) Error

func (e *ToolError) Error() string

func (*ToolError) Unwrap

func (e *ToolError) Unwrap() error

type ToolFunc

type ToolFunc func(ctx context.Context, params map[string]any) (string, error)

ToolFunc is the signature for tool execution.

type ToolMiddleware

type ToolMiddleware func(ToolFunc) ToolFunc

ToolMiddleware wraps tool execution.

type Tools

type Tools struct {

	// OnFileWrite is called after a successful write_file or append_file operation.
	// Parameters: ctx, relative path, operation ("write"/"append"), description.
	OnFileWrite func(ctx context.Context, path, operation, description string)
	// contains filtered or unexported fields
}

Tools is a collection of callable tools.

func NewTools

func NewTools(opts ...ToolsOption) *Tools

NewTools creates a new Tools collection.

func (*Tools) ActiveProject added in v0.2.0

func (t *Tools) ActiveProject() string

ActiveProject returns the current active project name, or "" if none.

func (*Tools) BuiltinServerConnected added in v0.2.0

func (t *Tools) BuiltinServerConnected(name string) bool

BuiltinServerConnected reports whether a built-in server's tools are already registered.

func (*Tools) ConnectBuiltinServer added in v0.2.0

func (t *Tools) ConnectBuiltinServer(ctx context.Context, name string) (int, error)

ConnectBuiltinServer registers all tools from a built-in Go MCP server implementation. Tools are registered with the standard "servername__toolname" prefix. Returns the number of tools registered.

func (*Tools) ConnectMCP

func (t *Tools) ConnectMCP(ctx context.Context) error

ConnectMCP connects all MCP servers and discovers their tools.

func (*Tools) ConnectMCPServer added in v0.2.0

func (t *Tools) ConnectMCPServer(ctx context.Context, config mcp.ServerConfig) (int, error)

ConnectMCPServer connects a single MCP server by config at runtime, discovers its tools, and registers them. Returns the number of tools found.

func (*Tools) ContainerAvailable

func (t *Tools) ContainerAvailable() bool

ContainerAvailable returns whether container execution is available.

func (*Tools) DisconnectMCP

func (t *Tools) DisconnectMCP() error

DisconnectMCP disconnects all MCP servers.

func (*Tools) DisconnectMCPServer added in v0.2.1

func (t *Tools) DisconnectMCPServer(name string) error

DisconnectMCPServer disconnects a single MCP server by name, removes it from the client list, and unregisters all its tools.

func (*Tools) Execute

func (t *Tools) Execute(ctx context.Context, name string, params map[string]any) (string, error)

Execute calls a tool by name.

func (*Tools) Filter

func (t *Tools) Filter(names ...string) *Tools

Filter returns a new Tools with only the specified tools.

func (*Tools) FilterMCP

func (t *Tools) FilterMCP(patterns ...string) *Tools

FilterMCP returns a new Tools with only tools from specified MCP servers. Supports patterns like "server__*" to include all tools from a server.

func (*Tools) GetSettings added in v0.2.0

func (t *Tools) GetSettings() map[string]string

GetSettings returns a copy of the current settings map.

func (*Tools) HasBuiltinServer added in v0.2.0

func (t *Tools) HasBuiltinServer(name string) bool

HasBuiltinServer reports whether a Go-native implementation exists for the named MCP server.

func (*Tools) LoadDirectory

func (t *Tools) LoadDirectory(path string) error

LoadDirectory loads tool definitions from YAML files.

func (*Tools) LoadFile

func (t *Tools) LoadFile(path string) error

LoadFile loads a single tool definition from YAML.

func (*Tools) MCPServerConnected added in v0.2.0

func (t *Tools) MCPServerConnected(name string) bool

MCPServerConnected reports whether a server with the given name is already connected.

func (*Tools) MCPServerStatuses

func (t *Tools) MCPServerStatuses() []MCPServerStatus

MCPServerStatuses returns the status of all configured MCP servers.

func (*Tools) ReadMCPResource

func (t *Tools) ReadMCPResource(ctx context.Context, serverName, uri string) (string, error)

ReadMCPResource reads a resource from a specific MCP server by name.

func (*Tools) Register

func (t *Tools) Register(name string, fn any) error

Register adds a tool to the collection. The function can be: - func(params) string - func(params) (string, error) - func(ctx, params) (string, error) - ToolDef with explicit schema

func (*Tools) RegisterBuiltins

func (t *Tools) RegisterBuiltins()

RegisterBuiltins adds the built-in tools.

func (*Tools) RegisterDynamicTool

func (t *Tools) RegisterDynamicTool(def DynamicToolDef) error

RegisterDynamicTool registers a tool from a DynamicToolDef.

func (*Tools) Sandbox added in v0.2.0

func (t *Tools) Sandbox() string

Sandbox returns the base sandbox path (without project subdirectory).

func (*Tools) Schema

func (t *Tools) Schema() []llm.ToolSchema

Schema returns the schemas for all tools. If a skillsRef is set, tools declared by matched skills are also included.

func (*Tools) SetActiveProject added in v0.2.0

func (t *Tools) SetActiveProject(name string)

SetActiveProject sets the active project name for workspace subdirectories. All file and exec operations will target sandbox/<project>/ when set. Pass an empty string to clear the active project.

func (*Tools) SetProject

func (t *Tools) SetProject(name string)

SetProject sets the active project for container routing.

func (*Tools) SetSettings added in v0.2.0

func (t *Tools) SetSettings(m map[string]string)

SetSettings replaces the tool settings map used for dynamic tool interpolation.

func (*Tools) Use

func (t *Tools) Use(mw ToolMiddleware)

Use adds middleware to the tool chain.

func (*Tools) WithSkillsRef

func (t *Tools) WithSkillsRef(sp SkillsRef) *Tools

WithSkillsRef returns a shallow copy with a skills prompt reference set. When Schema() is called, tools declared by matched skills are included.

type ToolsOption

type ToolsOption func(*Tools)

ToolsOption configures Tools.

func WithContainer

func WithContainer(cm *container.Manager) ToolsOption

WithContainer enables container-based tool execution.

func WithContainerRouting

func WithContainerRouting(toolNames ...string) ToolsOption

WithContainerRouting specifies which tools should be routed to containers.

func WithMCPServer

func WithMCPServer(config mcp.ServerConfig) ToolsOption

WithMCPServer adds an MCP server to the tools collection. Tools from the server will be prefixed with "server_name__tool_name".

func WithSandbox

func WithSandbox(path string) ToolsOption

WithSandbox restricts file operations to a directory.

Jump to

Keyboard shortcuts

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