Documentation
¶
Index ¶
- Constants
- Variables
- func ObjectSchema(properties map[string]any, required ...string) json.RawMessage
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- type Annotations
- type CallInput
- type Content
- type Descriptor
- type Handler
- type Manager
- type Plugin
- type PluginClient
- type PluginOpts
- type PluginServer
- type Provider
- type Result
- type Scope
- type Tool
Constants ¶
const (
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 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) ListTools ¶
func (m *Manager) ListTools(_ *types.PluginContext) ([]Descriptor, error)
ListTools returns the descriptors in registration order.
type Plugin ¶
func (*Plugin) GRPCClient ¶
func (p *Plugin) GRPCClient( _ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn, ) (interface{}, error)
func (*Plugin) GRPCServer ¶
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 (s *PluginServer) CallTool( ctx context.Context, in *toolspb.CallToolRequest, ) (*toolspb.CallToolResponse, error)
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 ¶
ErrorResult returns a tool-level error result.
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.