mcp

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Overview

~/_git/wiz/mcp/computer_map.go

~/_git/wiz/mcp/computer_safety.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArtifactURI added in v0.11.0

func ArtifactURI(id int64) string

ArtifactURI formats an artifact ID as an artifact:// URI.

func BlockedComputerReason added in v0.5.0

func BlockedComputerReason(in ComputerUseInput) string

BlockedComputerReason returns a non-empty reason if the action is hard-blocked (un-overridable, regardless of approval). Empty means allowed.

func IsDestructiveComputerAction added in v0.5.0

func IsDestructiveComputerAction(action string) bool

IsDestructiveComputerAction reports whether an action mutates user-visible state and must go through approval. Exported for consumers' approval policies.

func LimitOutput added in v0.11.0

func LimitOutput(s, toolName string, limits OutputLimits, store *ArtifactStore) string

LimitOutput applies the full output-limiting pipeline to s:

  1. Strip ANSI escape codes
  2. Collapse runs of repeated lines
  3. Truncate lines longer than MaxLineLength
  4. If the result fits the budget, return it as-is
  5. If it exceeds the budget, keep head+tail and prepend a warning
  6. If it exceeds the spill threshold, save the full output as an artifact and append a recovery notice

toolName is the name of the calling tool ("bash", "read", etc.), used only for artifact metadata. store may be nil, in which case no artifact is saved (the output is still truncated).

func ParseArtifactURI added in v0.11.0

func ParseArtifactURI(s string) (id int64, ok bool)

ParseArtifactURI extracts the numeric ID from an "artifact://N" URI. Returns ok=false if the string is not an artifact URI.

func StartBrowserMCPServer added in v0.5.0

func StartBrowserMCPServer(ctx context.Context, transport mcp.Transport, cfg types.Config) error

StartBrowserMCPServer starts a headed-Chrome-backed MCP server exposing the browser_* tools (navigate, snapshot, click, type, press, scroll, vision). Blocks until ctx is done, at which point the browser is torn down.

func StartComputerMCPServer added in v0.5.0

func StartComputerMCPServer(ctx context.Context, transport mcp.Transport, cfg types.Config) error

StartComputerMCPServer spawns cua-driver as a stdio MCP child and serves the in-process computer_use tool that proxies to it. Blocks until ctx is done.

func StartFileSystemMCPServer

func StartFileSystemMCPServer(ctx context.Context, transport mcp.Transport, root string, limits *OutputLimitsPolicy, artifacts *ArtifactStore) error

StartFileSystemMCPServer starts the filesystem MCP server. When root is non-empty, relative paths are rooted at it; an empty root preserves the legacy process-cwd behavior.

func StartSkillsMCPServer

func StartSkillsMCPServer(ctx context.Context, transport mcp.Transport, skills []types.Skill) error

StartSkillsMCPServer runs an in-memory MCP server exposing a load_skill tool that returns a skill's full instructions by name.

func StartTransports

func StartTransports(ctx context.Context, cfg types.Config, shellJobs *ShellJobs, limits *OutputLimitsPolicy, artifacts *ArtifactStore) ([]mcp.Transport, error)

The in-memory servers below run until ctx ends. A server whose ctx is cancelled at exit returns context.Canceled, which is shutdown, not a failure, so it is not reported. Whether a server sees that or its client closing first depends on goroutine timing.

func StartWebMCPServer

func StartWebMCPServer(ctx context.Context, transport mcp.Transport, cfg types.Config) error

StartWebMCPServer starts the web MCP server exposing web_fetch and web_search. web_fetch reuses the session's main model and request options (model, API key, base URL, metadata, and reasoning effort) for its extraction pass.

func TransportForServer added in v0.3.0

func TransportForServer(srv types.MCPServer) mcp.Transport

TransportForServer returns the client transport for a configured MCP server. A server with URL set uses a remote HTTP/SSE transport (Streamable HTTP by default, SSE when Transport == "sse"); otherwise it launches Command over stdio, inheriting the process environment plus the server's Env.

Types

type Artifact added in v0.11.0

type Artifact struct {
	ID        int64
	Tool      string // "bash", "read", "grep", etc.
	CreatedAt time.Time
	Content   string
}

Artifact is one piece of spilled tool output.

type ArtifactStore added in v0.11.0

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

ArtifactStore is a session-scoped store for tool output that was too large to return inline. When a tool result exceeds the spill threshold, the full output is saved here and the model gets a head+tail slice plus an artifact://N reference it can page through with the read tool.

Artifacts are in-memory and do not survive a session restart. They are addressed by a monotonically increasing ID: artifact://1, artifact://2, etc. The ID is assigned at save time and never reused.

func NewArtifactStore added in v0.11.0

func NewArtifactStore() *ArtifactStore

NewArtifactStore creates an empty artifact store.

func (*ArtifactStore) Count added in v0.11.0

func (s *ArtifactStore) Count() int

Count returns the number of stored artifacts.

func (*ArtifactStore) Get added in v0.11.0

func (s *ArtifactStore) Get(id int64) *Artifact

Get retrieves an artifact by ID. Returns nil if not found.

func (*ArtifactStore) Save added in v0.11.0

func (s *ArtifactStore) Save(tool, content string) string

Save stores content as a new artifact and returns its artifact:// URI.

type BrowserInput added in v0.5.0

type BrowserInput struct {
	URL       string `json:"url,omitempty" jsonschema:"the URL to open (browser_navigate)"`
	Ref       string `json:"ref,omitempty" jsonschema:"element ref from the snapshot, e.g. @e5 (browser_click/browser_type)"`
	Text      string `json:"text,omitempty" jsonschema:"text to type (browser_type)"`
	Key       string `json:"key,omitempty" jsonschema:"key to press, e.g. Enter, Tab, Escape (browser_press)"`
	Direction string `json:"direction,omitempty" jsonschema:"up or down (browser_scroll)"`
	Full      bool   `json:"full,omitempty" jsonschema:"return the full page snapshot, not just interactive elements (browser_snapshot)"`
	Question  string `json:"question,omitempty" jsonschema:"what to look for in the screenshot (browser_vision)"`
}

BrowserInput is the shared input shape for every browser_* tool. Only the fields relevant to a given tool are populated by the model for that call.

type BrowserOutput added in v0.5.0

type BrowserOutput struct {
	Snapshot         string `json:"snapshot,omitempty"`
	ElementCount     int    `json:"element_count,omitempty"`
	SourceID         string `json:"source_id,omitempty"`
	RedactedFindings int    `json:"redacted_findings,omitempty"`
}

BrowserOutput is the structured result returned to the model for every browser_* tool that produces (or refreshes) a snapshot.

type ComputerElement added in v0.5.0

type ComputerElement struct {
	Index int    `json:"element_index"`
	Role  string `json:"role"`
	Label string `json:"label"`
}

ComputerElement is one AX element surfaced from a capture.

type ComputerUseInput added in v0.5.0

type ComputerUseInput struct {
	Action         string   `` /* 165-byte string literal not displayed */
	Mode           string   `json:"mode,omitempty" jsonschema:"capture mode: som (default),vision,ax"`
	App            string   `` /* 192-byte string literal not displayed */
	MaxElements    int      `json:"max_elements,omitempty" jsonschema:"cap on returned AX elements (default 100, max 1000)"`
	Element        int      `json:"element,omitempty" jsonschema:"1-based SOM index from the last capture (preferred over coordinates)"`
	Coordinate     []int    `json:"coordinate,omitempty" jsonschema:"pixel [x,y]; use only when no element index is available"`
	Button         string   `json:"button,omitempty" jsonschema:"left,right,middle"`
	Modifiers      []string `json:"modifiers,omitempty" jsonschema:"modifier keys held during the action"`
	FromElement    int      `json:"from_element,omitempty"`
	ToElement      int      `json:"to_element,omitempty"`
	FromCoordinate []int    `json:"from_coordinate,omitempty"`
	ToCoordinate   []int    `json:"to_coordinate,omitempty"`
	Direction      string   `json:"direction,omitempty" jsonschema:"up,down,left,right"`
	Amount         int      `json:"amount,omitempty" jsonschema:"scroll wheel ticks (default 3)"`
	Value          string   `json:"value,omitempty" jsonschema:"value for set_value"`
	Text           string   `json:"text,omitempty" jsonschema:"text to type"`
	Keys           string   `json:"keys,omitempty" jsonschema:"key combo, e.g. cmd+s, ctrl+alt+t, return"`
	Seconds        float64  `json:"seconds,omitempty" jsonschema:"seconds to wait (max 30)"`
	RaiseWindow    bool     `json:"raise_window,omitempty"`
	CaptureAfter   bool     `json:"capture_after,omitempty" jsonschema:"take a follow-up capture after the action"`
}

ComputerUseInput is the single wrapper tool's argument set.

type ComputerUseOutput added in v0.5.0

type ComputerUseOutput struct {
	Summary   string            `json:"summary"`
	Elements  []ComputerElement `json:"elements,omitempty"`
	ImageMIME string            `json:"image_mime_type,omitempty"`
}

ComputerUseOutput is the structured result returned to the model.

type OutputLimits added in v0.11.0

type OutputLimits struct {
	Disabled               bool
	Budget                 int
	HeadBudget             int
	MaxLineLength          int
	ArtifactSpillThreshold int
}

OutputLimits is the resolved tool-output limits policy. Zero values are replaced with defaults by ResolveOutputLimits.

func ResolveOutputLimits added in v0.11.0

func ResolveOutputLimits(cfg types.ToolOutputLimitsConfig) OutputLimits

ResolveOutputLimits fills zero fields with defaults, matching the whole-block defaulting in config/config.go.

type OutputLimitsPolicy added in v0.11.0

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

OutputLimitsPolicy is a thread-safe wrapper around the tool-output limits config. The MCP tool handlers read it on every call; the session updates it when /settings changes a tool_output_limits.* key at runtime.

It is shared between the bash/filesystem MCP servers (started in StartTransports, running as goroutines) and the Session (which owns the setter). Both sides go through this struct rather than reading the Config directly, so a /settings update lands without a restart.

func NewOutputLimitsPolicy added in v0.11.0

func NewOutputLimitsPolicy(cfg types.ToolOutputLimitsConfig) *OutputLimitsPolicy

NewOutputLimitsPolicy creates a policy seeded from cfg.

func (*OutputLimitsPolicy) Get added in v0.11.0

Get returns a snapshot of the current limits.

func (*OutputLimitsPolicy) Resolved added in v0.11.0

func (p *OutputLimitsPolicy) Resolved() OutputLimits

Resolved returns the current limits with defaults filled in. This is what tool handlers should call on each invocation.

func (*OutputLimitsPolicy) Set added in v0.11.0

Set replaces the limits. Called from Session.SetToolOutputLimits.

type ShellJobInfo

type ShellJobInfo struct {
	ID      string
	Script  string
	Status  string // running | completed | failed
	Running bool
	// Backgrounded is true for jobs that run detached from a turn — started via
	// bash_background, or a foreground command the user backgrounded with Ctrl+B.
	// A normal foreground command (consumed inline by the turn) is false.
	Backgrounded bool
}

ShellJobInfo is a UI-facing snapshot of a shell job.

type ShellJobs

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

ShellJobs is the shared registry of shell jobs. It is created in main.go and shared between the shell MCP server (which starts/manages jobs) and the UI (which lists jobs for the footer and backgrounds the foreground one on Ctrl+B).

func NewShellJobs

func NewShellJobs() *ShellJobs

NewShellJobs creates an empty shared shell-job registry.

func NewShellJobsInDir added in v0.4.1

func NewShellJobsInDir(dir string) *ShellJobs

NewShellJobsInDir creates a shell-job registry whose commands run in dir (cmd.Dir). An empty dir preserves the legacy process-cwd behavior.

func (*ShellJobs) DetachForeground

func (s *ShellJobs) DetachForeground() (string, bool)

DetachForeground backgrounds the running foreground shell command (Ctrl+B).

func (*ShellJobs) HasForeground

func (s *ShellJobs) HasForeground() bool

HasForeground reports whether a detachable foreground shell command is currently running.

func (*ShellJobs) HasRunning

func (s *ShellJobs) HasRunning() bool

HasRunning reports whether any shell job (background or foreground) is still running. Used as a WithPendingWork predicate so the live agent run parks while a backgrounded shell command is still in flight.

func (*ShellJobs) Kill

func (s *ShellJobs) Kill(id string) bool

Kill stops a shell job by id.

func (*ShellJobs) List

func (s *ShellJobs) List() []ShellJobInfo

List returns all shell jobs in start order, oldest first.

func (*ShellJobs) Output

func (s *ShellJobs) Output(id string) (stdout, stderr string, ok bool)

Output returns the captured stdout/stderr of a shell job by id.

func (*ShellJobs) SetOnJobDone

func (s *ShellJobs) SetOnJobDone(fn func(ShellJobInfo))

SetOnJobDone registers a callback invoked once for each shell job that finishes (from the job's wait goroutine). The session uses it to inject a completion notice into the live run. fn receives a UI-facing snapshot; it is called for every job — the caller decides whether to act (e.g. only on backgrounded jobs). Safe to call once at setup.

func (*ShellJobs) Shutdown added in v0.9.2

func (s *ShellJobs) Shutdown(timeout time.Duration) int

Shutdown cancels every running shell job and waits up to timeout for them to exit. It returns how many were still running when it gave up.

nib calls it on quit, before the process exits. Cancelling the app context alone was not enough: the jobs were signalled, but nib exited before they could stop or be sent the follow-up SIGKILL, and some of them kept running.

type StickyContext added in v0.5.0

type StickyContext struct {
	PID       int
	WindowID  int
	SessionID string
	Desktop   bool // true after a desktop-scope capture: act by screen-absolute pixel, no window
	// Explicit marks a target the model deliberately chose — open_app, focus_app,
	// or capture(app=...) — as opposed to whatever happened to be frontmost. A
	// plain capture reuses an explicit target instead of re-detecting frontmost,
	// so "open_app then capture" sees the app just opened, not e.g. a mounted
	// DMG's Finder window that stole the front.
	Explicit bool
}

StickyContext is the pid/window/session carried forward from the last capture.

Jump to

Keyboard shortcuts

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