browser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package browser implements a Resolver that asks the user via an ephemeral local HTTP server and a browser-rendered form.

Lifecycle of a single Ask call:

  1. bind an OS-assigned localhost port (loopback only)
  2. publish a one-shot HTTP server with two handlers: - GET / renders the form for the current request - POST /submit accepts the user's selections and signals done
  3. attempt to open the URL in the user's browser via OpenURL
  4. block until the form is submitted, the user cancels, or ctx is done
  5. tear down the HTTP server and return the answers

Only one Ask runs at a time per Resolver instance (guarded by a mutex) so a misbehaving model issuing parallel tool calls won't race for the same port. Tools may call Ask serially as much as they like.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

type Resolver struct {
	// Host is the bind address; defaults to 127.0.0.1.
	Host string
	// OpenURL is the function used to launch the user's browser. Defaults
	// to platform-appropriate `open` / `xdg-open` / `rundll32`. Tests can
	// inject a stub.
	OpenURL func(url string) error
	// Logger receives one-line status messages (server start, browser
	// launch, errors). When nil, messages go to io.Discard so an MCP
	// server using stdio doesn't get polluted output.
	Logger io.Writer
	// contains filtered or unexported fields
}

Resolver implements server.Resolver by hosting an ephemeral form.

func New

func New() *Resolver

New returns a Resolver with defaults appropriate for stdio MCP usage: loopback binding, platform-appropriate browser launcher, no logging.

func (*Resolver) Ask

Ask implements server.Resolver.

Jump to

Keyboard shortcuts

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