Documentation
¶
Overview ¶
Package capability defines the per-MCP capability state model used by the chatbot to control tool access. Each capability maps 1:1 to an MCP server.
Design ref: docs/chatbot-design-spec.md section 7.1, 7.2, 7.4
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RenderGroupIndex ¶ added in v0.1.16
RenderGroupIndex produces the compact markdown table injected into the system prompt for in-band tool routing. It mirrors the shape of the interest index. Returns "" when there are no groups, so the caller can omit the section entirely (and emit no dangling header).
Types ¶
type Capability ¶
type Capability struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"`
Description string `json:"description" yaml:"description"`
State State `json:"state" yaml:"state"`
Available bool `json:"available" yaml:"-"`
ToolsCount int `json:"tools_count" yaml:"-"`
ReadOnlyToolsCount int `json:"read_only_tools_count" yaml:"-"`
ServerName string `json:"-" yaml:"server_name"`
}
Capability describes a single MCP capability and its current state.
func DefaultCapabilities ¶
func DefaultCapabilities() []Capability
DefaultCapabilities returns an empty capability set. Products provide their capabilities via config.yaml mcp_servers definitions.
func Merge ¶
func Merge(caps []Capability, saved CapabilityMap) []Capability
Merge applies saved states onto a list of capabilities, preserving defaults for any capabilities not present in the map.
type CapabilityMap ¶
CapabilityMap is a convenience alias for capability states keyed by ID.
func ToMap ¶
func ToMap(caps []Capability) CapabilityMap
ToMap converts a capability slice into a CapabilityMap of just the states.
func (CapabilityMap) MarshalJSON ¶
func (cm CapabilityMap) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling.
func (*CapabilityMap) UnmarshalJSON ¶
func (cm *CapabilityMap) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling with validation.
type Group ¶ added in v0.1.16
type Group struct {
// ID is the capability ID; this is the value the model passes to
// load_tools.
ID string
// Label is a human-readable name (capability name, falling back to ID).
Label string
// Description tells the model what the group covers. It is the operator-
// configured capability description when set, otherwise auto-derived from
// the group's tool names.
Description string
// ToolNames are the tools that become available when this group is loaded.
ToolNames []string
// Tools carries the per-tool metadata (name + one-line description) used
// to render an expandable sub-index for oversized groups (S8). Sorted by
// name; mirrors ToolNames.
Tools []ToolInfo
// Expandable is true when this group exceeds the configured size threshold
// (S8): the routing menu lists its individual tools so the model can load
// just the ones it needs via load_tools(tools:[…]) instead of pulling in
// the whole server. Small groups load wholesale and leave this false.
Expandable bool
}
Group is one entry in the tool-routing group menu (S7a). Each group maps 1:1 to a capability / MCP server: the menu is derived directly from the capability set, never from a hardcoded product→tools map, so it stays host-agnostic.
func BuildGroups ¶ added in v0.1.16
func BuildGroups(caps []Capability, enabled map[string]bool, toolsByCap map[string][]ToolInfo) []Group
BuildGroups derives the ordered tool-routing group menu from the capability set. It is a pure function (no router/IO dependency) so it can be unit tested table-style.
Only capabilities present and true in enabled are included; this mirrors interest.Catalog.BuildIndex(enabled), so the menu self-updates as MCP servers connect/disconnect or capabilities are toggled off — no restart. When enabled is nil, all supplied capabilities are included.
toolsByCap maps capability ID -> the tools that belong to it (already resolved from tool→server→capability upstream). It is used both to populate Group.ToolNames and to auto-derive a Description when the capability has no configured one.
Groups are ordered by capability ID for determinism.
BuildGroups keeps every group whole (group-level S7a routing). Use BuildGroupsExpanding to enable tool-level expansion of oversized groups (S8).
func BuildGroupsExpanding ¶ added in v0.1.19
func BuildGroupsExpanding(caps []Capability, enabled map[string]bool, toolsByCap map[string][]ToolInfo, expandThreshold int) []Group
BuildGroupsExpanding is BuildGroups plus S8 intra-group expansion: any group whose tool count exceeds expandThreshold (when > 0) is marked Expandable and carries its per-tool metadata so the routing menu can list individual tools. expandThreshold <= 0 disables expansion, reproducing BuildGroups exactly.
type State ¶
type State string
State represents the autonomy level for a capability.
const ( // StateOff disables the capability entirely. StateOff State = "off" // StateAsk requires user approval for every tool invocation. StateAsk State = "ask" // StateAskOnWrite permits read-only tools to execute autonomously and // requires user approval for write tools. A tool is considered // read-only when its MCP ToolAnnotations.ReadOnlyHint is true or it // appears in the server's read_only_tools allowlist; tools without // either marker are treated as writes. StateAskOnWrite State = "ask-on-write" // StateAllow permits autonomous tool execution. StateAllow State = "allow" )