Documentation
¶
Overview ¶
Package tools defines plugin tools, validates their descriptors, and exposes tool discovery and calls over the plugin gRPC transport.
Index ¶
- Constants
- Variables
- func ObjectSchema(properties map[string]any, required ...string) json.RawMessage
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- func ValidateDescriptor(descriptor Descriptor) error
- type Annotations
- type CallInput
- type Content
- type Descriptor
- type EffectiveAnnotations
- type Handler
- type Manager
- func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
- func (m *Manager) BindHostConnections(binding *hostconnections.Binding)
- func (m *Manager) CallTool(ctx *types.PluginContext, input CallInput) (*Result, error)
- func (m *Manager) ListTools(_ *types.PluginContext) ([]Descriptor, error)
- type Plugin
- func (p *Plugin) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
- func (p *Plugin) BindHostConnections(binding *hostconnections.Binding)
- func (p *Plugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn) (any, error)
- func (p *Plugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error
- type PluginClient
- type PluginOpts
- type PluginServer
- type Provider
- type Result
- type Scope
- type Tool
Constants ¶
const ( ErrorExecutionFailed = "EXECUTION_FAILED" ErrorPermissionDenied = "PERMISSION_DENIED" )
Safe error codes are a closed vocabulary. Diagnostic strings never cross this boundary.
const ContractVersion uint32 = 2
ContractVersion identifies exclusive tools.v2 explicit-route/native-admission semantics.
const (
// PluginID identifies the tools capability in the plugin registry.
PluginID = "tools"
)
Variables ¶
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) ListTools ¶
func (m *Manager) ListTools(_ *types.PluginContext) ([]Descriptor, error)
ListTools returns the descriptors in registration order.
type Plugin ¶
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 ¶
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 ¶
func (s *PluginServer) CallTool( ctx context.Context, in *toolspb.CallToolRequest, ) (*toolspb.CallToolResponse, error)
CallTool invokes the provider and maps provider errors to gRPC status codes.
func (*PluginServer) ListTools ¶
func (s *PluginServer) ListTools( ctx context.Context, in *toolspb.ListToolsRequest, ) (*toolspb.ListToolsResponse, error)
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 ¶
ErrorResult creates a local failure. Diagnostic text is removed at dispatch.
func JSONResult ¶
JSONResult returns v as indented JSON text and as structured content.
type Tool ¶
type Tool struct {
Descriptor
Handler Handler
}
Tool pairs a descriptor with its handler.