tools

package
v0.0.0-...-9c0f5be Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package tools provides interfaces and implementations for MCP tools

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParams    = errors.New("invalid parameters")
	ErrNotImplemented   = errors.New("operation not implemented")
	ErrResourceNotFound = errors.New("resource not found")
	ErrPermissionDenied = errors.New("permission denied")
	ErrExternalAPIError = errors.New("external API error")
	ErrInternalError    = errors.New("internal server error")
)

Standard errors for consistent error handling

Functions

func GetOpenAITools

func GetOpenAITools(tools []Tool) []openai.ChatCompletionToolParam

GetOpenAITools converts a slice of tools to OpenAI format

func NewErrorResult

func NewErrorResult(err error) *mcp.CallToolResult

NewErrorResult creates a standard error result

func NewTextResult

func NewTextResult(text string) *mcp.CallToolResult

NewTextResult creates a standard text result

func WrapError

func WrapError(err error, msg string) error

WrapError wraps a domain error with a context message

Types

type BaseTool

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

BaseTool provides common functionality for all tools

func NewBaseTool

func NewBaseTool(name string, handle mcp.Tool) *BaseTool

NewBaseTool creates a new BaseTool with the given name and handle

func (*BaseTool) Handle

func (b *BaseTool) Handle() mcp.Tool

Handle returns the MCP Tool definition

func (*BaseTool) Name

func (b *BaseTool) Name() string

Name returns the name of the tool

type Handler

type Handler func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

Handler processes tool requests and returns responses

func DefaultHandler

func DefaultHandler(text string) Handler

DefaultHandler provides a default implementation for tool handlers

func ErrorHandler

func ErrorHandler(err error) Handler

ErrorHandler provides an error implementation for tool handlers

func NotImplementedHandler

func NotImplementedHandler() Handler

NotImplementedHandler returns a handler that indicates a feature is not implemented

type Tool

type Tool interface {
	// Handle returns the underlying MCP tool
	Handle() mcp.Tool

	// ToOpenAITool converts the tool to OpenAI format
	ToOpenAITool() openai.ChatCompletionToolParam

	// Handler processes tool requests and returns responses
	Handler(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error)

	// Name returns the name of the tool
	Name() string
}

Tool defines the interface for all tools in the system

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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