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, and Progress reports on a long-running call.
Index ¶
- Constants
- func Admin(t *mcp.Tool) *mcp.Tool
- func Caller(req *mcp.CallToolRequest) (person, via string)
- func CheckToolName(pluginID, tool string) error
- func DataDir() (string, error)
- func I18n(t *mcp.Tool, lang string, text Text) *mcp.Tool
- func Inventory(t *mcp.Tool) *mcp.Tool
- func InventoryRef(prop map[string]any) map[string]any
- func New(p Plugin) *mcp.Server
- func Progress(ctx context.Context, req *mcp.CallToolRequest, progress, total float64, ...) error
- func Serve(ctx context.Context, s *mcp.Server) error
- func Timeout(t *mcp.Tool, d time.Duration) *mcp.Tool
- type Plugin
- type Text
Constants ¶
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.
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.
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 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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 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.