toolset

package
v5.64.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	KindPreset   = "preset"
	KindServer   = "server"
	KindWorkflow = "workflow"
	KindTool     = "tool"
)

Inline selector kinds.

View Source
const HeaderName = "X-Muster-Toolset"

HeaderName is the request header that carries an agent's declared toolset.

View Source
const MaxInlineBytes = 8 << 10

MaxInlineBytes leaves room for authentication in an HTTP/2 header list.

View Source
const MaxInlineSelectors = 128

MaxInlineSelectors caps the number of selectors a toolset may carry inline (in the header or the filter_tools argument). Larger selections are presets.

View Source
const MetaKeyLabels = "muster.giantswarm.io/labels"

MetaKeyLabels mirrors api.MetaKeyLabels for tests in this package; the aggregator stashes discovery labels under it.

View Source
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 CommonDescription added in v5.50.1

func CommonDescription(tools []mcp.Tool) string

CommonDescription returns the description most of the tools carry. A tie goes to the longest description, as a newer member tends to describe a tool more fully, then to the alphabetically first, so the choice is stable.

func ContextWithBound added in v5.49.0

func ContextWithBound(ctx context.Context, selectors []string) context.Context

ContextWithBound stores the toolset bound to the caller's Session, the selectors of its Session binding as stored. nil binds none (the request stays unscoped unless it declares a header).

func ContextWithSource

func ContextWithSource(ctx context.Context, src Source) context.Context

ContextWithSource stores the request's toolset source in ctx.

func FamilyMembers added in v5.44.1

func FamilyMembers(description string) []string

FamilyMembers returns the members a family-grouped tool's description trailer names, in trailer order, or nil when the description carries no trailer.

func Filter

func Filter(tools []mcp.Tool, res Resolution) []mcp.Tool

Filter returns the tools whose names the resolution selected, in input order. A family tool selected on some of its members only is narrowed to them: its instance argument, description and origin name those members alone, so a resolution of the filtered tools cannot select the others.

func FromScope added in v5.58.0

func FromScope(scopes []string) []string

FromScope picks the selectors out of the scope tokens of a token's scope claim (RFC 8693 §4.2): the scope tokens of the form kind:name whose kind is a selector kind, the reserved ones included so ParseInline refuses them. Other scope tokens, such as openid or email, are not selectors and are skipped.

func HTTPContextFunc

func HTTPContextFunc(ctx context.Context, r *http.Request) context.Context

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: the header is never remembered on the MCP session.

func InputSchemaFingerprint added in v5.50.1

func InputSchemaFingerprint(tool mcp.Tool) string

InputSchemaFingerprint returns a canonical JSON encoding of the arguments the tool's input schema accepts, raw or structured: the annotation keywords (description, title, examples, $comment) are dropped at every level, so two versions of a server that only reword a tool's argument descriptions compare equal, and key order does not matter.

func Scoped added in v5.49.0

func Scoped(ctx context.Context) bool

Scoped reports whether the request is bounded by any toolset: one bound to its Session or one it declares.

func SetFamilyMembers added in v5.37.1

func SetFamilyMembers(tool *mcp.Tool, instanceArg string, servers []string)

SetFamilyMembers advertises servers as the members a family-grouped tool runs on: a required string parameter named instanceArg whose enum lists them, and a description trailer naming them. It replaces what a previous call advertised. Properties and Required are deep-copied — including nested object properties and array items — so the per-server cached tool schema is not mutated by callers that walk the result.

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
	// InstanceArg is the argument a call to a family tool selects its member
	// with; empty for every other entry.
	InstanceArg 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

func EntriesFromTools(tools []mcp.Tool) []Entry

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.

func (Entry) Member added in v5.37.1

func (e Entry) Member(server string) Entry

Member is the entry as one member of a family tool serves it: the same name, family and annotations, with that member alone among its servers.

type Info

type Info struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Icon        string `json:"icon,omitempty"`
	BuiltIn     bool   `json:"built_in"`
}

Info describes a preset for discovery (filter_tools include_presets).

type Kind

type Kind string

Kind classifies a catalogue entry the way the meta-tools report it.

const (
	KindEntryTool     Kind = "tool"
	KindEntryWorkflow Kind = "workflow"
	KindEntryCore     Kind = "core"
)

func KindOf

func KindOf(t mcp.Tool) Kind

KindOf classifies an exposed tool: from its origin when the aggregator recorded one, else by the name prefixes the aggregator uses.

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"`
	Icon        string `yaml:"icon,omitempty" json:"icon,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. Icon is an optional data: URI (svg, png, jpeg or webp, at most 65536 characters), validated and stored sanitised like an MCPServer's status.icon.

type PresetsConfig

type PresetsConfig map[string]Preset

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

func (r *Registry) Check(ts Toolset) error

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) Get

func (r *Registry) Get(name string) (Preset, bool)

Get returns a preset by name.

func (*Registry) List

func (r *Registry) List() []Info

List describes every known preset for discovery.

func (*Registry) MaySelect added in v5.37.1

func (r *Registry) MaySelect(ts Toolset, u Unlisted, labels ServerLabels) bool

MaySelect reports whether ts could select the unlisted tool (or, with an empty Name, some tool of the server) once the session signs in and the tool is listed. A readOnly rule may or may not match an annotation that is not known yet: it counts as a possible include and never as an exclude, so MaySelect is true whenever the resolution after sign-in could hold the tool, and false only when no listing can put it in the toolset.

func (*Registry) Names

func (r *Registry) Names() []string

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.

A family tool is evaluated once per member, as that member serves it (Entry.Member): a rule naming one member selects or excludes the tool on that member alone. The tool is selected when the toolset selects it on at least one member, and only those members are inside the toolset.

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:
	// for a family tool, the members the toolset selects it on. Resource and
	// prompt accessors use it to decide which servers are inside the toolset.
	Servers map[string]struct{}
	// contains filtered or unexported fields
}

Resolution is the outcome of evaluating a toolset against a catalogue.

func (Resolution) CallInside added in v5.37.1

func (r Resolution) CallInside(name string, args map[string]any) (member string, inside bool)

CallInside reports whether a call to the exposed tool name with args stays inside the toolset. For a family tool the call runs on the member its instance argument selects, so that member must be one the toolset selects the tool on: server:<member> selects one member, while server:<family>, tool:, pattern: and readOnly rules select every member. member is the member the call selects, "" for a solo tool or a call without the argument (the aggregator refuses that call as missing its argument).

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)

func (Rule) String

func (r Rule) String() string

String renders the rule the way it is written in configuration.

type Selector

type Selector struct {
	Kind string
	Name string
}

Selector is one inline selector, e.g. preset:read-only or tool:x_k8s_get.

func (Selector) String

func (s Selector) String() string

String renders the selector in its inline form.

type ServerLabels

type ServerLabels func(server string) map[string]string

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

type Source struct {
	Present bool
	Raw     string
}

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

func SourceFromContext(ctx context.Context) Source

SourceFromContext returns the toolset source stored by ContextWithSource.

func SourceFromRequest

func SourceFromRequest(r *http.Request) Source

SourceFromRequest reads the toolset the request declares in the X-Muster-Toolset header. A request of a bound Session also carries the toolset of its Session binding (ContextWithBound); the header then only narrows it.

type ToolGroup added in v5.50.1

type ToolGroup struct {
	Servers []string
	Tools   []mcp.Tool
}

ToolGroup is a set of family members and their contribution of one tool, Servers[i] contributing Tools[i].

func SplitFamilyTool added in v5.50.1

func SplitFamilyTool(servers []string, tools []mcp.Tool) (group, rest ToolGroup)

SplitFamilyTool splits the members contributing one family tool by the arguments their input schema accepts (InputSchemaFingerprint). The largest schema group keeps the family name (a tie goes to the group of the alphabetically first server, so the choice is stable across listings); rest holds the members of every other schema group, which fall back to per-server names. Descriptions take no part: members whose tool differs only in its own or its arguments' descriptions are one group.

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
	// InstanceArg is the argument a call to a family-grouped tool selects its
	// member with. Empty for every other tool.
	InstanceArg 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

type Toolset struct {
	Raw       []string
	Selectors []Selector
}

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 BoundFromContext added in v5.49.0

func BoundFromContext(ctx context.Context) (ts Toolset, present bool, err error)

BoundFromContext parses the toolset bound to the caller's Session. present is false when the Session binds none. A bound toolset that fails to parse returns the error, which callers surface on every meta-tool call.

func FromContext

func FromContext(ctx context.Context) (ts Toolset, present bool, err error)

FromContext parses the toolset the request declared in its header, without the bound one (BoundFromContext). 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

func ParseHeader(value string) (Toolset, error)

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

func ParseInline(list []string) (Toolset, error)

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.

func (Toolset) Presets

func (t Toolset) Presets() []string

Presets returns the names of the presets the toolset references, in order.

func (Toolset) String

func (t Toolset) String() string

String renders the toolset as it appears in errors and log lines.

type Unlisted added in v5.37.1

type Unlisted struct {
	// Server is the MCPServer that would serve the tool.
	Server string
	// Family is the server's family name when its tools are grouped under
	// it, as the family's listed tools carry it in Entry.Server.
	Family string
	// Prefix is the exposed prefix every tool of the server carries.
	Prefix string
	// Name is the exposed tool name. Empty asks about any tool of the server.
	Name string
	// Owns reports whether an exposed name is one of the server's tools; it
	// answers tool selectors and rules when Name is empty.
	Owns func(exposedName string) bool
}

Unlisted describes a server tool the session cannot list yet because it has not signed in to the server: what is known of it before sign-in is its name, its server and the server's labels, never its annotations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL