Documentation
¶
Overview ¶
Package mcp implements a minimal Model Context Protocol server over stdio.
The implementation hand-rolls JSON-RPC 2.0 framing (newline-delimited JSON objects on stdin/stdout) and the small subset of MCP methods we need:
- initialize
- tools/list
- tools/call
- notifications/initialized (accepted, ignored)
- ping
All log/diagnostic output goes to stderr so the JSON-RPC stream on stdout stays clean. Concurrent tool calls are serialized through a single mutex around the underlying browser handle.
Index ¶
- Variables
- type Browser
- func (b *Browser) Click(selector string, nth int, timeoutMs int) (map[string]any, error)
- func (b *Browser) Close()
- func (b *Browser) Eval(expression string) (map[string]any, error)
- func (b *Browser) Extract(selector, attribute string, all bool) (map[string]any, error)
- func (b *Browser) GetURL() (map[string]any, error)
- func (b *Browser) Goto(rawURL string, waitForLoad bool) (map[string]any, error)
- func (b *Browser) Screenshot(selector string, fullPage bool) (string, error)
- func (b *Browser) SessionInfo() (map[string]any, error)
- func (b *Browser) Type(selector, text string, clearFirst, submit bool) (map[string]any, error)
- func (b *Browser) WaitFor(selector, expression string, timeoutMs int) (map[string]any, error)
- type BrowserOptions
- type Config
- type Server
Constants ¶
This section is empty.
Variables ¶
var ErrIdleTimeout = errors.New("mcp: idle timeout")
ErrIdleTimeout is reported when the idle watchdog fires.
Functions ¶
This section is empty.
Types ¶
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser wraps a single rod browser/page pair, providing a serialized API for tool calls. It lazy-launches Chrome on first use and can be torn down idempotently from any goroutine (EOF, idle timer, signal).
func NewBrowser ¶
func NewBrowser(opts BrowserOptions) *Browser
NewBrowser returns an unstarted handle. Chrome is not launched until the first tool call that needs it (e.g. browser_goto).
func (*Browser) Close ¶
func (b *Browser) Close()
Close tears down the browser if it was started. Safe to call multiple times.
func (*Browser) Eval ¶
Eval evaluates a JS expression and returns its JSON-encoded result.
The expression is evaluated verbatim. To get a strict-bool, wrap it yourself: `Boolean(document.querySelector('a'))`. This avoids the rod MustEval bool gotcha by never assuming a type.
func (*Browser) Extract ¶
Extract returns matches for selector. all=false returns at most one match. attribute, if set, returns the named attribute instead of text/html.
func (*Browser) Screenshot ¶
Screenshot captures either the full page or a single selector. Returns base64-encoded PNG.
func (*Browser) SessionInfo ¶
SessionInfo reports cookie count, URL, viewport, and UA.
type BrowserOptions ¶
BrowserOptions configure how the lazy browser is launched.
type Config ¶
type Config struct {
Browser *Browser
IdleTimeout time.Duration // 0 = disabled
Logger *log.Logger // defaults to stderr
}
Config configures the Server before Run.