Documentation
¶
Overview ¶
Package plugin defines the universal plugin SDK surface that both a host application and its plugins import.
The package is host-neutral: it has zero dependencies on any specific product code path. A host extends the base contract here with host-specific registration methods in its own public package; a plugin imports this package directly.
Layout:
github.com/hollis-labs/libs/mcp/plugin-mcp/plugin-sdk Plugin, Host, CRUDHandler, EventHook, UIComponent, errors, EnvelopeOut/MessageOut, Logger.
github.com/hollis-labs/libs/mcp/plugin-mcp/plugin-sdk/subprocess Subprocess server library (Serve), JSON-RPC 2.0 wire protocol, plugin-side capability interfaces (CommandHandler, EventHandler, MCPHandler, HTTPHandler, Migrator, ...), and stderr JSON-lines logging.
github.com/hollis-labs/libs/mcp/plugin-mcp/plugin-sdk/subprocess/subprocesstest In-process test harness for driving plugins without spawning a subprocess.
See the examples directory for runnable plugins, and the README for versioning and release status.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCancelled = errors.New("plugin: action cancelled by hook")
ErrCancelled is returned by an EventHook's Handle method to signal that the pre-hook action should be cancelled. Only meaningful for pre-hook events (e.g., message.sending, tool.executing). Regular post-events ignore this value.
Functions ¶
This section is empty.
Types ¶
type CRUDHandler ¶
type CRUDHandler interface {
Create(ctx context.Context, resource interface{}) (interface{}, error)
Read(ctx context.Context, id string) (interface{}, error)
Update(ctx context.Context, id string, resource interface{}) (interface{}, error)
Delete(ctx context.Context, id string) error
List(ctx context.Context, filters map[string]interface{}) ([]interface{}, error)
}
CRUDHandler defines CRUD operations for plugin-provided resources.
type ConfigFieldDef ¶
type ConfigFieldDef struct {
Key string `json:"key"`
Type string `json:"type"` // "string", "bool", "int", "select", "secret"
Label string `json:"label"`
Description string `json:"description,omitempty"`
Default any `json:"default,omitempty"`
Required bool `json:"required,omitempty"`
Options []string `json:"options,omitempty"` // for "select" type
Component string `json:"component,omitempty"` // custom React component (requires developer_mode)
}
ConfigFieldDef defines a single configuration field for frontend rendering.
type Connector ¶
type Connector interface {
Name() string
Send(ctx context.Context, payload map[string]interface{}) error
Health(ctx context.Context) error
}
Connector is the interface for outbound integrations (email, webhook, Slack, etc.).
type EnvelopeOut ¶
type EnvelopeOut struct {
// Type is the envelope type identifier, e.g. "oembed.card" or
// "support-ticket.created". Must match one of the types declared in
// the plugin's plugin.yaml registers.envelopes section.
Type string `json:"type"`
// Data is the envelope payload. Validated against the schema
// registered for Type.
Data map[string]interface{} `json:"data"`
// SessionID routes the envelope to a specific chat session. Empty
// means broadcast to all listeners.
SessionID string `json:"session_id,omitempty"`
}
EnvelopeOut is an envelope emitted by a plugin as the result of a command, event handler, or MCP tool call. Envelopes are validated by the host against the plugin's declared envelope types and their JSON Schemas before being surfaced to the UI.
Envelope-type registration is declarative: plugins declare envelope types in plugin.yaml and return EnvelopeOut values from capability handlers. Plugins do not register envelope types programmatically.
type Error ¶
Error is a typed plugin error that carries an HTTP-friendly status code plus a stable code constant for wire-protocol mapping. Plugin CRUD handlers should return these instead of plain errors so the host can translate them into HTTP status codes and JSON-RPC error objects.
PluginError is a backward-compatibility alias retained for callers that imported the type under its older name; new code should use Error directly.
type Event ¶
type Event struct {
Type string `json:"type"`
Source string `json:"source"`
Timestamp time.Time `json:"timestamp"`
Data map[string]interface{} `json:"data"`
SessionID string `json:"session_id,omitempty"`
}
Event represents an event in the system.
type EventHook ¶
type EventHook interface {
// Handle processes an event. Returning ErrCancelled from a pre-hook
// event (e.g., message.sending) cancels the pending action.
Handle(ctx context.Context, event Event) error
// EventTypes returns the list of event types this hook handles.
EventTypes() []string
// PluginID returns the ID of the owning plugin. The host uses this to
// remove all hooks belonging to a plugin during unload.
PluginID() string
}
EventHook processes events from the host application.
Implementations MUST report the ID of the plugin that owns them via PluginID so the host can cleanly unregister hooks during unload. Hooks without a PluginID cannot be cleanly removed at unload and are a known source of leak bugs.
type Host ¶
type Host interface {
// GetPlugin retrieves another loaded plugin by ID.
GetPlugin(id string) (Plugin, bool)
// RegisterCRUDHandler registers a CRUD handler for a resource type.
RegisterCRUDHandler(resourceType string, handler CRUDHandler) error
// RegisterEventHook registers an event hook for specific event types.
RegisterEventHook(eventTypes []string, hook EventHook) error
// RegisterUIComponent registers UI components for the frontend.
RegisterUIComponent(component UIComponent) error
// GetService provides access to core services (MCP clients, databases, etc.).
GetService(name string) (interface{}, error)
// GetConfig returns a plugin configuration value.
// Resolution order: env var -> DB setting -> config file -> default.
// Returns an error if the key is required and not found.
GetConfig(key string) (string, error)
// SetConfig persists a configuration value for the calling plugin.
SetConfig(key string, value string) error
// RegisterConfigSchema registers the config field definitions for the
// calling plugin. The frontend reads this schema to render settings
// forms automatically.
RegisterConfigSchema(fields []ConfigFieldDef) error
// RegisterConnector registers a named outbound connector (webhook, email, etc.).
RegisterConnector(name string, connector Connector) error
// RegisterProvider registers a runtime LLM provider.
RegisterProvider(name string, provider interface{}) error
// RegisterCLIAdapter registers a runtime CLI adapter for PTY/subprocess bridges.
RegisterCLIAdapter(name string, adapter interface{}) error
// Logger provides a logger instance for the plugin.
Logger() Logger
// Context returns the plugin's execution context.
Context() context.Context
}
Host provides the runtime environment and services available to plugins. This is the base Host contract — host applications may extend it with additional registration methods in their own public package (for example, adding RegisterCommand / RegisterSlot / RegisterKeybinding in a host's own pkg/plugin package).
type Installable ¶
Installable is an optional interface plugins implement to run setup logic during first-time installation. If not implemented, Load handles all setup.
type Logger ¶
type Logger interface {
Debug(msg string, keysAndValues ...interface{})
Info(msg string, keysAndValues ...interface{})
Warn(msg string, keysAndValues ...interface{})
Error(msg string, keysAndValues ...interface{})
With(keysAndValues ...interface{}) Logger
}
Logger provides structured logging capabilities for plugins. Hosts supply an implementation via Host.Logger(); plugins running as subprocesses use the stderr JSON-lines logger from github.com/hollis-labs/libs/mcp/plugin-mcp/plugin-sdk/subprocess.
type MessageOut ¶
type MessageOut struct {
// SessionID is the chat session to post into.
SessionID string `json:"session_id"`
// Role is the message role: "assistant", "system", or "tool".
Role string `json:"role"`
// Content is the message body (markdown).
Content string `json:"content"`
// Envelopes are optional envelopes to attach alongside the message.
Envelopes []EnvelopeOut `json:"envelopes,omitempty"`
}
MessageOut is a chat message produced by a plugin. Typically used by command handlers that want to inject a message into the session rather than emit a rendered envelope.
type Plugin ¶
type Plugin interface {
// ID returns a unique identifier for this plugin.
ID() string
// Name returns the human-readable name of the plugin.
Name() string
// Version returns the plugin version.
Version() string
// Description returns a brief description of the plugin's purpose.
Description() string
// Dependencies returns a list of required plugin IDs this plugin depends on.
Dependencies() []string
// Load is called when the plugin is loaded into the host.
Load(host Host) error
// Unload is called when the plugin is being removed.
Unload() error
// Status returns the current status of the plugin.
Status() PluginStatus
}
Plugin is the minimum contract a plugin must implement. Optional capability interfaces (CRUDHandler, EventHook, Installable, Uninstallable, Connector) are detected via type assertion at registration time.
type PluginError
deprecated
type PluginError = Error
PluginError is a backward-compatible alias for Error.
Deprecated: use Error directly. This alias will be removed in a future release.
type PluginStatus ¶
type PluginStatus struct {
Loaded bool `json:"loaded"`
Enabled bool `json:"enabled"`
LoadedAt time.Time `json:"loaded_at"`
LastError string `json:"last_error,omitempty"`
}
PluginStatus represents the current state of a plugin.
type UIComponent ¶
type UIComponent struct {
ID string `json:"id"`
Type UIComponentType `json:"type"`
Name string `json:"name"`
Description string `json:"description"`
Props map[string]interface{} `json:"props,omitempty"`
// Handler is used for server-side rendering (compiled-in plugins only).
// Subprocess plugins cannot carry an http.Handler across the wire and
// must leave this nil.
Handler http.Handler `json:"-"`
}
UIComponent represents a UI component that can be rendered in the frontend.
type UIComponentType ¶
type UIComponentType string
UIComponentType defines the type of UI component.
const ( UIComponentTypeWidget UIComponentType = "widget" UIComponentTypeEnvelope UIComponentType = "envelope" UIComponentTypeAction UIComponentType = "action" UIComponentTypeWorkflow UIComponentType = "workflow" UIComponentTypeView UIComponentType = "view" )
type Uninstallable ¶
Uninstallable is an optional interface plugins implement to clean up artifacts during uninstallation. User-created data is preserved.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package capability supplies host-neutral capability descriptors, exact-match scope narrowing and safe typed application failures.
|
Package capability supplies host-neutral capability descriptors, exact-match scope narrowing and safe typed application failures. |
|
host/hosttest
Package hosttest runs behavioral capability conformance through a host's actual admission, dispatcher, lifecycle and non-plugin bridge adapters.
|
Package hosttest runs behavioral capability conformance through a host's actual admission, dispatcher, lifecycle and non-plugin bridge adapters. |
|
examples
|
|
|
hello
command
Hello is the minimum-viable subprocess plugin: a plugin that uses only plugin-sdk imports, fits in roughly fifty lines, and handles a full init / load / unload lifecycle plus a single command.
|
Hello is the minimum-viable subprocess plugin: a plugin that uses only plugin-sdk imports, fits in roughly fifty lines, and handles a full init / load / unload lifecycle plus a single command. |
|
manifest
command
Command manifest emits a generated plugin.yaml declaration on stdout.
|
Command manifest emits a generated plugin.yaml declaration on stdout. |
|
internal
|
|
|
strictjson
Package strictjson checks JSON tokens before decoding can discard duplicate keys.
|
Package strictjson checks JSON tokens before decoding can discard duplicate keys. |
|
Package manifest defines the host-neutral declaration emitted by a plugin binary and reviewed before the host starts it.
|
Package manifest defines the host-neutral declaration emitted by a plugin binary and reviewed before the host starts it. |
|
protocol
|
|
|
v1
Code generated by generate.py; DO NOT EDIT.
|
Code generated by generate.py; DO NOT EDIT. |
|
Package registry defines the registry-v2 host-authoritative contribution catalog.
|
Package registry defines the registry-v2 host-authoritative contribution catalog. |
|
Package subprocess carries the JSON-RPC 2.0 wire protocol used for host-to-plugin communication over stdio.
|
Package subprocess carries the JSON-RPC 2.0 wire protocol used for host-to-plugin communication over stdio. |
|
subprocesstest
Package subprocesstest provides an in-process test harness for subprocess plugins.
|
Package subprocesstest provides an in-process test harness for subprocess plugins. |