Documentation
¶
Overview ¶
Package cliagent turns an explicit, reviewed description of an existing command-line tool into coding-agent host plugins (Codex, Claude Code and Cursor) and serves that description as a stdio MCP server.
The package does not infer capabilities. A Spec names one canonical executable, a version probe, and a finite list of tools. Each tool is a fixed argv prefix followed by named, typed inputs rendered as flags or positional arguments. Anything the specification does not declare cannot be invoked: there is no shell, no generic command tool and no executable chosen by tool arguments.
Render produces deterministic plugin files, Generate writes them to an absent or empty directory without overwriting, and Check detects drift read-only. NewRunner resolves and probes the installed CLI, and NewServer exposes the declared tools through the official MCP Go SDK.
Tool annotations and input schemas describe declared effects; they are not authorization, sandboxing or approval. The CLI runs with the caller's environment and the same trust as invoking it directly, and its output may contain anything the CLI prints, including secrets. See docs/cli-agent-plugins.md for the contract, limits and evidence.
Index ¶
- Constants
- Variables
- func Check(s *Spec, outDir string) error
- func Generate(s *Spec, outDir string) error
- func NewServer(r *Runner) *mcp.Server
- func Paths(s *Spec) ([]string, error)
- type Author
- type CLI
- type Effects
- type File
- type Input
- type Limits
- type Plugin
- type Result
- type Runner
- type RunnerOptions
- type Skill
- type Spec
- type Tool
- type VersionProbe
Constants ¶
const ( HostCodex = "codex" HostClaudeCode = "claude-code" HostCursor = "cursor" )
Hosts rendered by Render, in output order.
const ( MaxSpecBytes = 256 << 10 // MaxInlineSpecBytes leaves headroom below Linux's 128 KiB per-argument // exec limit. Validate measures canonical JSON, including escaping. MaxInlineSpecBytes = 96 << 10 MaxTimeoutSeconds = 600 MaxOutputBytes = 1 << 20 MaxConcurrent = 16 MaxTools = 64 MaxInputsPerTool = 32 MaxArgvPrefix = 16 MaxArgLength = 256 MaxStringInput = 64 << 10 DefaultStringInput = 4096 MaxEnumValues = 64 MaxInstructions = 64 << 10 )
Bounds enforced by Spec.Validate. They are deliberately small: a spec is reviewed by a person and embedded inline in host MCP configuration.
const ( TypeString = "string" TypeBoolean = "boolean" TypeInteger = "integer" )
Input types.
const ( CostNone = "none" CostPossible = "possible" )
Cost values.
const CodexMarketplacePath = ".agents/plugins/marketplace.json"
CodexMarketplacePath is the local Codex marketplace catalog, relative to the output root. Its single entry points at the codex host folder, so the output root is a marketplace source for `codex plugin marketplace add`.
const DefaultKillGrace = 5 * time.Second
DefaultKillGrace is how long a canceled or timed-out process group has after SIGTERM before SIGKILL.
const SchemaVersion = 1
SchemaVersion is the only accepted Spec.SchemaVersion.
const ServerCommand = "amsl-agent-plugin"
ServerCommand is the executable host MCP configuration starts. It must be installed on PATH alongside the described CLI.
Variables ¶
var ErrBusy = errors.New("cliagent: concurrency limit reached; call rejected")
ErrBusy reports that MaxConcurrent invocations are already running.
var ErrDrift = errors.New("cliagent: generated output drift")
ErrDrift reports that generated output differs from the spec's rendering.
var ErrIncompatibleCLI = errors.New("cliagent: CLI missing or incompatible")
ErrIncompatibleCLI reports a missing executable or failed version probe.
var ErrInvalidArguments = errors.New("cliagent: invalid arguments")
ErrInvalidArguments wraps every tool-argument validation failure.
var ErrInvalidSpec = errors.New("cliagent: invalid spec")
ErrInvalidSpec wraps every specification validation failure.
var ErrOutputExists = errors.New("cliagent: output directory must be absent or empty")
ErrOutputExists reports that the output directory is not absent or empty.
var ErrUnknownTool = errors.New("cliagent: unknown tool")
ErrUnknownTool reports a tool name the spec does not declare.
var Hosts = []string{HostCodex, HostClaudeCode, HostCursor}
Hosts lists every rendered host directory.
Functions ¶
func Check ¶
Check compares outDir with the rendering of s without modifying anything. It reports missing, changed and unexpected files, symlinks and non-regular entries, and returns an error wrapping ErrDrift listing every problem.
func Generate ¶
Generate renders s into outDir. outDir must be absent or an empty real directory other than the process working directory; nothing existing is overwritten or deleted. Files are staged in a sibling temporary directory and moved into place with a single rename, so a failure leaves no partial output and a concurrent writer cannot be clobbered. An existing empty outDir is removed with rmdir (which fails if it gained content) immediately before the rename; rename never replaces a non-empty directory.
Types ¶
type CLI ¶
type CLI struct {
// Executable is a bare command name resolved once through PATH at startup.
Executable string `json:"executable"`
// Install is human setup guidance rendered into README files.
Install string `json:"install"`
VersionProbe VersionProbe `json:"version_probe"`
}
CLI names the canonical executable and how compatibility is checked.
type Effects ¶
type Effects struct {
ReadOnly bool `json:"read_only"`
Destructive bool `json:"destructive"`
Idempotent bool `json:"idempotent"`
Network bool `json:"network"`
Cost string `json:"cost"`
Notes string `json:"notes"`
}
Effects declares what a tool may do. They become MCP annotations and README text; they are hints for hosts and people, never enforcement.
type File ¶
File is one rendered artifact. Path is slash-separated and relative to the output directory.
type Input ¶
type Input struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
Flag string `json:"flag,omitempty"`
Positional bool `json:"positional,omitempty"`
Required bool `json:"required,omitempty"`
Enum []string `json:"enum,omitempty"`
MaxLength int `json:"max_length,omitempty"`
Minimum *int64 `json:"minimum,omitempty"`
Maximum *int64 `json:"maximum,omitempty"`
}
Input is one named argument. Exactly one of Flag or Positional is set.
type Limits ¶
type Limits struct {
TimeoutSeconds int `json:"timeout_seconds"`
// MaxOutputBytes is shared by stdout and stderr of one invocation.
MaxOutputBytes int `json:"max_output_bytes"`
// MaxConcurrent bounds simultaneous invocations; excess calls are rejected.
MaxConcurrent int `json:"max_concurrent"`
}
Limits bound every tool invocation.
type Plugin ¶
type Plugin struct {
Name string `json:"name"`
DisplayName string `json:"display_name,omitempty"`
Version string `json:"version"`
Description string `json:"description"`
Author Author `json:"author"`
Homepage string `json:"homepage,omitempty"`
Repository string `json:"repository,omitempty"`
License string `json:"license,omitempty"`
Keywords []string `json:"keywords,omitempty"`
}
Plugin is host-facing package metadata.
type Result ¶
type Result struct {
Argv []string `json:"argv"`
ExitCode int `json:"exit_code"`
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
Truncated bool `json:"truncated"`
TimedOut bool `json:"timed_out"`
Canceled bool `json:"canceled"`
// WaitError reports incomplete output collection or another wait failure.
WaitError string `json:"wait_error,omitempty"`
}
Result is the structured outcome of one invocation. It never contains usage or cost figures: the runner does not know them.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner invokes declared tools of one resolved executable.
func NewRunner ¶
NewRunner validates s, resolves its executable once through PATH to an absolute path, and runs the version probe. It returns ErrIncompatibleCLI (with the probe output) when the CLI is absent or the probe fails; there is no fallback executable.
func (*Runner) Call ¶
Call validates arguments and runs the named tool. Validation, busy and unknown-tool failures return an error before any process starts; process outcomes (including non-zero exit, timeout and cancellation) are reported in Result.
func (*Runner) Executable ¶
Executable returns the absolute path resolved at startup.
type RunnerOptions ¶
type RunnerOptions struct {
// Workspace is the child working directory. Empty means the current
// working directory at startup.
Workspace string
// KillGrace overrides DefaultKillGrace when positive.
KillGrace time.Duration
// LookPath overrides exec.LookPath (tests only need this to avoid
// mutating PATH).
LookPath func(string) (string, error)
}
RunnerOptions configure NewRunner.
type Skill ¶
type Skill struct {
Name string `json:"name"`
Description string `json:"description"`
Instructions string `json:"instructions"`
}
Skill is the user-invoked workflow rendered identically for every host.
type Spec ¶
type Spec struct {
SchemaVersion int `json:"schema_version"`
Plugin Plugin `json:"plugin"`
CLI CLI `json:"cli"`
Skill Skill `json:"skill"`
Limits Limits `json:"limits"`
Tools []*Tool `json:"tools"`
}
Spec is the reviewed, declarative description of one CLI. It contains no secrets and is bundled verbatim (in canonical form) with generated plugins.
func ParseSpec ¶
ParseSpec strictly decodes and validates a spec. Unknown fields, duplicate object keys, trailing values and oversize input are rejected.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description"`
Argv []string `json:"argv"`
Inputs []*Input `json:"inputs,omitempty"`
Effects Effects `json:"effects"`
TimeoutSeconds int `json:"timeout_seconds,omitempty"`
}
Tool is one fixed CLI command exposed as an MCP tool.
func (*Tool) BuildArgv ¶
func (t *Tool) BuildArgv(raw json.RawMessage) ([]string, error)
BuildArgv validates raw MCP tool arguments against the tool's declared inputs and returns the argv that follows the executable: the fixed prefix, then inputs in declaration order. Each value is exactly one argv element; no shell parsing or splitting happens anywhere.
func (*Tool) InputSchema ¶
InputSchema returns the JSON Schema object advertised for the tool. additionalProperties is false; the server re-validates every call itself.
type VersionProbe ¶
type VersionProbe struct {
Argv []string `json:"argv"`
RequireOutput string `json:"require_output"`
}
VersionProbe runs Executable with Argv before serving. The probe passes only when the process exits 0 and its combined output contains RequireOutput.