Documentation
¶
Overview ¶
Package toolset implements declared toolsets: the selector list an agent sends in the X-Muster-Toolset header (or passes to filter_tools) that bounds which of the gateway's tools its meta-tools can see and call.
A toolset is evaluated per request, statelessly, as the third filter on the per-session catalogue — after server-authentication visibility and workflow availability. It never widens access: the catalogue it filters is already the caller's own.
Inline grammar (header, filter_tools argument): preset:<name>, server:<name>, workflow:<name>, tool:<name> with exact names, at most MaxInlineSelectors. toolset:<name> is reserved; label: exists inside presets only. Patterns, excludes, the read-only predicate and composition live in presets, which are muster configuration (toolsetPresets) with read-only, none and full built in.
The package has one scope-source seam, SourceFromRequest: the header is the first source of a request's toolset, an actor claim from a future agent identity the second. Parsing, resolution and the refusal do not change with the source.
Index ¶
- Constants
- func ContextWithSource(ctx context.Context, src Source) context.Context
- func Filter(tools []mcp.Tool, res Resolution) []mcp.Tool
- func HTTPContextFunc(ctx context.Context, r *http.Request) context.Context
- func SetToolOrigin(tool *mcp.Tool, origin ToolOrigin)
- type Entry
- type Info
- type Kind
- type OriginKind
- type Preset
- type PresetsConfig
- type Registry
- func (r *Registry) Check(ts Toolset) error
- func (r *Registry) Get(name string) (Preset, bool)
- func (r *Registry) List() []Info
- func (r *Registry) Names() []string
- func (r *Registry) Resolve(ts Toolset, entries []Entry) (Resolution, error)
- func (r *Registry) ResolveWith(ts Toolset, entries []Entry, labels ServerLabels) (Resolution, error)
- type Resolution
- type Rule
- type Selector
- type ServerLabels
- type Source
- type ToolOrigin
- type Toolset
Constants ¶
const ( PresetReadOnly = "read-only" PresetNone = "none" PresetFull = "full" )
Built-in preset names. They are always defined and cannot be redefined by configuration, so a toolset naming one of them can never hit the unknown-preset error.
const ( KindPreset = "preset" KindServer = "server" KindWorkflow = "workflow" KindTool = "tool" )
Inline selector kinds.
const HeaderName = "X-Muster-Toolset"
HeaderName is the request header that carries an agent's declared toolset.
const MaxInlineSelectors = 32
MaxInlineSelectors caps the number of selectors a toolset may carry inline (in the header or the filter_tools argument). Larger selections are presets.
const MetaKeyLabels = "muster.giantswarm.io/labels"
MetaKeyLabels mirrors api.MetaKeyLabels for tests in this package; the aggregator stashes discovery labels under it.
const MetaKeyOrigin = "muster.giantswarm.io/origin"
MetaKeyOrigin is the mcp.Tool._meta.AdditionalFields key under which the aggregator records where an exposed tool comes from (ToolOrigin). Like the discovery labels key it is an in-process annotation: the meta-tools project it into their own response fields (server, kind) and it is never sent to a client as _meta.
Variables ¶
This section is empty.
Functions ¶
func ContextWithSource ¶
ContextWithSource stores the request's toolset source in ctx.
func Filter ¶
func Filter(tools []mcp.Tool, res Resolution) []mcp.Tool
Filter returns the tools whose names the resolution selected, in input order.
func HTTPContextFunc ¶
HTTPContextFunc has the shape of mcp-go's server.HTTPContextFunc / SSEContextFunc: it stashes the request's toolset source in the context every tool handler receives. Evaluation is per request by construction — nothing is bound to the session.
func SetToolOrigin ¶
func SetToolOrigin(tool *mcp.Tool, origin ToolOrigin)
SetToolOrigin records origin on tool. The tool's _meta is cloned before it is written to, because exposed tools are shallow copies of the downstream tools the registry keeps and share their Meta pointer.
Types ¶
type Entry ¶
type Entry struct {
// Name is the exposed tool name (x_<server>_<tool>, workflow_<name>, core_*).
Name string
// Kind is tool, workflow or core.
Kind Kind
// Server is the owning MCPServer (the family name for a family tool).
// Empty for workflows and core tools.
Server string
// Servers lists the member servers of a family tool.
Servers []string
// ReadOnly is the tool's readOnlyHint annotation (for a workflow the
// derived hint the aggregator computed from its step tools).
ReadOnly bool
}
Entry is what toolset resolution knows about one exposed tool.
func EntriesFromTools ¶
EntriesFromTools projects exposed tools to resolution entries. Kind and server come from the origin the aggregator stashed on the tool; tools without one are classified by name prefix, which is how the aggregator itself tells core and workflow tools apart.
type Info ¶
type Info struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
BuiltIn bool `json:"built_in"`
}
Info describes a preset for discovery (filter_tools include_presets).
type OriginKind ¶
type OriginKind string
OriginKind classifies an exposed tool by what serves it.
const ( // OriginKindTool is a tool served by a registered MCP server // (x_<server>_<tool> or x_<family>_<tool>). OriginKindTool OriginKind = "tool" // OriginKindWorkflow is a workflow execution tool (workflow_<name>). OriginKindWorkflow OriginKind = "workflow" // OriginKindCore is one of muster's own core_* tools. OriginKindCore OriginKind = "core" )
type Preset ¶
type Preset struct {
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Include []Rule `yaml:"include" json:"include"`
Exclude []Rule `yaml:"exclude,omitempty" json:"exclude,omitempty"`
}
Preset is a named, described selection of tools: the union of its include rules minus its exclude rules.
type PresetsConfig ¶
PresetsConfig is the `toolsetPresets:` block of muster's configuration.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds the built-in presets and the configured ones, validated.
func BuiltIns ¶
func BuiltIns() *Registry
BuiltIns returns a registry with only the built-in presets.
func NewRegistry ¶
func NewRegistry(cfg PresetsConfig) (*Registry, error)
NewRegistry validates cfg and returns the registry of built-in plus configured presets. Every validation error names the preset (and rule) so the operator can fix the values; the first error stops startup.
func (*Registry) Check ¶
Check verifies that every preset the toolset names is known. It is what makes an unknown preset an error on every meta-tool call, before any catalogue is consulted.
func (*Registry) Names ¶
Names lists every known preset: built-ins first, then configured presets sorted by name. This is the order error messages and List use.
func (*Registry) Resolve ¶
func (r *Registry) Resolve(ts Toolset, entries []Entry) (Resolution, error)
Resolve evaluates ts against entries without a label lookup: label rules select nothing. See ResolveWith.
func (*Registry) ResolveWith ¶
func (r *Registry) ResolveWith(ts Toolset, entries []Entry, labels ServerLabels) (Resolution, error)
ResolveWith evaluates ts against entries. Inline selectors are unioned; each preset resolves to its includes minus its excludes, recursively for composed presets. Every preset the toolset names must exist (Check) or the unknown-preset error is returned. labels resolves an MCPServer name to its resource labels for label: rules and is consulted lazily — only when such a rule is evaluated — so a request whose presets carry no label rule never pays for the lookup; nil means no labels are known.
type Resolution ¶
type Resolution struct {
// Selected holds the exposed names of the tools the toolset resolves to.
Selected map[string]struct{}
// Unmatched lists the inline selectors (as written) that selected no
// tool in this catalogue. preset:none is empty by definition and is never
// reported.
Unmatched []string
// Servers holds every server that contributes at least one selected tool
// (family members included). Resource and prompt accessors use it to
// decide which servers are inside the toolset.
Servers map[string]struct{}
}
Resolution is the outcome of evaluating a toolset against a catalogue.
func (Resolution) Contains ¶
func (r Resolution) Contains(name string) bool
Contains reports whether the exposed tool name is inside the resolution.
func (Resolution) ContainsServer ¶
func (r Resolution) ContainsServer(server string) bool
ContainsServer reports whether a server contributes to the resolution.
func (Resolution) Names ¶
func (r Resolution) Names() []string
Names returns the selected exposed names, sorted.
type Rule ¶
type Rule struct {
Tool string `yaml:"tool,omitempty" json:"tool,omitempty"`
Pattern string `yaml:"pattern,omitempty" json:"pattern,omitempty"`
Server string `yaml:"server,omitempty" json:"server,omitempty"`
Workflow string `yaml:"workflow,omitempty" json:"workflow,omitempty"`
ReadOnly *bool `yaml:"readOnly,omitempty" json:"readOnly,omitempty"`
Preset string `yaml:"preset,omitempty" json:"preset,omitempty"`
Label string `yaml:"label,omitempty" json:"label,omitempty"`
}
Rule is one selector inside a preset. Exactly one field is set.
- tool: <exact exposed name>
- pattern: <glob on the exposed name> (e.g. core_*, x_mcp-kubernetes_*)
- server: <name> (every tool of that server; a family name selects the family surface)
- workflow: <name> (the workflow's execution tool)
- readOnly: true (every tool annotated read-only, including the derived workflow hint)
- preset: <name> (composition; include only)
- label: <key>=<value> | <key> (every tool of an MCPServer whose resource carries that label; #1168)
type ServerLabels ¶
ServerLabels resolves an MCPServer name to its resource labels (nil when the server is unknown). Label: preset rules consult it lazily, per request, so a server gaining or losing a label changes the resolution on the next request without a restart (#1168).
type Source ¶
Source is where a request's toolset came from, before parsing. Present is false when the request declared no toolset at all (today's unscoped behaviour); a present but empty value is a declared, invalid toolset.
func SourceFromContext ¶
SourceFromContext returns the toolset source stored by ContextWithSource.
func SourceFromRequest ¶
SourceFromRequest is the single seam that decides which request attribute carries the toolset. Today that is the X-Muster-Toolset header; an actor claim from a future agent identity would be read here too, and nothing downstream (parsing, resolution, refusal, scenarios) would change.
type ToolOrigin ¶
type ToolOrigin struct {
// Kind classifies the tool: tool, workflow or core.
Kind OriginKind
// Server is the owning MCPServer for a server tool. For a family-grouped
// tool it is the family name, which is what the exposed name carries.
// Empty for workflows and core tools.
Server string
// Servers lists the member servers providing a family-grouped tool, in
// sorted order. Empty for solo tools, workflows and core tools.
Servers []string
}
ToolOrigin records where an exposed tool comes from. It is stashed on the mcp.Tool by the aggregator when the exposed catalogue is assembled and read by the meta-tools (server / kind in list_tools, filter_tools, describe_tool) and by toolset resolution (server:<name> selectors).
func ToolOriginOf ¶
func ToolOriginOf(tool mcp.Tool) (ToolOrigin, bool)
ToolOriginOf returns the origin recorded on tool, if any.
type Toolset ¶
Toolset is a parsed inline toolset: the selectors as given (trimmed) and their parsed form. Raw is kept for echoing and for naming the toolset in errors exactly as the caller wrote it.
func FromContext ¶
FromContext parses the toolset the request declared. present is false when the request carried none. A present toolset that fails to parse returns the error, which callers surface on every meta-tool call.
func ParseHeader ¶
ParseHeader parses the value of the X-Muster-Toolset header: a comma-separated list of inline selectors with whitespace around each selector trimmed. The caller decides whether the header was present; a present-but-empty value is an error here, never "no toolset".
func ParseInline ¶
ParseInline parses a list of inline selectors (the filter_tools "toolset" argument, or a header already split on commas). Every error names the toolset and the offending selector so the caller can relay it verbatim.