Documentation
¶
Overview ¶
Package mcpgen generates the MCP surface from the machine registry (contract:cli.mcp-tools v2, EPIC P7-SURF D5).
Purpose: one MCP tool per exposed document command of the registry (core, subcommand and installed plugin commands), so the tool list is data, not code. The input schema is the machine request schema, the output schema is the command's committed data schema, annotations come from the side effect, and every call runs through the invoker and its gate.
Inputs: a *cmdregistry.Registry, an Invoker, a schema lookup, the compat mode.
Outputs: server.ServerTool values (Tools), resources (Resources) and server options (ServerOptions).
Constraints: v1.4 mode keeps the 26 legacy tools primary and adds generated tools only under names no legacy tool uses; v1.5 mode registers generated tools only, where the 13 legacy names equal to a generated name become that one tool with a dual-shape input and the other 13 are deprecated aliases (legacy_aliases.yaml). No name is ever registered twice. This package imports invoke, cmdregistry, canon, errs, output and mcp-go, never internal/plugin.
Layer: L2.
Index ¶
- Constants
- func ErrorEnvelope(command string, err error) []byte
- func ErrorResult(command string, err error, deps []output.Deprecation) *mcp.CallToolResult
- func PluginPathOK(path string) bool
- func Resources(o ResourceOptions) ([]server.ServerResource, []server.ServerResourceTemplate)
- func Result(stdout []byte, deps []output.Deprecation) *mcp.CallToolResult
- func ServerOptions() []server.ServerOption
- func Tools(o Options) ([]server.ServerTool, error)
- func ValidToolName(name string) bool
- type FlagMap
- type Invoker
- type Options
- type Param
- type Removed
- type ResourceOptions
- type Row
- type Table
Constants ¶
const ( KindMerged = "merged" KindAlias = "alias" KindRemoved = "removed" )
Row kinds.
const ( URIRegistry = "nself://registry" URIErrors = "nself://errors" URICatalog = "nself://plugins/catalog" URISchemas = "nself://schemas/" )
URIs of the resources this package serves.
const ( ServerName = "nSelf MCP Server" ServerVersion = "2.0.0" )
ServerName and ServerVersion identify the server in the initialize result.
const DeprecatedPrefix = "Deprecated: "
DeprecatedPrefix starts every alias description and every legacy property.
Variables ¶
This section is empty.
Functions ¶
func ErrorEnvelope ¶
ErrorEnvelope renders err as a v1 error envelope for command.
func ErrorResult ¶
func ErrorResult(command string, err error, deps []output.Deprecation) *mcp.CallToolResult
ErrorResult is the tool result for an error raised before or instead of a run.
func PluginPathOK ¶
PluginPathOK reports whether every word of a plugin command path (without the leading "nself ") is a valid plugin command name.
func Resources ¶
func Resources(o ResourceOptions) ([]server.ServerResource, []server.ServerResourceTemplate)
Resources builds the resources and templates. The legacy URIs are included only in v1.5 mode: in v1.4 mode the hand handlers keep serving them.
func Result ¶
func Result(stdout []byte, deps []output.Deprecation) *mcp.CallToolResult
Result maps envelope bytes to a tool result, adding deps to meta.deprecations.
func ServerOptions ¶
func ServerOptions() []server.ServerOption
ServerOptions are the extra options for server.NewMCPServer.
func Tools ¶
func Tools(o Options) ([]server.ServerTool, error)
Tools builds the tools for the mode, sorted by name.
func ValidToolName ¶
ValidToolName reports whether name may be a tool name.
Types ¶
type FlagMap ¶
type FlagMap struct {
Flag string `yaml:"flag"`
Param string `yaml:"param"`
As string `yaml:"as"` // "" | seconds
}
FlagMap maps a legacy param onto a flag of the target command.
type Invoker ¶
Invoker runs one registry command; cmd/commands wires invoke.Invoke with the project directory, the confirmation Guard and the audit surface.
type Options ¶
type Options struct {
Registry *cmdregistry.Registry
Invoke Invoker
// Schema returns a committed schema by its path relative to schemas/.
Schema func(name string) ([]byte, bool)
// V15 selects v1.5 mode: generated tools and aliases only.
V15 bool
// Warn receives one line for each plugin command skipped because its tool
// name is invalid or taken; core conflicts fail Tools instead.
Warn func(string)
}
Options configures Tools.
type Param ¶
type Param struct {
Name string `yaml:"name"`
Type string `yaml:"type"` // string | integer | number | boolean
Description string `yaml:"description"`
Default any `yaml:"default"`
// AllowEmpty keeps an empty string as a value (config set may clear a key);
// otherwise an empty string counts as not given, as the hand tools did.
AllowEmpty bool `yaml:"allow_empty"`
// Positive makes a value of zero or less fall back to Default, as the hand
// tools did (lines <= 0 meant 50).
Positive bool `yaml:"positive"`
}
Param is one legacy property of a tool.
type Removed ¶
type Removed struct {
Code string `yaml:"code"`
Message string `yaml:"message"`
Use []string `yaml:"use"`
}
Removed names the refusal a removed tool returns.
type ResourceOptions ¶
type ResourceOptions struct {
Registry *cmdregistry.Registry
Invoke Invoker
Schema func(name string) ([]byte, bool)
// Catalog returns the cached plugin catalogue document, or an error when
// there is none; it must not touch the network.
Catalog func() ([]byte, error)
// Fallback serves a legacy URI whose command is not exposed on machine
// surfaces yet (for example one with no envelope), so the URI keeps working
// until the command is converted. Keyed by URI; optional.
Fallback map[string]server.ResourceHandlerFunc
V15 bool
}
ResourceOptions configures Resources.
type Row ¶
type Row struct {
Name string `yaml:"name"`
Kind string `yaml:"kind"`
Target string `yaml:"target"`
Plugin string `yaml:"plugin"`
SideEffect string `yaml:"side_effect"`
Summary string `yaml:"summary"`
Params []Param `yaml:"params"`
Required []string `yaml:"required"`
Args []string `yaml:"args"`
Flags []FlagMap `yaml:"flags"`
Unsupported []string `yaml:"unsupported"`
Removed *Removed `yaml:"removed"`
// Shortcut marks a row that is not a legacy name: a short, current alias
// of a generated tool (nself_capabilities). It is registered in both modes,
// is not deprecated and adds no deprecation note.
Shortcut bool `yaml:"shortcut"`
}
Row is one legacy tool name.
func (*Row) CheckNoMix ¶
func (r *Row) CheckNoMix(members map[string]json.RawMessage) error
CheckNoMix refuses a call that carries both machine members and legacy properties.
func (*Row) IsLegacyShape ¶
func (r *Row) IsLegacyShape(members map[string]json.RawMessage) bool
IsLegacyShape reports whether the call carries at least one legacy-only property.
func (*Row) ParamNames ¶
ParamNames lists the legacy property names of the row.