tools

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0 Imports: 24 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

Overview

Package tools defines plugin tools, validates their descriptors, and exposes tool discovery and calls over the plugin gRPC transport.

Index

Constants

View Source
const (
	ErrorExecutionFailed  = "EXECUTION_FAILED"
	ErrorUnavailable      = "UNAVAILABLE"
	ErrorPermissionDenied = "PERMISSION_DENIED"
)

Safe error codes are a closed vocabulary. Diagnostic strings never cross this boundary.

View Source
const ContractVersion uint32 = 2

ContractVersion identifies exclusive tools.v2 explicit-route/native-admission semantics.

View Source
const (
	// PluginID identifies the tools capability in the plugin registry.
	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 an explicit, nonempty body route.
	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.

func ValidateDescriptor added in v0.9.0

func ValidateDescriptor(descriptor Descriptor) error

ValidateDescriptor validates tool metadata without requiring a handler. It uses the same bounded schema profile as registration, does not mutate the descriptor, and performs no tool execution or native connection work. Returned diagnostics are for local use, not model-facing presentation.

Types

type Annotations

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

Annotations are the MCP tool annotation hints.

func (Annotations) Resolve added in v0.9.0

func (a Annotations) Resolve() EffectiveAnnotations

Resolve preserves explicit false values while applying MCP defaults.

type CallInput

type CallInput struct {
	Name            string
	Arguments       json.RawMessage
	Route           *resourcev2.AccessRoute
	DelegationToken []byte
}

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"`
	ConnectionOwner string          `json:"connectionOwner,omitempty"`
}

Descriptor describes one tool to the host.

type EffectiveAnnotations added in v0.9.0

type EffectiveAnnotations struct {
	ReadOnly, Destructive, Idempotent, OpenWorld bool
}

EffectiveAnnotations contains MCP defaults, not authorization decisions.

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) BindConnectionContextProvider added in v0.9.0

func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)

BindConnectionContextProvider installs the sole native registry during setup, before requests are served, matching the other utility managers.

func (*Manager) BindHostConnections added in v0.13.0

func (m *Manager) BindHostConnections(binding *hostconnections.Binding)

BindHostConnections shares the process callback binding.

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
}

Plugin exposes a tools provider through the go-plugin gRPC transport.

func (*Plugin) BindConnectionContextProvider added in v0.9.0

func (p *Plugin) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)

BindConnectionContextProvider forwards native registry binding to the provider.

func (*Plugin) BindHostConnections added in v0.13.0

func (p *Plugin) BindHostConnections(binding *hostconnections.Binding)

BindHostConnections installs the process-wide callback binding.

func (*Plugin) GRPCClient

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

GRPCClient creates a tools client for the plugin's gRPC connection.

func (*Plugin) GRPCServer

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

GRPCServer registers the tools provider with the plugin's gRPC server.

type PluginClient

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

PluginClient calls a remote tools provider over gRPC.

func (*PluginClient) CallTool

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

CallTool invokes a remote tool using the caller's cancellation and deadline.

func (*PluginClient) ListTools

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

ListTools retrieves the remote tool descriptors using the caller's context.

type PluginOpts

type PluginOpts struct {
	Tools []Tool
}

PluginOpts lists the tools a plugin exposes.

type PluginServer

type PluginServer struct {
	toolspb.UnimplementedToolsPluginServer

	Impl Provider
}

PluginServer serves a tools provider over gRPC.

func (*PluginServer) CallTool

CallTool invokes the provider and maps provider errors to gRPC status codes.

func (*PluginServer) ListTools

ListTools returns the provider's tool descriptors for the caller's plugin context.

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"`
	ErrorCode         string          `json:"errorCode,omitempty"`
}

Result is the outcome of a tool call. IsError results expose only reviewed, fixed safe presentation; diagnostic content stays local.

func ErrorResult

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

ErrorResult creates a local failure. Diagnostic text is removed at dispatch.

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 configured connection selected by an
	// explicit CallInput route and admitted by the native connection registry.
	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