Documentation
¶
Overview ¶
Package mcpserver exposes CLI commands as MCP tools over stdio.
A tool runs one CLI command with --output json and --non-interactive, and returns its JSON result. The input schema of a tool comes from the flags of its command, so the tools and the commands cannot drift apart. Command progress (stderr) becomes MCP progress notifications. Stdout is the MCP channel, so nothing else may write to it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Args ¶
func Args(t Tool, raw json.RawMessage) ([]string, error)
Args builds the CLI arguments of one call: the command, its flags, then "--" and the positional arguments, so that a value can never become a flag.
func InputSchema ¶
InputSchema returns the JSON schema of the tool parameters.
Types ¶
type Flag ¶
type Flag struct {
Name string
Type string // pflag type: bool, string, int, int64, duration, stringSlice, intSlice
Default string
Usage string
Values []string // allowed values, when fixed
}
Flag is a command flag that the tool accepts as a parameter.
type Options ¶
type Options struct {
Name string
Version string
Instructions string
Tools []Tool
Run Runner
// Prefix comes before the command of every call, for example --dir <folder>.
Prefix []string
// AllowDestructive registers the destructive tools. Without it they do not exist.
AllowDestructive bool
// Log receives the stderr of every command.
Log io.Writer
// MaxResultBytes cuts longer results, so that one result cannot fill the
// context of a small model. 0 means no limit.
MaxResultBytes int
}
Options configure the server.
type Runner ¶
Runner runs the CLI with args. Progress receives stderr. It returns the exit code and stdout.
type Tool ¶
type Tool struct {
Name string
Title string
Description string
Command []string // for example ["documents", "get"]
Kind Kind
Flags []Flag
Args []Arg
// Defaults are flag values used when the caller does not give the parameter.
Defaults map[string]string
// Extra arguments always passed, for example --yes.
Extra []string
}
Tool is one CLI command exposed as an MCP tool.