toolpolicy

package
v1.0.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package toolpolicy enforces the stack.yaml `policy:` block: ordered per-tool call rules, an optional destructive-hint default, and a permissive or blocking fallback. It implements the gateway's CallGate seam. Evaluation is in-memory and does no I/O.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CatalogEntry

type CatalogEntry struct {
	Name        string
	Annotations *mcp.ToolAnnotations
	Exposed     bool
}

CatalogEntry is one pre-whitelist catalog tool plus whether the post-whitelist dispatch index currently exposes it.

type Policy

type Policy struct {
	// contains filtered or unexported fields
}

Policy is the compiled, enforcement-ready form of a config.PolicyConfig. A nil *Policy means the key was omitted; every method is nil-safe and permissive. A non-nil policy, including an empty block, installs a gate.

func NewPolicy

func NewPolicy(cfg *config.PolicyConfig, logger *slog.Logger) *Policy

NewPolicy compiles the policy block. A nil config returns a nil policy (no block, byte-identical legacy dispatch). Any non-nil config, including an empty block, returns a non-nil policy.

func (*Policy) Evaluate

func (p *Policy) Evaluate(prefixedName string, ann *mcp.ToolAnnotations) Verdict

Evaluate applies last-match-wins rules, then block_destructive, then default. A nil policy allows. A tool with no annotations is unaffected by block_destructive. ann is the downstream server's own hints, not a group override.

func (*Policy) Gates

func (p *Policy) Gates() []mcp.CallGate

Gates returns the policy's pre-call gate. A nil policy returns nil. A non-nil policy always returns one gate, including an empty block.

func (*Policy) Status

func (p *Policy) Status() StatusReport

Status snapshots the authored block with no per-tool rows. A nil policy reports configured false.

func (*Policy) StatusWithCatalog

func (p *Policy) StatusWithCatalog(entries []CatalogEntry) StatusReport

StatusWithCatalog snapshots the block and evaluates each catalog entry with Evaluate, using that entry's own annotations. A nil policy ignores the catalog and returns the unconfigured payload: a hidden tool's row is only meaningful once a block is declared.

type RuleStatus

type RuleStatus struct {
	Index  int    `json:"index"`
	Match  string `json:"match"`
	Action string `json:"action"`
}

RuleStatus is one authored rule, index 0-based as written.

type StatusReport

type StatusReport struct {
	Configured       bool                  `json:"configured"`
	Default          string                `json:"default,omitempty"`
	BlockDestructive *bool                 `json:"block_destructive,omitempty"`
	Rules            []RuleStatus          `json:"rules"`
	Tools            map[string]ToolStatus `json:"tools"`
}

StatusReport is the GET /api/policy payload. Rules and Tools are never nil. Default and BlockDestructive are omitted when the block is absent so the unconfigured body is {"configured":false,"rules":[],"tools":{}}.

func EmptyStatus

func EmptyStatus() StatusReport

EmptyStatus is the unconfigured payload. Never null collections.

type ToolStatus

type ToolStatus struct {
	Action    string `json:"action"`
	Source    string `json:"source"`
	RuleIndex *int   `json:"rule_index,omitempty"`
	Rule      string `json:"rule,omitempty"`
	Exposed   bool   `json:"exposed"`
}

ToolStatus is the verdict dispatch would apply if the tool were exposed. A hidden tool is still evaluated; dispatch itself rejects hidden names before any gate. RuleIndex is omitted unless a rule matched, so index 0 is not dropped.

type Verdict

type Verdict struct {
	Action    string
	Source    string
	RuleIndex int
	Rule      string
	Matched   bool
}

Verdict is one tool's policy decision. Action is the authored action (require_approval is not rewritten to block). Source is rule, block_destructive, or default. RuleIndex is set only for a rule match.

Jump to

Keyboard shortcuts

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