pluginkit

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 12 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 pluginkit helps write Homie plugins in Go.

A plugin is an executable that the hub starts with the argument "serve". It speaks MCP over stdio (newline-delimited JSON-RPC on stdin and stdout) and writes its log to stderr. See docs/PLUGINS.md for the full contract.

A minimal plugin:

s := pluginkit.New(pluginkit.Plugin{ID: "echo", Name: "homie-echo", Title: "Echo", Version: "0.1.0"})
mcp.AddTool(s, &mcp.Tool{Name: "echo_say", Description: "Repeats the text back."}, say)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
if err := pluginkit.Serve(ctx, s); err != nil {
	log.Fatal(err)
}

The tool helpers (Admin, Timeout, Inventory, I18n) set the tool _meta keys the hub understands and return the same tool, so they chain: pluginkit.Admin(pluginkit.Timeout(tool, 3*time.Minute)). InventoryRef marks an input property that names a device, Progress reports on a long-running call, and Ask asks the person who runs a call in the admin for input, then Answer reads the reply in the same call.

Index

Constants

View Source
const (
	MetaAudience = "homie/audience" // "admin" hides a tool from assistants; the default is "assistant"
	MetaTimeout  = "homie/timeout"  // the hub-side call timeout in seconds
	MetaRole     = "homie/role"     // "inventory" marks the device-list tool
	MetaI18n     = "homie/i18n"     // translated texts: tool _meta (see I18n) and progress _meta (see Progress)
	MetaCaller   = "homie/caller"   // request _meta: the person's display name
	MetaVia      = "homie/via"      // request _meta: "chatgpt", "claude", "admin" or "cli"
)

Tool _meta keys and request _meta keys of the plugin protocol.

View Source
const (
	SchemaRef    = "x-homie-ref"
	RefInventory = "inventory"
)

SchemaRef is the input property schema keyword that links a property to something the hub knows; its only value is RefInventory. See InventoryRef.

View Source
const (
	EnvPluginID   = "HOMIE_PLUGIN_ID"
	EnvDataDir    = "HOMIE_DATA_DIR"
	EnvLogLevel   = "HOMIE_LOG_LEVEL"
	EnvHubVersion = "HOMIE_HUB_VERSION"
)

Environment variables the hub sets for a plugin.

Variables

This section is empty.

Functions

func Admin

func Admin(t *mcp.Tool) *mcp.Tool

Admin hides t from assistants: only the admin UI and the homed CLI see it.

func Ask added in v0.3.0

func Ask(key string, q Question, state string) *mcp.CallToolResult

Ask returns the result that asks q. key names the question; Answer reads the reply under it in the next round. state comes back unchanged in that round (State): keep there what the round needs, e.g. the id of what the first round started. It passes through the hub, so a plugin that needs more than an id there must protect it.

func Caller

func Caller(req *mcp.CallToolRequest) (person, via string)

Caller returns who asked for this call, from the request _meta the hub adds. Both are empty when the call did not come through the hub. Log them if useful, but never trust them for security.

func CheckToolName

func CheckToolName(pluginID, tool string) error

CheckToolName reports whether tool is a valid name for a tool of plugin pluginID: "<pluginID>_<verb>", where the plugin id matches ^[a-z][a-z0-9]{1,15}$ and the verb ^[a-z][a-z0-9_]*$. The hub skips tools that fail it.

func DataDir

func DataDir() (string, error)

DataDir returns the plugin's persistent data directory: HOMIE_DATA_DIR when the hub runs the plugin, otherwise ./data for development. The directory is created with mode 0700 if it is missing.

func I18n

func I18n(t *mcp.Tool, lang string, text Text) *mcp.Tool

I18n adds the texts of t in lang (a language tag such as "ru") to its _meta "homie/i18n". Calling it again for another language adds that language; for the same language it replaces the texts. Empty fields are left out.

func Inventory

func Inventory(t *mcp.Tool) *mcp.Tool

Inventory marks t as the plugin's device list. Use it on at most one read-only tool; it must return {"items":[{"id","name","subtitle"?,"state"?}]} with state one of on|off|offline|unknown|paired|unpaired.

func InventoryRef

func InventoryRef(prop map[string]any) map[string]any

InventoryRef marks an input property schema as a device id from the plugin's inventory tool, so the admin shows a device picker for it. It sets "x-homie-ref": "inventory" on prop and returns it; a nil prop becomes a new map. For a *jsonschema.Schema, set Extra[SchemaRef] = RefInventory instead.

func New

func New(p Plugin) *mcp.Server

New returns a go-sdk server with the plugin's identity and instructions set. Its log goes to stderr at the level of HOMIE_LOG_LEVEL (default info). It panics when p.ID breaks the plugin id rule, like mcp.AddTool panics on a bad tool: both are programming errors.

func Progress

func Progress(ctx context.Context, req *mcp.CallToolRequest, progress, total float64, message string, i18n map[string]string) error

Progress reports how far a long-running call is, when the hub asked for reports (the request carries a progress token); otherwise it does nothing and returns nil. progress must grow with every report; total is 0 when unknown. message is short English for a person ("Press OK on the TV remote"), and i18n holds its translations by language ({"ru": "Нажмите OK на пульте телевизора"}); both are optional.

func Serve

func Serve(ctx context.Context, s *mcp.Server) error

Serve runs s over stdio until ctx is done or stdin is closed. Both are a normal shutdown and return nil.

func State added in v0.3.0

func State(req *mcp.CallToolRequest) string

State returns the state Ask passed in the round before; "" in the first round.

func Timeout

func Timeout(t *mcp.Tool, d time.Duration) *mcp.Tool

Timeout sets the hub-side call timeout of t, in whole seconds rounded up. The hub default is 30 s and its maximum is 300 s.

Types

type Plugin

type Plugin struct {
	ID           string // "tv"; every tool name starts with "<ID>_"
	Name         string // "homie-tv" (serverInfo.name)
	Title        string // "TV" (serverInfo.title)
	Version      string // semver
	Instructions string // optional short English guidance for the model
}

Plugin is the identity a plugin reports in its MCP initialize result.

type Question added in v0.3.0

type Question struct {
	// Message says what to do, in English: "Enter the code the TV shows on its screen."
	Message string
	// Schema is the form: a JSON Schema object of primitive properties only (string, number, integer, boolean,
	// string enum), as MCP elicitation allows; e.g. {"type":"object","properties":{"code":{"type":"string",
	// "title":"Code","minLength":1}},"required":["code"]}.
	Schema map[string]any
	// I18n holds Message and the property labels translated, by language ("ru"). Optional.
	I18n map[string]QuestionText
}

Question is what a tool asks: a message and a small form.

type QuestionText added in v0.3.0

type QuestionText struct {
	Message    string
	Properties map[string]string // property name → label, e.g. "code" → "Код с экрана"
}

QuestionText is a question's message and property labels in one language.

type Reply added in v0.3.0

type Reply struct {
	// Action is "accept" (the form was sent), "decline" (they said no) or "cancel" (they closed the question).
	Action string
	// Content holds the form's values when Action is "accept".
	Content map[string]any
}

Reply is the person's answer to a question.

func Answer added in v0.3.0

func Answer(req *mcp.CallToolRequest, key string) (Reply, bool)

Answer returns the reply to the question key in a round the hub ran because of Ask; ok is false in the first round.

func (Reply) Accepted added in v0.3.0

func (r Reply) Accepted() bool

Accepted reports whether the person sent the form.

func (Reply) String added in v0.3.0

func (r Reply) String(name string) string

String returns the text value of the property name, trimmed; "" when it is missing or not a string.

type Text

type Text struct {
	Title       string
	Description string
	Properties  map[string]string // input property name → label, e.g. "percent" → "Громкость, %"
}

Text is a tool's title, description and input labels in one language. The admin UI shows them; assistants always get the tool's English title and description.

Directories

Path Synopsis
Command example is a minimal Homie plugin built on pluginkit.
Command example is a minimal Homie plugin built on pluginkit.

Jump to

Keyboard shortcuts

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