tools

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	PluginID = "tools"
)

Variables

View Source
var (
	// ErrToolNotFound is returned when no tool has the requested name.
	ErrToolNotFound = errors.New("tool not found")
	// ErrConnectionRequired is returned when a connection-scoped tool is
	// called without a connection in the PluginContext.
	ErrConnectionRequired = errors.New("tool requires a connection")
)

Functions

func ObjectSchema

func ObjectSchema(properties map[string]any, required ...string) json.RawMessage

ObjectSchema builds a closed JSON object schema.

func RegisterPlugin

func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error

RegisterPlugin validates the tools and registers the capability.

Types

type Annotations

type Annotations struct {
	ReadOnly    bool `json:"readOnly"`
	Destructive bool `json:"destructive"`
	Idempotent  bool `json:"idempotent"`
	OpenWorld   bool `json:"openWorld"`
}

Annotations are the MCP tool annotation hints.

type CallInput

type CallInput struct {
	Name      string
	Arguments json.RawMessage
}

CallInput names the tool and carries its JSON object arguments.

type Content

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

Content is one text block of a tool result.

type Descriptor

type Descriptor struct {
	Name         string          `json:"name"`
	Title        string          `json:"title"`
	Description  string          `json:"description"`
	InputSchema  json.RawMessage `json:"inputSchema"`
	OutputSchema json.RawMessage `json:"outputSchema,omitempty"`
	Scope        Scope           `json:"scope"`
	Annotations  Annotations     `json:"annotations"`
}

Descriptor describes one tool to the host.

type Handler

type Handler func(ctx *types.PluginContext, arguments json.RawMessage) (*Result, error)

Handler runs one tool call.

type Manager

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

Manager holds the registered tools and dispatches calls to them.

func NewManager

func NewManager(log logging.Logger, opts PluginOpts) (*Manager, error)

NewManager validates every tool and returns the provider.

func (*Manager) CallTool

func (m *Manager) CallTool(ctx *types.PluginContext, input CallInput) (*Result, error)

CallTool dispatches the call to the named tool's handler.

func (*Manager) ListTools

func (m *Manager) ListTools(_ *types.PluginContext) ([]Descriptor, error)

ListTools returns the descriptors in registration order.

type Plugin

type Plugin struct {
	plugin.Plugin
	Impl Provider
}

func (*Plugin) GRPCClient

func (p *Plugin) GRPCClient(
	_ context.Context,
	_ *plugin.GRPCBroker,
	c *grpc.ClientConn,
) (interface{}, error)

func (*Plugin) GRPCServer

func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error

type PluginClient

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

func (*PluginClient) CallTool

func (p *PluginClient) CallTool(ctx *types.PluginContext, input CallInput) (*Result, error)

func (*PluginClient) ListTools

func (p *PluginClient) ListTools(ctx *types.PluginContext) ([]Descriptor, error)

type PluginOpts

type PluginOpts struct {
	Tools []Tool
}

PluginOpts lists the tools a plugin exposes.

type PluginServer

type PluginServer struct {
	toolspb.UnimplementedToolsPluginServer
	Impl Provider
}

func (*PluginServer) CallTool

func (*PluginServer) ListTools

func (s *PluginServer) ListTools(
	ctx context.Context,
	_ *emptypb.Empty,
) (*toolspb.ListToolsResponse, error)

type Provider

type Provider interface {
	ListTools(*types.PluginContext) ([]Descriptor, error)
	CallTool(*types.PluginContext, CallInput) (*Result, error)
}

Provider is the interface satisfied by the plugin server and client to expose tools to the host.

type Result

type Result struct {
	Content           []Content       `json:"content"`
	StructuredContent json.RawMessage `json:"structuredContent,omitempty"`
	IsError           bool            `json:"isError"`
}

Result is the outcome of a tool call. IsError marks a tool-level failure that the caller (an AI model) should read, as opposed to a transport error.

func ErrorResult

func ErrorResult(format string, args ...any) *Result

ErrorResult returns a tool-level error result.

func JSONResult

func JSONResult(v any) (*Result, error)

JSONResult returns v as indented JSON text and as structured content.

func TextResult

func TextResult(text string) *Result

TextResult returns a plain text result.

type Scope

type Scope string

Scope states what a tool acts on.

const (
	// ScopePlugin tools act on the plugin itself and take no connection.
	ScopePlugin Scope = "plugin"
	// ScopeConnection tools act on one plugin connection. The host resolves
	// the connection and passes it in the PluginContext.
	ScopeConnection Scope = "connection"
)

type Tool

type Tool struct {
	Descriptor
	Handler Handler
}

Tool pairs a descriptor with its handler.

Jump to

Keyboard shortcuts

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