plugin

package
v0.0.0-...-ea39c83 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 8 Imported by: ? 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 plugin defines a minimal plugin interface and a Manager that bridges plugins into the mcprouter as Backends.

Index

Constants

This section is empty.

Variables

View Source
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 Config

type Config map[string]string

Config is the per-plugin configuration map.

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.

func (*EchoPlugin) Meta

func (p *EchoPlugin) Meta() Meta

Meta returns the plugin metadata.

func (*EchoPlugin) Start

func (p *EchoPlugin) Start(_ context.Context) error

Start is a no-op.

func (*EchoPlugin) Stop

func (p *EchoPlugin) Stop(_ context.Context) error

Stop is a no-op.

type Manager

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

Manager owns the plugin registry and runtime state.

func NewManager

func NewManager() *Manager

NewManager creates an empty Manager.

func (*Manager) Disable

func (m *Manager) Disable(id string) error

Disable marks a plugin as disabled but does not stop it. The plugin's tools will no longer be advertised.

func (*Manager) Enable

func (m *Manager) Enable(ctx context.Context, id string) error

Enable starts a plugin and marks it as enabled.

func (*Manager) Get

func (m *Manager) Get(id string) (PluginInfo, error)

Get returns the plugin metadata + enabled state by ID.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled(id string) bool

IsEnabled returns true if the plugin exists and is enabled.

func (*Manager) List

func (m *Manager) List() []PluginInfo

List returns metadata for all registered plugins, including enabled state.

func (*Manager) PluginFor

func (m *Manager) PluginFor(id string) Plugin

PluginFor returns the underlying Plugin if enabled, or nil.

func (*Manager) Register

func (m *Manager) Register(p Plugin, cfg Config) error

Register adds a plugin to the registry. The plugin is not started until Enable is called.

func (*Manager) SetConfig

func (m *Manager) SetConfig(id string, cfg Config) error

SetConfig updates a plugin's config and re-inits it. The plugin is stopped before re-init and must be re-enabled to restart.

func (*Manager) StopAll

func (m *Manager) StopAll(ctx context.Context)

StopAll stops every running plugin. Used during graceful shutdown.

func (*Manager) Unregister

func (m *Manager) Unregister(ctx context.Context, id string) error

Unregister removes a plugin. The plugin is stopped first.

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

func (b *PluginBackend) ListTools(_ context.Context) ([]*mcp.Tool, error)

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

type PluginInfo struct {
	Meta    Meta `json:"meta"`
	Enabled bool `json:"enabled"`
}

PluginInfo pairs a plugin's metadata with its enabled state.

type ToolRequest

type ToolRequest struct {
	Tool string         `json:"tool"`
	Args map[string]any `json:"args"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL