app

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 32 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.

help.go — the CLI's self-explanation: grouped verb table, per-verb help, near-miss suggestions, and shell completion. One table is the single source help and completion both render from.

mcpcli.go — the `toolhost mcp` server registry: the federated `X mcp add` grammar pointed at toolhost.json. The developer's habit stays; the binary swaps.

requestscli.go — `toolhost requests`, the human's petition-review surface. gateway__request files petitions into the env's queue file; this command is the other side of the conversation.

Index

Constants

This section is empty.

Variables

View Source
var Verbs = []Verb{
	{"init", "setup", "write a config with a fresh bearer token",
		"toolhost init [--project|--shared]\n\n" +
			"  default:    ~/.toolhost/toolhost.json + fresh th_* token (0600)\n" +
			"  --project   this folder's private env under ~/.toolhost/projects/\n" +
			"  --shared    committable ./.toolhost/toolhost.json — env: token ref, no secret\n\n" +
			"init never overwrites — delete the file first if you mean it."},
	{"doctor", "setup", "check an install end to end — config, token, backends, grants",
		"toolhost doctor\n\n" +
			"Verifies: config parses, token resolves, port free, each backend dials,\n" +
			"oauth grants present, service state. Per-check remedies on failure."},
	{"mcp", "servers", "the server registry — add, list, get, remove, enable, disable, test, tools, auth, logout, import",
		"toolhost mcp <sub>\n\n" +
			"  add <name> <command…|url>   register a backend (flags anywhere; --json / --from / -s scope)\n" +
			"  list                        the registry — name, transport, state, approved count\n" +
			"  get <name>                  one backend's entry, grant, approved tools\n" +
			"  remove <name>               delete it — refuses while it holds approvals (--prune-approvals)\n" +
			"  enable|disable <name>       reconnect / park a backend\n" +
			"  test <name>                 dial it — handshake, tool count, auth state\n" +
			"  tools <name>                its tools with schemas (--names-only)\n" +
			"  auth|logout <name>          upstream OAuth grant / drop the grant\n" +
			"  import <client>             absorb every server in a client's config (--dry-run)\n\n" +
			"Examples:\n" +
			"  toolhost mcp add fs -- npx -y @modelcontextprotocol/server-filesystem /tmp\n" +
			"  toolhost mcp add github https://api.githubcopilot.com/mcp/ --token env:GH_TOKEN\n" +
			"  toolhost mcp import claude"},
	{"discover", "policy", "every tool the backends expose — the governed catalog",
		"toolhost discover [--json]\n\n" +
			"Dials every backend and prints each tool marked:\n" +
			"  ✓ enabled · ○ approved-but-disabled · ! schema drifted · blank discovered only"},
	{"approve", "policy", "approve tool names (schema-pinned) or --requested petitions",
		"toolhost approve <backend__tool…> [--requested] [--dry-run]\n\n" +
			"Approving dials the owning backend and pins each tool's schema hash — the\n" +
			"grant binds to the contract reviewed. Upstream schema drift lapses the\n" +
			"approval until re-approved.\n\n" +
			"  --requested   approve every pending agent tool petition\n" +
			"  --dry-run     show the pins and diff without writing"},
	{"revoke", "policy", "drop approvals — tools leave the surface",
		"toolhost revoke <backend__tool…> [--dry-run]\n\n" +
			"Revoking removes the approval AND its schema pin — the tool leaves the\n" +
			"surface and is uncallable within ~2s of a running serve."},
	{"requests", "policy", "review agent petitions — --accept / --deny",
		"toolhost requests [--all] [--accept <name>] [--deny <name> --reason …]\n\n" +
			"The queue gateway__request files into: tool petitions and proposed\n" +
			"servers. Accepting a tool approves it; accepting a server materializes\n" +
			"its spec into config as a backend. Denied petitions stay visible to the\n" +
			"agent as refused.\n\n" +
			"  --all     include denied petitions in the listing\n" +
			"  --json    machine-readable queue"},
	{"enable", "surface", "put approved tools on the live surface (no args = all)",
		"toolhost enable [names…] [--only names…]\n\n" +
			"  no args     every approved tool is live (clears the allowlist)\n" +
			"  names       add these to the surface\n" +
			"  --only      the surface becomes exactly these\n\n" +
			"Enabling an unapproved tool refuses — approve first."},
	{"disable", "surface", "hide approved tools without un-approving them",
		"toolhost disable <names…>\n\n" +
			"Hidden tools leave the surface and are uncallable but keep their\n" +
			"approval — enable brings them back."},
	{"serve", "run", "serve the governed /mcp (or --stdio)",
		"toolhost serve [--stdio]\n\n" +
			"  default:    http://<listen>/mcp, Authorization: Bearer <token>\n" +
			"  --stdio:    MCP over stdin/stdout — the spawning process is authority,\n" +
			"              no bearer needed\n\n" +
			"The gateway watches the config file — policy and backend edits go live\n" +
			"in ~1.5s, emitting tools/list_changed to subscribed clients.\n" +
			"Admin reads: GET /status (bearer-gated), GET /healthz (open)."},
	{"attach", "run", "write the local-gateway entry into a client",
		"toolhost attach [<client>] [--project|--stdio|--print|--dry-run]\n\n" +
			"  no client   survey every known client — attached, set-up, absent\n" +
			"  <client>    merge the local-gateway entry into its config (user scope)\n" +
			"  --project   this folder's file — tokenless stdio spawn\n" +
			"  --stdio     spawn the gateway instead of HTTP\n" +
			"  --print     show the entry JSON without writing\n" +
			"  --dry-run   show the planned merge\n\n" +
			"Clients: claude, claude-desktop, cline, codex, cursor, devin, gemini,\n" +
			"opencode, roo, vscode, windsurf, zed."},
	{"install", "run", "register serve as a service (launchd / systemd --user)",
		"toolhost install\n\nRegisters `toolhost serve` as a user service for the current env."},
	{"uninstall", "run", "remove the service", "toolhost uninstall — stop and remove the service."},
	{"status", "evidence", "gateway health — backends, counts, petitions (--json)",
		"toolhost status [--json]\n\n" +
			"Gateway up/down, per-backend liveness, tool counts, pending petitions.\n" +
			"Live data comes from GET /status; a down gateway falls back to the\n" +
			"config view. --json is the harness's polling surface."},
	{"audit", "evidence", "tail the evidence log (-n, -kind)",
		"toolhost audit [-n 20] [-kind tool_call]\n\n" +
			"JSONL in the env's state dir: calls, refusals, governance actions,\n" +
			"reloads, backend errors. Never arguments, never secrets."},
	{"version", "cli", "print the version", "toolhost version"},
	{"completion", "cli", "shell completion script — bash|zsh|fish",
		"toolhost completion <bash|zsh|fish>\n\nPrints the script — no dependencies, source it or save it."},
	{"help", "cli", "this list, or one verb: toolhost help <verb>", "toolhost help [<verb>]"},
}

Verbs is the command surface, grouped by job in flow order.

Functions

func ApproveRequested added in v0.0.4

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

ApproveRequested drains the agent's tool-request queue: every pending tool name goes through the normal approve path — schema-pinned like a hand-typed approval. Server petitions are skipped — they answer through `toolhost requests --accept`, which materializes the backend first.

func Attach added in v0.0.2

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

Attach registers the gateway with an MCP client — the last mile of install. File-backed clients get an ownership-preserving, compare-and- swap merge of the mcpServers map; CLI-backed clients get their `mcp add` invocation executed. --stdio attaches the spawn form (serve --stdio) instead of the HTTP endpoint + bearer; --project writes the client's project-scope file in this folder (always the tokenless stdio spawn — no gateway config is needed, the env resolves at spawn time by cwd); --dry-run prints the planned action and resulting entry without writing.

func AttachDetect added in v0.0.4

func AttachDetect(w io.Writer) error

AttachDetect is the no-argument form: survey every known client and report which are attached, which are set up but not attached, and which aren't installed. It touches no gateway config — detection is about the clients, not the endpoint — and writes nothing.

func Audit added in v0.0.4

func Audit(cfgPath string, limit int, kind string, w io.Writer) error

Audit prints the tail of the gateway's JSONL audit log for the human at the shell. Agents have no audit tool. It reads the file directly: the gateway need not be running. limit <= 0 or > 500 reads the default tail.

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 Completion added in v0.0.4

func Completion(argv []string, w io.Writer) error

Completion prints a static completion script for the named shell — hand-rolled, no dependency.

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, enabled 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. Disabled backends are never dialed — parked is a state, not an error.

func Discover

func Discover(ctx context.Context, path string, asJSON bool, 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. asJSON emits the catalog as structured data — the harness form.

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(ctx context.Context, path string, names []string, approve, dryRun bool, w io.Writer) error

EditApprovals adds (approve=true) or removes qualified names from config. Approve is strict: it dials the owning backends and pins each tool's schema hash, so the approval binds to the contract actually reviewed — an upstream that silently changes a schema drops the tool off the surface until re-approved. A name no backend currently exposes fails the whole call (nothing half-approved).

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 Help added in v0.0.4

func Help(argv []string, w io.Writer)

Help renders the grouped verb list, or one verb's deeper help.

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 InitProject added in v0.0.4

func InitProject(w io.Writer) error

InitProject creates the private environment for the current folder — keyed under the user's home (~/.toolhost/projects/<id>) so the folder itself stays clean: nothing to commit, nothing to leak.

func InitShared added in v0.0.4

func InitShared(w io.Writer) error

InitShared creates the committed environment — ./.toolhost/toolhost.json holding an env: token reference, never a literal credential, so the file is safe to check in. The hidden namespaced path reads as tooling, never as project content. Serving HTTP needs TOOLHOST_TOKEN exported; stdio doesn't care.

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 mcp auth`. Serve then fails closed on that backend until the next `toolhost mcp auth <backend>`.

func MCP added in v0.0.4

func MCP(ctx context.Context, argv []string, w io.Writer) error

MCP dispatches the registry group: `toolhost mcp <sub> [flags] [args]`. args arrives as raw argv — mcp's grammar is "flags anywhere, command tail literal", which is not stdlib-flag-shaped, so parsing lives here.

func MCPAdd added in v0.0.4

func MCPAdd(ctx context.Context, argv []string, w io.Writer) error

MCPAdd registers a backend. Write-only by default — approval flags dial to pin schemas, but the entry lands regardless.

func MCPGet added in v0.0.4

func MCPGet(argv []string, w io.Writer) error

func MCPImport added in v0.0.4

func MCPImport(argv []string, w io.Writer) error

func MCPList added in v0.0.4

func MCPList(argv []string, w io.Writer) error

func MCPRemove added in v0.0.4

func MCPRemove(argv []string, w io.Writer) error

func MCPSetEnabled added in v0.0.4

func MCPSetEnabled(argv []string, enable bool, w io.Writer) error

func MCPTest added in v0.0.4

func MCPTest(ctx context.Context, argv []string, w io.Writer) error

func MCPTools added in v0.0.4

func MCPTools(ctx context.Context, argv []string, w io.Writer) error

func Requests added in v0.0.4

func Requests(ctx context.Context, argv []string, w io.Writer) error

Requests dispatches the petition queue: list pending (or all with --all), grant one with --accept <name>, close one with --deny <name>. Tool petitions approve into policy; server petitions materialize into config — the agent's ask becomes a backend entry the human then governs like any other.

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, asJSON bool, w io.Writer) error

Status reports gateway health. Live path: GET /status on the real endpoint — an admin read, bearer-gated like /mcp but never part of the agent's tool surface. If the gateway isn't running, it still prints what the config knows: backends, counts, pending requests, stored grants. asJSON emits the report (or config view) verbatim — the form harnesses poll.

func Suggest added in v0.0.4

func Suggest(got string) string

Suggest offers the nearest verb on a typo — Levenshtein ≤ 2 wins.

Types

type Verb added in v0.0.4

type Verb struct {
	Name, Group, Blurb, Long string
}

Verb is one line of the command surface — name, job group, one-line blurb, and the deeper help shown by `toolhost help <verb>`.

Jump to

Keyboard shortcuts

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