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 ¶
- func Attach(cfgPath, client string, stdio, printOnly bool, w io.Writer) error
- func Auth(ctx context.Context, path, name string, w io.Writer) error
- func ConnectBackends(ctx context.Context, f *config.File, tokens *oauth.Store, sink core.AuditSink, ...) ([]core.Upstream, map[string]error)
- func Discover(ctx context.Context, path string, w io.Writer) error
- func Doctor(ctx context.Context, cfgPath string, w io.Writer) error
- func EditApprovals(path string, names []string, approve bool, w io.Writer) error
- func EditEnabled(path string, names []string, enable, only bool, w io.Writer) error
- func Init(path string, w io.Writer) error
- func Install(cfgPath string, install bool, w io.Writer) error
- func Logout(path, name string, w io.Writer) error
- func Serve(ctx context.Context, path string, w io.Writer, stdio bool) error
- func Status(ctx context.Context, path string, w io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Attach ¶ added in v0.0.2
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 ¶
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 ¶
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
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 ¶
EditApprovals adds (approve=true) or removes qualified names from config.
func EditEnabled ¶
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 ¶
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 ¶
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 ¶
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 ¶
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).
Types ¶
This section is empty.