tools

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 36 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 tools holds the MCP tool handlers. Handlers are thin: they validate input, call the browser, perception and action layers, and format compact text for the model.

One file per tool group: navigate.go, snapshot.go, act.go (act + fill), read.go, screenshot.go, tabs.go, wait.go. view.go holds what they share (refs per tab, outline vs diff, the response of acting tools); catalog.go the tool classes. To add a group, write a register function and call it from Register.

Index

Constants

View Source
const (
	GroupCore   = "core"   // navigate, snapshot, act, fill, read, wait, tabs, ask_human, plan
	GroupFlows  = "flows"  // flow_save, flow_list, flow_run
	GroupDev    = "dev"    // screenshot: pixels, for visual checks and debugging layouts
	GroupRecord = "record" // record: start a screencast, export replays (the Cockpit can export too)
	GroupDebug  = "debug"  // network, console, mock, emulate, inspect: for developers checking their app
	// GroupSession: session (save the human's login for --session runs, list saved ones).
	GroupSession = "session"
	// GroupRetouch: retouch (preview, save, discard, list, toggle per-site CSS the human keeps).
	GroupRetouch = "retouch"
	// GroupMap: goto and map_find, over the site map learned from clicks (also turns learning on).
	GroupMap = "map"
)

Tool groups (--tools). Every tool's schema costs context tokens on each request, so clients only get the groups they ask for. core is always on.

View Source
const DefaultGroups = "core,flows,dev"

DefaultGroups keeps the default tools/list under 2 150 tokens (measured in TestDefaultSchemaBudget).

Variables

This section is empty.

Functions

This section is empty.

Types

type ActInput

type ActInput struct {
	Ref    string `json:"ref,omitempty" jsonschema:"element ref (e12), or dialog for a JavaScript dialog; optional for press and scroll"`
	Action string `` /* 160-byte string literal not displayed */
	Value  string `` /* 168-byte string literal not displayed */
	Why    string `json:"why" jsonschema:"why, in a few words (the human sees it)"`
	// contains filtered or unexported fields
}

ActInput is the input of the act tool.

type AskHumanInput

type AskHumanInput struct {
	Question string   `json:"question" jsonschema:"short and specific, in the user's language"`
	Kind     string   `` /* 157-byte string literal not displayed */
	Options  []string `json:"options,omitempty" jsonschema:"2 to 6 short options (kind=choice)"`
}

AskHumanInput is the input of ask_human.

type Browser

type Browser interface {
	Active(ctx context.Context) (*browser.Tab, error)
	Tabs() []*browser.Tab
	SwitchTab(ctx context.Context, id string) (*browser.Tab, error)
	NewTab(ctx context.Context, url string) (*browser.Tab, error)
	CloseTab(ctx context.Context, id string) error
	TabEvents() (opened []*browser.Tab, closed []string)
	WaitNewTab(ctx context.Context, d time.Duration) bool
	Downloads() *browser.Downloads
}

Browser is what the tools need from the browser manager (browser.Manager in production).

type Catalog

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

Catalog records the class each registered tool declared.

func NewCatalog

func NewCatalog() *Catalog

NewCatalog returns an empty catalog.

func Register

func Register(s *mcp.Server, d Deps) *Catalog

Register adds the core tools to s and returns the class each declared (for the pause gate).

func (*Catalog) Class

func (c *Catalog) Class(name string) Class

Class returns the declared class of a tool (0 when undeclared).

func (*Catalog) Declare

func (c *Catalog) Declare(name string, cl Class)

Declare records a tool's class.

func (*Catalog) Gated

func (c *Catalog) Gated(name string) bool

Gated reports whether a tool must pass the human's pause gate: every tool except those declared ReadOnly, so a tool that forgot to declare itself is gated rather than let through.

type Class

type Class int

Class says what a tool may do to the page. Every tool declares its class when it is registered (add requires one): the Cockpit's pause gate uses it, and so does tab focus (only acting tools bring the AI's tab to the front).

const (
	// ReadOnly tools only look (snapshot, read, screenshot, wait, plan): they run while the human
	// has paused or is driving, and never pull the AI's tab in front of the human's.
	ReadOnly Class = iota + 1
	// Acts tools may change the page or the browser (navigate, act, fill, tabs): they wait at the
	// pause gate and bring the AI's tab to the front before input.
	Acts
)

type ConsoleInput

type ConsoleInput struct {
	Action string `json:"action,omitempty" jsonschema:"list (default) or clear"`
	Level  string `json:"level,omitempty" jsonschema:"error, warn, info, log, debug or all"`
	Since  int    `json:"since,omitempty" jsonschema:"after this id"`
	Limit  int    `json:"limit,omitempty" jsonschema:"newest N (30)"`
}

ConsoleInput is the input of the console tool.

type Deps

type Deps struct {
	Browser Browser
	Logger  *slog.Logger
	// Bus receives activity events (optional).
	Bus activity.Bus
	// Hook runs right before input is dispatched (optional; the Cockpit's ghost cursor).
	Hook activity.PreActionHook
	// Settle overrides the settle timing (tests).
	Settle act.SettleOptions
	// Human reports whether the human has taken over the browser (the Cockpit; optional). While
	// they drive, Daisybell never brings its tab to the front.
	Human interface{ Driving() bool }
	// Gate asks the human before risky actions, hands credential fields off and serves ask_human
	// (nil: no approvals; the engine still refuses to type credentials).
	Gate *guard.Gate
	// Hosts restricts navigation (--allowed-hosts; empty allows everything).
	Hosts guard.Hosts
	// Flows stores saved flows; nil leaves out flow_save, flow_list and flow_run.
	Flows *flows.Store
	// Lang is the human-facing language of elicitation forms (--lang: en, pt-BR; "" follows the
	// OS locale).
	Lang string
	// Groups are the tool groups to register (nil: DefaultGroups).
	Groups Groups
	// Tempo makes the Cockpit brisk while a flow replays and returns what restores it (optional).
	Tempo func() (restore func())
	// Typed records what the human types in handoffs, never shown back; the server shares it with
	// the recorder so recordings mask the same values (nil: Register makes one).
	Typed *guard.Typed
	// Cockpit reports the browser launch number and whether the Cockpit extension connected in it
	// (the hub; nil with --no-cockpit). The first result after a launch where it didn't says so.
	Cockpit interface {
		ConnectState() (launch int, connected bool)
	}
	// Mocks are the mock tool's fake responses (debug group; the browser shares the registry).
	// Nil leaves out the mock tool.
	Mocks *mock.Registry
	// Emulator applies the emulate tool's screen and network emulation (browser.Manager; nil
	// leaves out the emulate tool).
	Emulator Emulator
	// Sessions saves and lists the human's logins (session group; nil leaves out the session
	// tool).
	Sessions *SessionStore
	// Retouches stores the retouches the human kept (retouch group; nil: the tool can't save).
	Retouches *retouch.Store
	// Maps stores the site maps learned from clicks (map group; nil leaves out goto and map_find
	// and learns nothing).
	Maps *mapstore.Store
	// Retoucher is the Cockpit, which injects retouches into the pages (the hub; nil with
	// --no-cockpit: the retouch tool says it needs the Cockpit).
	Retoucher Retoucher
}

Deps are the handlers' dependencies.

type EmulateInput

type EmulateInput struct {
	Action  string `json:"action,omitempty" jsonschema:"device, viewport, network or reset (inferred)"`
	Device  string `json:"device,omitempty" jsonschema:"mobile, tablet or desktop"`
	Width   int    `json:"width,omitempty" jsonschema:"CSS px"`
	Height  int    `json:"height,omitempty" jsonschema:"CSS px"`
	Network string `json:"network,omitempty" jsonschema:"slow3g, fast3g, offline or none"`
	Why     string `json:"why,omitempty" jsonschema:"why, in a few words (the human sees it)"`
}

EmulateInput is the input of the emulate tool.

type Emulator

type Emulator interface {
	Emulation() browser.Emulation
	SetEmulation(ctx context.Context, e browser.Emulation) error
	ReapplyScreen(ctx context.Context) error
}

Emulator is what the emulate tool needs from the browser manager.

type FillField

type FillField struct {
	Ref   string `json:"ref" jsonschema:"field ref (e12)"`
	Value string `json:"value" jsonschema:"text, option, or true/false for a checkbox"`
	// contains filtered or unexported fields
}

FillField is one field of the fill tool.

type FillInput

type FillInput struct {
	Fields []FillField `json:"fields" jsonschema:"in order"`
	Submit string      `json:"submit,omitempty" jsonschema:"button ref to click after filling"`
	Why    string      `json:"why" jsonschema:"why, in a few words (the human sees it)"`
}

FillInput is the input of the fill tool.

type FlowListInput

type FlowListInput struct{}

FlowListInput is the input of flow_list.

type FlowRunInput

type FlowRunInput struct {
	Name   string            `json:"name" jsonschema:"flow name"`
	Params map[string]string `json:"params,omitempty" jsonschema:"{name: value} (the shape flow_save takes too), e.g. {\"email\": \"a@b.co\"}"`
	From   int               `json:"from,omitempty" jsonschema:"step to start at (1-based)"`
	Update bool              `json:"update,omitempty" jsonschema:"save healed targets after a successful run"`
}

FlowRunInput is the input of flow_run.

type FlowSaveInput

type FlowSaveInput struct {
	Name        string `json:"name" jsonschema:"short, e.g. buy-coffee"`
	Description string `json:"description,omitempty" jsonschema:"one sentence"`
	From        string `json:"from,omitempty" jsonschema:"last (default: steps since the last save) or all"`
	Steps       string `json:"steps,omitempty" jsonschema:"instead of from: step numbers, e.g. 3-9 or 2,4"`
	// Params is {name: value} (canonical, like flow_run) or a list of names; see parseSaveParams.
	Params  any    `` /* 128-byte string literal not displayed */
	Expect  string `json:"expect,omitempty" jsonschema:"text on the page at the end; flow_run checks it"`
	Preview bool   `json:"preview,omitempty" jsonschema:"list steps and possible params; don't save"`
}

FlowSaveInput is the input of flow_save.

type GotoInput

type GotoInput struct {
	Screen string `json:"screen" jsonschema:"screen name or heading, e.g. Order detail (map_find lists them)"`
}

GotoInput is the input of goto.

type Groups

type Groups map[string]bool

Groups is a set of enabled tool groups.

func ParseGroups

func ParseGroups(s string) (Groups, error)

ParseGroups parses a comma-separated list ("" is the default; "all" enables every group).

func (Groups) Has

func (g Groups) Has(name string) bool

Has reports whether a group is on; a nil set means the default groups.

type Hints

type Hints struct {
	ReadOnly    bool // changes nothing outside the call
	Destructive bool // may lose data or do something irreversible (submit, delete, pay)
	Idempotent  bool // repeating the call with the same input has no further effect
	OpenWorld   bool // may send traffic to arbitrary hosts
}

Hints are the MCP tool annotations: what a tool does to the world, as the client is told. They are independent of Class, which only says whether the tool may run while the human has paused. Each value is the worst case across the tool's actions.

func (Hints) Annotations

func (h Hints) Annotations() *mcp.ToolAnnotations

Annotations returns all four hints set explicitly: directory listings reject tools where one is missing, and the SDK leaves nil pointers out.

type InspectInput

type InspectInput struct {
	Ref   string   `json:"ref" jsonschema:"element ref from the outline (e12)"`
	Props []string `json:"props,omitempty" jsonschema:"more CSS properties"`
}

InspectInput is the input of the inspect tool.

type MapFindInput

type MapFindInput struct {
	Text string `json:"text,omitempty" jsonschema:"words to look for, e.g. export; empty lists the known screens"`
}

MapFindInput is the input of map_find.

type MockInput

type MockInput struct {
	Action  string            `json:"action,omitempty" jsonschema:"add, list (default) or clear"`
	Pattern string            `json:"pattern,omitempty" jsonschema:"URL glob like */api/orders*"`
	Method  string            `json:"method,omitempty" jsonschema:"HTTP method (default any)"`
	Status  int               `json:"status,omitempty" jsonschema:"default 200"`
	Body    string            `json:"body,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Fail    string            `json:"fail,omitempty" jsonschema:"network failure instead: timeout, offline, connection_refused, dns…"`
	DelayMs int               `json:"delayMs,omitempty" jsonschema:"answer late (loading states)"`
	Times   int               `json:"times,omitempty" jsonschema:"expire after N uses"`
	ID      string            `json:"id,omitempty" jsonschema:"clear: m1 (default all)"`
	Why     string            `json:"why,omitempty" jsonschema:"why, in a few words (the human sees it)"`
}

MockInput is the input of the mock tool.

type NavigateInput struct {
	URL     string `json:"url,omitempty" jsonschema:"http(s) URL"`
	History string `json:"history,omitempty" jsonschema:"back, forward or reload (instead of url)"`
	Why     string `json:"why" jsonschema:"why, in a few words (the human sees it)"`
}

NavigateInput is the input of the navigate tool.

type NetworkInput

type NetworkInput struct {
	Action string `json:"action,omitempty" jsonschema:"list (default) or get"`
	Status string `json:"status,omitempty" jsonschema:"failed (≥ 400 or network error), 2xx..5xx, pending or a code"`
	URL    string `json:"url,omitempty" jsonschema:"text in the URL"`
	Type   string `json:"type,omitempty" jsonschema:"fetch, xhr, document, script…"`
	Since  int    `json:"since,omitempty" jsonschema:"after this id"`
	Limit  int    `json:"limit,omitempty" jsonschema:"newest N (20)"`
	ID     int    `json:"id,omitempty" jsonschema:"for get"`
	Body   *bool  `json:"body,omitempty" jsonschema:"get: response body (default true)"`
}

NetworkInput is the input of the network tool.

type ReadInput

type ReadInput struct {
	Ref   string `json:"ref,omitempty" jsonschema:"element (default: main content)"`
	Query string `json:"query,omitempty" jsonschema:"only passages with these words"`
	Page  int    `json:"page,omitempty" jsonschema:"page number (~3000 chars each)"`
}

ReadInput is the input of the read tool.

type RetouchInput

type RetouchInput struct {
	Action string `json:"action" jsonschema:"preview, save, discard, list or toggle"`
	CSS    string `` /* 128-byte string literal not displayed */
	On     *bool  `json:"on,omitempty" jsonschema:"toggle: false shows the original, true the retouch"`
	Why    string `json:"why,omitempty" jsonschema:"why, in a few words (the human sees it)"`
}

RetouchInput is the input of the retouch tool.

type Retoucher

type Retoucher interface {
	PreviewRetouch(host, css string) (had bool)
	SaveRetouch(host, css string)
	ShowOriginal(host string, original bool) bool
	// RetouchOf is a host's state: its preview (if showing) and whether it shows the original.
	RetouchOf(host string) (preview string, previewing, original bool)
}

Retoucher is what the retouch tool needs from the Cockpit hub (internal/cockpit/retouch.go).

type ScreenshotInput

type ScreenshotInput struct {
	Ref   string `json:"ref,omitempty" jsonschema:"only this element"`
	Marks bool   `json:"marks,omitempty" jsonschema:"label elements with their refs"`
	Hires bool   `json:"hires,omitempty" jsonschema:"full-resolution PNG (default: JPEG, fewer tokens)"`
}

ScreenshotInput is the input of the screenshot tool.

type SessionBrowser

type SessionBrowser interface {
	SaveState(ctx context.Context) (storagestate.State, error)
	ProfileName() string
}

SessionBrowser is what the session tool needs from the browser manager.

type SessionInput

type SessionInput struct {
	Action string `json:"action,omitempty" jsonschema:"list (default) or save"`
	Name   string `json:"name,omitempty" jsonschema:"save: lowercase letters, digits, - and _"`
}

SessionInput is the input of the session tool.

type SessionStore

type SessionStore struct {
	Browser SessionBrowser
	Store   storagestate.Store
}

SessionStore is the session tool's dependency: the browser to capture from and where to save.

type SnapshotInput

type SnapshotInput struct {
	Mode  string `json:"mode,omitempty" jsonschema:"diff (default) or full"`
	All   bool   `json:"all,omitempty" jsonschema:"include off-screen elements and folded rows"`
	Scope string `json:"scope,omitempty" jsonschema:"a ref or landmark: main, nav, dialog, form \"Login\""`
	Find  string `json:"find,omitempty" jsonschema:"words: only controls and links naming them, anywhere on the page"`
}

SnapshotInput is the input of the snapshot tool.

type TabsInput

type TabsInput struct {
	Action string `json:"action,omitempty" jsonschema:"list (default), switch, close, new"`
	ID     string `json:"id,omitempty" jsonschema:"tab id (t2); close defaults to the active tab"`
	URL    string `json:"url,omitempty" jsonschema:"for new"`
	Why    string `json:"why,omitempty" jsonschema:"why, in a few words (the human sees it)"`
}

TabsInput is the input of the tabs tool.

type WaitInput

type WaitInput struct {
	Text    string `json:"text,omitempty" jsonschema:"text to wait for"`
	Ref     string `json:"ref,omitempty" jsonschema:"element to wait for"`
	Gone    bool   `json:"gone,omitempty" jsonschema:"wait for it to disappear"`
	Ms      int    `json:"ms,omitempty" jsonschema:"fixed wait in ms (max 10000)"`
	Timeout int    `json:"timeout,omitempty" jsonschema:"ms (default 10000, max 30000)"`
}

WaitInput is the input of the wait tool.

Jump to

Keyboard shortcuts

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