policy

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 11 Imported by: 1 module, 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 policy restricts which tools can be called, and with which arguments.

A policy is an ordered list of rules. The first rule whose tool glob matches and whose optional CEL condition holds decides; when no rule matches, the call is denied.

Index

Constants

This section is empty.

Variables

View Source
var Default []byte

Default is the policy used when no policy file is given: read-only access.

Functions

This section is empty.

Types

type Action

type Action string

Action is the decision of a rule.

const (
	Allow Action = "allow"
	Deny  Action = "deny"
)

Actions.

type Policy

type Policy struct {
	Rules []Rule `yaml:"rules"`
}

Policy is an ordered list of rules, first match wins, default deny.

func Load

func Load(path string) (*Policy, error)

Load reads a policy file, or returns the default policy when path is empty.

func Parse

func Parse(data []byte) (*Policy, error)

Parse parses and compiles a policy.

func (*Policy) Allowed

func (p *Policy) Allowed(tool string, args map[string]any) (bool, string)

Allowed decides a tool call. Conditions failing to evaluate (e.g. a missing argument) fail closed: an allow rule does not match, a deny rule denies.

func (*Policy) Middleware

func (p *Policy) Middleware(next mcp.MethodHandler) mcp.MethodHandler

Middleware enforces the policy on tool calls and hides tools which can never be called.

func (*Policy) Visible

func (p *Policy) Visible(tool string) bool

Visible reports whether some call to the tool could be allowed.

type Rule

type Rule struct {

	// When is a CEL expression over `tool` (string) and `args` (map); empty always matches.
	When   string   `yaml:"when"`
	Action Action   `yaml:"action"`
	Tools  []string `yaml:"tools"`
	// contains filtered or unexported fields
}

Rule matches tool calls by tool name glob and an optional CEL condition.

Jump to

Keyboard shortcuts

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