Help us shape the future of Go! Take the 2026 Go Developer Survey

registry

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package registry is the single source of truth for tools (spec §5): metadata, input and output types, JSON Schemas, and the function that runs each tool. The CLI, the MCP server and the generated documentation are all built from it.

Index

Constants

View Source
const ResultStringMax = sanitize.DefaultMax

ResultStringMax is the byte cap on one untrusted string in a result. Pseudonym filters read what a result still shows after the cap (UntrustedRefs), so the cap is applied and read here and nowhere else.

Variables

This section is empty.

Functions

This section is empty.

Types

type Credential

type Credential string

Credential is the credential class a tool uses (spec §7.1).

const (
	CredRead Credential = "read"
	CredNone Credential = "none"
)

type Env

type Env struct {
	API      *api.Client // nil when no credential is configured; APIErr says why
	APIErr   error
	Local    *local.Runner // nil when no tailscale CLI was found; LocalErr says why
	LocalErr error
	Config   *config.Loaded
	// Privacy names masked values and keys audit-log digests (spec §7.6); nil
	// when no key was provided, and PrivacyErr then says why if one was malformed.
	Privacy    *privacy.Key
	PrivacyErr error
	Now        func() time.Time
}

Env is everything a tool may use at run time.

func (*Env) Clock

func (e *Env) Clock() time.Time

Clock returns the current time from Env.Now or time.Now.

func (*Env) Display

func (e *Env) Display(ptr any)

Display rewrites ptr, which a tool owns, into what a result shows: masked unless the owner opted in, then escaped and capped. Mask comes before the cap: an address cut short by it would no longer parse and would keep its first octets. A tool that needs the bytes a caller will see (a sort key, say) runs it on a deep copy.

func (*Env) Masker

func (e *Env) Masker() sanitize.Masker

Masker masks personal data, naming masked values when a privacy key is loaded.

func (*Env) PersonalRefs

func (e *Env) PersonalRefs(s string) []string

PersonalRefs returns the pseudonym a result shows for the personal field holding s (a login or a display name), as the registry masks and caps it.

func (*Env) RequireAPI

func (e *Env) RequireAPI() (*api.Client, error)

RequireAPI returns the API client or the reason it is unavailable.

func (*Env) RequireLocal

func (e *Env) RequireLocal() (*local.Runner, error)

RequireLocal returns the local runner or the reason it is unavailable.

func (*Env) RequirePrivacy

func (e *Env) RequirePrivacy() (*privacy.Key, error)

RequirePrivacy returns the privacy key, or why there is none.

func (*Env) ShowPersonalData

func (e *Env) ShowPersonalData() bool

ShowPersonalData reports whether the owner opted in to unmasked personal data ("personalData": "show"). By default results are masked (spec Appendix C).

func (*Env) UntrustedRefs

func (e *Env) UntrustedRefs(s string) []string

UntrustedRefs returns the pseudonyms a result shows for the untrusted string s, as the registry masks and caps it.

type Meta

type Meta struct {
	Name       string
	Area       string // CLI group, e.g. "devices"
	Verb       string // CLI command, e.g. "list"
	Summary    string
	Tier       Tier
	Stage      Stage
	PlanGate   string // documented plan gating; "" means all plans
	Credential Credential
	Scopes     []string // minimal OAuth scopes, companions included
	// PartialScopes means each scope reads part of the result (settings fields,
	// key types): a missing one narrows the result instead of failing the tool.
	PartialScopes bool
	Notes         string // extra facts for the docs, e.g. an unverified scope
	// Operations are the API operations the tool calls, as "METHOD /path" with the
	// path spelled as Tailscale's OpenAPI document spells it (spec §20).
	Operations []string
	// MaxResultChars raises the result size an MCP host keeps for this tool
	// (Claude Code's anthropic/maxResultSizeChars); 0 leaves the default, which
	// list tools raise to 200,000 characters.
	MaxResultChars int
}

Meta is a tool's declared metadata.

type Registry

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

Registry holds tools by name.

func New

func New() *Registry

New returns an empty registry.

func (*Registry) Add

func (r *Registry) Add(t Tool) error

Add validates a tool's metadata and registers it.

func (*Registry) All

func (r *Registry) All() []Tool

All returns every tool sorted by area then verb.

func (*Registry) ByCommand

func (r *Registry) ByCommand(area, verb string) (Tool, bool)

ByCommand returns the tool for a CLI area and verb.

func (*Registry) Get

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

Get returns a tool by name.

func (*Registry) MustAdd

func (r *Registry) MustAdd(tools ...Tool)

MustAdd is Add that panics, for static registration at startup.

func (*Registry) Profile

func (r *Registry) Profile(profile string, enableAlpha bool) ([]Tool, error)

Profile returns the tools an MCP profile advertises (spec §5.4). Profiles are a context-budget control on stdio, not a security boundary.

func (*Registry) ReadScopes

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

ReadScopes returns the union of scopes of all read tools, sorted.

type Stage

type Stage string

Stage is the documented release stage of the underlying Tailscale feature.

const (
	StageGA    Stage = "ga"
	StageBeta  Stage = "beta"
	StageAlpha Stage = "alpha"
)

type Tier

type Tier string

Tier is a tool's base tier (spec §5).

const (
	TierRead           Tier = "read"
	TierLocal          Tier = "local"
	TierOffline        Tier = "offline"
	TierPrivilegedRead Tier = "privileged_read"
	TierReversible     Tier = "reversible"
	TierEscalation     Tier = "escalation"
	TierIrreversible   Tier = "irreversible"
)

type Tool

type Tool struct {
	Meta            Meta
	InputType       reflect.Type
	OutputType      reflect.Type
	InputSchema     *jsonschema.Schema
	OutputSchema    *jsonschema.Schema
	UntrustedFields []string // JSON paths of untrusted output fields
	PersonalFields  []string // JSON paths of identifiers masked whole unless personalData is "show"
	PlainFields     []string // JSON paths of untrusted fields kept unmasked (configuration such as routes)
	EmailFields     []string // JSON paths of untrusted fields whose email addresses alone are masked
	// contains filtered or unexported fields
}

Tool is a registered tool.

func Define

func Define[In, Out any](m Meta, run func(ctx context.Context, env *Env, in In) (Out, error)) Tool

Define builds a Tool from its metadata and a typed run function. Personal data is masked (unless the owner opted in) and untrusted output fields are sanitized in place after every run, so run must return values it owns, never shared or cached ones.

func (Tool) Call

func (t Tool) Call(ctx context.Context, env *Env, raw json.RawMessage) (out any, err error)

Call validates raw JSON arguments against the input schema, decodes them strictly, and runs the tool. Errors leave it the way results do, sanitized and then scanned by the secret tripwire, and a panic in the tool becomes internal_error without its value.

Jump to

Keyboard shortcuts

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