tools

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidToolInput = &ToolError{
	Code:    "invalid_tool_input",
	Message: "Invalid tool input",
}

ErrInvalidToolInput is returned when the input parameters are invalid

View Source
var ErrToolExecutionFailed = &ToolError{
	Code:    "tool_execution_failed",
	Message: "Tool execution failed",
}

ErrToolExecutionFailed is returned when a tool execution fails

View Source
var ErrToolNotFound = &ToolError{
	Code:    "tool_not_found",
	Message: "Tool not found",
}

ErrToolNotFound is returned when a tool is not found

Functions

This section is empty.

Types

type Content

type Content struct {
	Type string `json:"type"`
	Text string `json:"text,omitempty"`
}

Content represents content in a tool execution result

func NewTextContent

func NewTextContent(text string) Content

NewTextContent creates a new text content

type Registry

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

Registry is a registry of tools

func GetRegistry added in v1.5.0

func GetRegistry() *Registry

GetRegistry returns the global registry instance

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new registry

func (*Registry) DeregisterTool

func (r *Registry) DeregisterTool(name string) bool

DeregisterTool removes a tool from the registry

func (*Registry) Execute added in v1.5.0

func (r *Registry) Execute(ctx context.Context, name string, params map[string]interface{}, opts *ToolExecutionOptions) (interface{}, error)

Execute executes a tool by name with the given parameters

func (*Registry) GetAllTools

func (r *Registry) GetAllTools() []*Tool

GetAllTools returns all registered tools

func (*Registry) GetTool

func (r *Registry) GetTool(name string) (*Tool, bool)

GetTool returns a tool by name

func (*Registry) GetToolsByCategory

func (r *Registry) GetToolsByCategory(category string) []*Tool

GetToolsByCategory returns tools filtered by category

func (*Registry) PrintTools added in v1.5.0

func (r *Registry) PrintTools()

PrintTools prints all registered tools for debugging

func (*Registry) RegisterTool

func (r *Registry) RegisterTool(tool *Tool)

RegisterTool registers a tool with the registry

func (*Registry) ValidateToolInput

func (r *Registry) ValidateToolInput(name string, params map[string]interface{}) error

ValidateToolInput validates the input parameters against the tool's schema

type Result

type Result struct {
	Result  interface{} `json:"result,omitempty"`
	Content []Content   `json:"content,omitempty"`
	IsError bool        `json:"isError,omitempty"`
}

Result represents a tool execution result

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema ToolInputSchema `json:"inputSchema"`
	Handler     ToolHandler
	// Optional metadata for the tool
	Category  string      `json:"-"` // Category for grouping tools
	CreatedAt time.Time   `json:"-"` // When the tool was registered
	RawSchema interface{} `json:"-"` // Alternative to InputSchema for complex schemas
}

Tool represents a tool that can be executed by the MCP server

type ToolError

type ToolError struct {
	Code    string
	Message string
	Data    interface{}
}

ToolError represents an error that occurred while executing a tool

func (*ToolError) Error

func (e *ToolError) Error() string

Error returns a string representation of the error

type ToolExecutionOptions

type ToolExecutionOptions struct {
	Timeout     time.Duration
	ProgressCB  func(progress float64, message string) // Optional progress callback
	TraceID     string                                 // For tracing/logging
	UserContext map[string]interface{}                 // User-specific context
}

ToolExecutionOptions provides options for tool execution

type ToolHandler

type ToolHandler func(ctx context.Context, params map[string]interface{}) (interface{}, error)

ToolHandler is a function that handles a tool execution Enhanced to use context for cancellation and timeouts

type ToolInputSchema

type ToolInputSchema struct {
	Type       string                 `json:"type"`
	Properties map[string]interface{} `json:"properties,omitempty"`
	Required   []string               `json:"required,omitempty"`
}

ToolInputSchema represents the schema for tool input parameters

Jump to

Keyboard shortcuts

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