tools

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 13 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 FormatListResultAsJSDoc

func FormatListResultAsJSDoc(result *ListResult) string

FormatListResultAsJSDoc formats the list result as JSDoc function stubs

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) (*mcp.CallToolResult, error)

InvokeTool is the shared core function for invoking a tool. Used by both CLI and MCP server handlers.

func RenderListDescription

func RenderListDescription(baseMarkdown string, remoteTools map[string]*mcp.Tool) string

RenderListDescription renders the list tool's markdown description by injecting a summary of currently available remote tools.

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) (*InspectResult, error)

InspectTool is the shared core function for inspecting a tool. Used by both CLI and MCP server handlers.

type ListOptions

type ListOptions struct {
	Server string // Optional: filter by server name
	Query  string // Optional: comma-separated keywords for search
}

ListOptions contains options for listing tools

type ListResult

type ListResult struct {
	Tools []ListToolResult `json:"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

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