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: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExecDescription string
View Source
var InspectDescription string
View Source
var InvokeDescription string
View Source
var ListDescription string

Functions

func FormatInspectResultAsJSDoc added in v0.1.1

func FormatInspectResultAsJSDoc(result *InspectResult) string

FormatInspectResultAsJSDoc formats the inspect result as a JSDoc function stub

func FormatListResultAsText added in v0.1.1

func FormatListResultAsText(tools []ListToolResult, total int) string

FormatListResultAsText formats the list result as simple text (name: description)

func HandleExecuteTool

func HandleExecuteTool(ctx context.Context, logger *slog.Logger, manager *client.Manager, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)

HandleExecuteTool implements the execute built-in tool (MCP server handler)

func HandleInspectTool

func HandleInspectTool(ctx context.Context, provider ToolProvider, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)

HandleInspectTool handles the inspect tool call (MCP server handler)

func HandleInvokeTool

func HandleInvokeTool(ctx context.Context, provider ToolProvider, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)

HandleInvokeTool handles the invoke tool call (MCP server handler)

func HandleListTool

func HandleListTool(ctx context.Context, provider ToolProvider, req *mcp.CallToolRequest) (*mcp.CallToolResult, error)

HandleListTool handles the list tool call (MCP server handler)

func InvokeTool

func InvokeTool(ctx context.Context, provider ToolProvider, name string, params json.RawMessage, mapper *toolname.Mapper) (*mcp.CallToolResult, error)

InvokeTool is the shared core function for invoking a tool. Used by both CLI and MCP server handlers. The name parameter can be either JS name (camelCase) or original name (serverID__toolName).

func TruncateDescription added in v0.1.1

func TruncateDescription(s string, maxWords int) string

TruncateDescription truncates a description to a maximum number of words

Types

type BuiltinToolRegistry

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

BuiltinToolRegistry manages built-in tools

func NewBuiltinToolRegistry

func NewBuiltinToolRegistry(logger *slog.Logger) *BuiltinToolRegistry

NewBuiltinToolRegistry creates a new registry

func (*BuiltinToolRegistry) GetAllTools

func (r *BuiltinToolRegistry) GetAllTools() map[string]config.BuiltinTool

GetAllTools returns all registered tools

func (*BuiltinToolRegistry) GetTool

func (r *BuiltinToolRegistry) GetTool(name string) (config.BuiltinTool, bool)

GetTool retrieves a tool from the registry

func (*BuiltinToolRegistry) RegisterTool

func (r *BuiltinToolRegistry) RegisterTool(tool config.BuiltinTool)

RegisterTool adds a tool to the registry

type ExecError

type ExecError struct {
	Type    string `json:"type"`
	Message string `json:"message"`
}

ExecError represents a structured execution error

type ExecResult

type ExecResult struct {
	Result any           `json:"result"`
	Logs   []js.LogEntry `json:"logs"`
	Error  *ExecError    `json:"error,omitempty"`
}

ExecResult represents the result from executing JavaScript code

func ExecuteCode

func ExecuteCode(ctx context.Context, logger *slog.Logger, caller js.ToolCaller, code string) (*ExecResult, error)

ExecuteCode executes JavaScript code using the provided ToolCaller. This is the shared implementation used by both CLI and MCP tool handler.

type InspectResult

type InspectResult struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Server      string         `json:"server,omitempty"`
	InputSchema map[string]any `json:"inputSchema,omitempty"`
}

InspectResult represents the result of inspecting a tool

func InspectTool

func InspectTool(ctx context.Context, provider ToolProvider, name string, mapper *toolname.Mapper) (*InspectResult, error)

InspectTool is the shared core function for inspecting a tool. Used by both CLI and MCP server handlers. The name parameter can be either JS name (camelCase) or original name (serverID__toolName).

type ListOptions

type ListOptions struct {
	Server            string // Optional: filter by server name
	Query             string // Optional: comma-separated keywords for search
	IncludeUnprefixed bool   // If true, include tools without server prefix (for direct server connections)
}

ListOptions contains options for listing tools

type ListResult

type ListResult struct {
	Tools []*mcp.Tool `json:"-"` // Internal: original tools
	Total int         `json:"total"`
}

ListResult represents the result of listing tools

func ListTools

func ListTools(ctx context.Context, provider ToolProvider, opts ListOptions) (*ListResult, error)

ListTools is the shared core function for listing tools. Used by both CLI and MCP server handlers.

type ListToolResult

type ListToolResult struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Server      string         `json:"server,omitempty"`
	InputSchema map[string]any `json:"inputSchema,omitempty"`
}

ListToolResult represents a tool in the list result

func FormatListResult added in v0.1.1

func FormatListResult(result *ListResult, mapper *toolname.Mapper) []ListToolResult

FormatListResult formats the list result with JS names for output. Used by both CLI and MCP server handlers for consistent output.

type ManagerAdapter

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

ManagerAdapter adapts client.Manager to implement ToolProvider interface. Used by MCP server handlers to call tools via the shared core functions.

func NewManagerAdapter

func NewManagerAdapter(manager *client.Manager) *ManagerAdapter

NewManagerAdapter creates a new ManagerAdapter

func (*ManagerAdapter) CallTool

func (a *ManagerAdapter) CallTool(ctx context.Context, name string, params json.RawMessage) (*mcp.CallToolResult, error)

CallTool invokes a tool by namespaced name (serverID__toolName)

func (*ManagerAdapter) GetTool

func (a *ManagerAdapter) GetTool(ctx context.Context, name string) (*mcp.Tool, error)

GetTool returns a specific tool by namespaced name (serverID__toolName)

func (*ManagerAdapter) ListTools

func (a *ManagerAdapter) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools returns all available tools from all connected servers

type ToolProvider

type ToolProvider interface {
	// ListTools returns all available tools
	ListTools(ctx context.Context) ([]*mcp.Tool, error)
	// GetTool returns a specific tool by name
	GetTool(ctx context.Context, name string) (*mcp.Tool, error)
	// CallTool invokes a tool with the given parameters
	CallTool(ctx context.Context, name string, params json.RawMessage) (*mcp.CallToolResult, error)
}

ToolProvider is the common interface for tool operations. Both CLI clients and MCP server's client.Manager implement this interface.

Jump to

Keyboard shortcuts

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