app

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 29 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 app wires the ports to the adapters: the use cases behind each CLI command. Nothing here knows HTTP flags or argv — cmd/toolhost owns that edge.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Attach added in v0.0.2

func Attach(cfgPath, client string, stdio, printOnly bool, w io.Writer) error

Attach registers the gateway with an MCP client — the last mile of install. Instead of hand-editing each client's JSON or memorizing its CLI syntax, one command writes (or prints) the entry. File-backed clients get an mcpServers merge; CLI-backed clients get their `mcp add` invocation executed. --stdio attaches the spawn form (serve --stdio) instead of the HTTP endpoint + bearer.

func Auth

func Auth(ctx context.Context, path, name string, w io.Writer) error

Auth runs the upstream grant for one backend — the OAuth browser dance or the client_credentials exchange — driven explicitly so it works the same for streamable and SSE upstreams. The minted token persists to the token store; serve reuses (and refreshes) it without ever prompting.

func ConnectBackends

func ConnectBackends(ctx context.Context, f *config.File, tokens *oauth.Store, sink core.AuditSink, log *slog.Logger) ([]core.Upstream, map[string]error)

ConnectBackends dials every configured backend. Failures are per-backend: the gateway keeps serving the rest, and the failure is evidenced — a dead backend's tools are absent, hence uncallable, which IS the closed posture.

func Discover

func Discover(ctx context.Context, path string, w io.Writer) error

Discover connects every backend and prints its tool inventory, marking which qualified names are approved. Read-only: it writes nothing, audits nothing.

func Doctor added in v0.0.2

func Doctor(ctx context.Context, cfgPath string, w io.Writer) error

Doctor checks an install end to end without needing the gateway to be running — the setup counterpart of status (which asks the live gateway). Each check prints one line; any failure returns an error so scripts can gate on `toolhost doctor`.

func EditApprovals

func EditApprovals(path string, names []string, approve bool, w io.Writer) error

EditApprovals adds (approve=true) or removes qualified names from config.

func EditEnabled

func EditEnabled(path string, names []string, enable, only bool, w io.Writer) error

EditEnabled adjusts the live surface. enable adds names to the allowlist (no-op until a list exists — without one, all approved tools are already enabled); disable hides approved tools, materializing the allowlist as approved ∖ names on first use. only=true replaces the list; names=nil with enable resets to "all approved" (the --all form).

func Init

func Init(path string, w io.Writer) error

Init writes a fresh config with a generated bearer token. It refuses to overwrite — the token is a credential, and clobbering it silently is how "my gateway stopped working" bugs are born.

func Install

func Install(cfgPath string, install bool, w io.Writer) error

Install registers (or removes) toolhost serve as a user service so the gateway survives logout and reboot — launchd on macOS, systemd --user on Linux. The unit runs the same binary and config this command was invoked with; on the gateway's own log discipline (stdout is captured to toolhost_serve.log beside the config).

func Logout

func Logout(path, name string, w io.Writer) error

Logout drops a backend's stored upstream grant — the counterpart of `toolhost auth`. Serve then fails closed on that backend until the next `toolhost auth <backend>`.

func Serve

func Serve(ctx context.Context, path string, w io.Writer, stdio bool) error

Serve connects all configured backends, resolves the approved set, and serves until ctx is canceled. stdio=false: HTTP /mcp with bearer. stdio= true: MCP over stdin/stdout — the whole gateway attachable to any client that spawns subprocesses; no bearer (the spawning process owns the pipe), status lines must go to w=stderr (stdout is the protocol).

func Status

func Status(ctx context.Context, path string, w io.Writer) error

Status reports gateway health. Live path: one tools/call to toolhost__status over the real endpoint (works in both serving modes — the SDK negotiates). If the gateway isn't running, it still prints what the config knows: backends, counts, pending requests, stored grants.

Types

This section is empty.

Jump to

Keyboard shortcuts

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