Documentation
¶
Overview ¶
Package plugin defines a minimal plugin interface and a Manager that bridges plugins into the mcprouter as Backends.
Index ¶
- Variables
- type Config
- type EchoPlugin
- func (p *EchoPlugin) HandleMCPTool(_ context.Context, req ToolRequest) (ToolResponse, error)
- func (p *EchoPlugin) Init(cfg Config) error
- func (p *EchoPlugin) ListTools() []*mcp.Tool
- func (p *EchoPlugin) Meta() Meta
- func (p *EchoPlugin) Start(_ context.Context) error
- func (p *EchoPlugin) Stop(_ context.Context) error
- type Manager
- func (m *Manager) Disable(id string) error
- func (m *Manager) Enable(ctx context.Context, id string) error
- func (m *Manager) Get(id string) (PluginInfo, error)
- func (m *Manager) IsEnabled(id string) bool
- func (m *Manager) List() []PluginInfo
- func (m *Manager) PluginFor(id string) Plugin
- func (m *Manager) Register(p Plugin, cfg Config) error
- func (m *Manager) SetConfig(id string, cfg Config) error
- func (m *Manager) StopAll(ctx context.Context)
- func (m *Manager) Unregister(ctx context.Context, id string) error
- type Meta
- type Plugin
- type PluginBackend
- type PluginInfo
- type ToolRequest
- type ToolResponse
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPluginRequired is returned when a nil plugin is registered. ErrPluginRequired = errors.New("plugin: plugin is required") // ErrPluginIDRequired is returned when the plugin ID is empty. ErrPluginIDRequired = errors.New("plugin: id is required") // ErrPluginExists is returned when a plugin with the same ID is registered. ErrPluginExists = errors.New("plugin: already registered") // ErrPluginNotFound is returned when a plugin is missing. ErrPluginNotFound = errors.New("plugin: not found") )
Functions ¶
This section is empty.
Types ¶
type EchoPlugin ¶
type EchoPlugin struct {
// contains filtered or unexported fields
}
EchoPlugin is a built-in test plugin that echoes its arguments. It advertises a single "echo" tool.
func NewEchoPlugin ¶
func NewEchoPlugin(prefix string) *EchoPlugin
NewEchoPlugin creates an EchoPlugin with the given prefix (defaults to "echo" if empty).
func (*EchoPlugin) HandleMCPTool ¶
func (p *EchoPlugin) HandleMCPTool(_ context.Context, req ToolRequest) (ToolResponse, error)
HandleMCPTool echoes the "message" arg.
func (*EchoPlugin) Init ¶
func (p *EchoPlugin) Init(cfg Config) error
Init accepts a "prefix" config key to override the echo prefix.
func (*EchoPlugin) ListTools ¶
func (p *EchoPlugin) ListTools() []*mcp.Tool
ListTools returns the "echo" tool.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the plugin registry and runtime state.
func (*Manager) Disable ¶
Disable marks a plugin as disabled but does not stop it. The plugin's tools will no longer be advertised.
func (*Manager) Get ¶
func (m *Manager) Get(id string) (PluginInfo, error)
Get returns the plugin metadata + enabled state by ID.
func (*Manager) List ¶
func (m *Manager) List() []PluginInfo
List returns metadata for all registered plugins, including enabled state.
func (*Manager) Register ¶
Register adds a plugin to the registry. The plugin is not started until Enable is called.
func (*Manager) SetConfig ¶
SetConfig updates a plugin's config and re-inits it. The plugin is stopped before re-init and must be re-enabled to restart.
type Meta ¶
type Meta struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Version string `json:"version,omitempty"`
}
Meta describes a plugin's identity.
type Plugin ¶
type Plugin interface {
Meta() Meta
Init(cfg Config) error
Start(ctx context.Context) error
Stop(ctx context.Context) error
HandleMCPTool(ctx context.Context, req ToolRequest) (ToolResponse, error)
ListTools() []*mcp.Tool
}
Plugin is the interface plugins implement. The Manager owns lifecycle (Init/Start/Stop) and routes tool calls via HandleMCPTool.
type PluginBackend ¶
type PluginBackend struct {
// contains filtered or unexported fields
}
PluginBackend bridges a Plugin into the mcprouter.Backend interface. Tool calls are routed to Plugin.HandleMCPTool; tool listings come from Plugin.ListTools.
func NewPluginBackend ¶
func NewPluginBackend(id string, mgr *Manager) (*PluginBackend, error)
NewPluginBackend creates a backend for the named plugin. The plugin must be registered and enabled before CallTool is called.
func (*PluginBackend) CallTool ¶
func (b *PluginBackend) CallTool(ctx context.Context, name string, args map[string]any) (*mcp.CallToolResult, error)
CallTool routes the call to the plugin's HandleMCPTool.
func (*PluginBackend) ListTools ¶
ListTools returns the plugin's advertised tools. If the plugin is not enabled, returns an empty list.
func (*PluginBackend) Name ¶
func (b *PluginBackend) Name() string
Name returns the plugin ID as the backend name.
type PluginInfo ¶
PluginInfo pairs a plugin's metadata with its enabled state.
type ToolRequest ¶
ToolRequest is what the router hands to a plugin when a tool is called.
type ToolResponse ¶
type ToolResponse struct {
Content string `json:"content"`
IsError bool `json:"isError,omitempty"`
}
ToolResponse is what the plugin hands back. Content is rendered as TextContent; IsError marks the result as an error.