Documentation
¶
Overview ¶
Package config is the driven adapter for the JSON config file — the only state toolhost keeps. Approval is a list of qualified names in this file; `toolhost approve` edits it, `serve` reads it at boot.
Index ¶
- Constants
- func ResolveEnv(s string) (string, error)
- type Auth
- type Backend
- type File
- func (f *File) Approve(names ...string) ([]string, error)
- func (f *File) ApprovedSet() map[string]bool
- func (f *File) Disable(names ...string) ([]string, error)
- func (f *File) Enable(names ...string) ([]string, error)
- func (f *File) EnableAll()
- func (f *File) EnableOnly(names ...string) ([]string, error)
- func (f *File) EnabledSet() (map[string]bool, bool)
- func (f *File) IsApproved(qualified string) bool
- func (f *File) IsEnabled(qualified string) bool
- func (f *File) RequestTools(reason string, names ...string) ([]string, error)
- func (f *File) RequestedSet() map[string]bool
- func (f *File) ResolvedToken() (string, error)
- func (f *File) Revoke(names ...string) []string
- func (f *File) Save(path string) error
- type Request
Constants ¶
const ( DefaultListen = "127.0.0.1:8080" DefaultAuditLog = "toolhost_audit.jsonl" // ModeStateless is the default serving mode — sessionless Streamable // HTTP. ModeStateful opts into session-bearing mode for older clients // that need held sessions for pushed notifications/tools/list_changed. ModeStateless = "stateless" ModeStateful = "stateful" // DefaultCallTimeout bounds upstream calls when the config doesn't say. DefaultCallTimeout = "60s" )
Variables ¶
This section is empty.
Functions ¶
func ResolveEnv ¶
ResolveEnv expands an "env:NAME" reference; anything else passes through unchanged. Unset or empty fails closed — a config pointing at a missing variable is broken, not merely incomplete.
Credential fields stay as references inside File — Save round-trips the reference, never the resolved secret, so toolhost.json can carry pointers and be committed safely. Resolution happens at the boundary: ResolvedToken for the gateway token, Backend.Resolved for upstream creds.
Types ¶
type Auth ¶
type Auth struct {
// Type: "none" (default), "bearer" (a static token sent as
// Authorization: Bearer — the API-key shape), "client_credentials"
// (machine OAuth; token endpoint discovered via the server's Protected
// Resource Metadata), "oauth" (interactive auth-code + PKCE; run
// `toolhost auth <backend>` to grant).
Type string `json:"type"`
// bearer:
Token string `json:"token,omitempty"`
// client_credentials + oauth:
ClientID string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
Scopes []string `json:"scopes,omitempty"`
// oauth only: loopback redirect the AS redirects the browser to.
// Must match the registered/registered-via-DCR redirect URI.
RedirectURL string `json:"redirect_url,omitempty"`
}
Auth configures how toolhost authenticates TO an upstream server — orthogonal to the bearer token that authenticates agents to toolhost.
type Backend ¶
type Backend struct {
// Transport is "stdio" (local subprocess), "http" (remote streamable-HTTP
// MCP server), or "sse" (legacy HTTP+SSE MCP server).
Transport string `json:"transport"`
// stdio transport:
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
// EnvAllowlist names host environment variables forwarded to the
// subprocess beyond the safe baseline (PATH, HOME, ...). Credentials
// should reach a backend by being named — here, or via env values
// holding "env:" references — never by inheriting everything.
EnvAllowlist []string `json:"env_allowlist,omitempty"`
// EnvInherit forwards the entire host environment: every credential in
// the gateway's shell reaches the backend. The least-safe option —
// prefer Env + EnvAllowlist.
EnvInherit bool `json:"env_inherit,omitempty"`
// http/sse transports:
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Auth *Auth `json:"auth,omitempty"`
// Passthrough marks this upstream as a federated toolhost gateway: its
// tool names arrive already qualified ("cbm__search_graph") and are
// trusted as-is instead of being re-namespaced. Its own toolhost__*
// meta-tools are dropped — the outer gateway has its own control plane.
Passthrough bool `json:"passthrough,omitempty"`
// CallTimeout overrides the top-level call_timeout for this backend —
// a Go duration ("30s", "2m"). A client-supplied tighter deadline still
// wins; this bounds how long a hung backend may hold a call.
CallTimeout string `json:"call_timeout,omitempty"`
}
Backend describes one upstream MCP server.
type File ¶
type File struct {
Listen string `json:"listen"`
Token string `json:"token"`
AuditLog string `json:"audit_log"`
Backends map[string]*Backend `json:"backends"`
// Mode selects the front-door serving mode — "stateless" (default) or
// "stateful". Stateless is the primary design (SEP-2567 sessionless +
// the 2026-07-28 spec): no Mcp-Session-Id, every request independent.
// Legacy-protocol clients still work sessionlessly there — initialize,
// tools/list, tools/call each stand alone; they cannot receive
// tools/list_changed without a held session. Modern clients can subscribe
// through subscriptions/listen. "stateful" is the opt-in compat mode for
// older clients that must hold Mcp-Session-Id.
Mode string `json:"mode,omitempty"`
// Approved is the qualified-name list ("backend__tool") that Resolve
// intersects with discovery. discovered ≠ approved: everything not on
// this list is invisible and uncallable.
Approved []string `json:"approved"`
// Enabled is the live-surface allowlist, third tier of the invariant:
// nil (absent) means every approved tool is enabled; a non-nil list
// means only enabled∩approved is visible. Pointer so "absent" and
// "explicitly empty" stay distinct — [] must not collapse into all.
Enabled *[]string `json:"enabled,omitempty"`
// CallTimeout bounds every upstream tool call — a Go duration,
// default "60s". A caller's tighter deadline still wins. Per-backend
// call_timeout overrides it. A hung backend can never hold a call
// forever.
CallTimeout string `json:"call_timeout,omitempty"`
// Requested is the agent's pending ask: qualified names an agent put
// on the record via toolhost__request, with its reason. Humans review
// it (`toolhost status`) and approve consumes entries. Agents can
// write it; only humans turn requests into approvals.
Requested []Request `json:"requested,omitempty"`
}
File is the on-disk config document.
func (*File) Approve ¶
Approve adds qualified names; returns those actually added. Approved names drop out of `requested` — the request has been answered.
func (*File) ApprovedSet ¶
ApprovedSet is the lookup form Resolve consumes.
func (*File) Disable ¶
Disable hides approved tools without un-approving them. The first disable materializes the allowlist as approved ∖ names — after that, the live surface is always explicit.
func (*File) Enable ¶
Enable adds qualified names to the live surface. No-op (nil) while no allowlist exists — without one, every approved tool is already enabled. Enabled names must be approved first; enabling is never a backdoor around approval.
func (*File) EnableAll ¶
func (f *File) EnableAll()
EnableAll clears the allowlist — every approved tool is enabled again.
func (*File) EnableOnly ¶
EnableOnly replaces the live surface with exactly the given names — the "I need just these tools" form. All must be approved.
func (*File) EnabledSet ¶
EnabledSet returns the allowlist and whether one is configured — (nil, false) means "all approved tools are enabled".
func (*File) IsApproved ¶
func (*File) IsEnabled ¶
IsEnabled reports whether a qualified tool is on the live surface: enabled (no list, or listed) AND approved.
func (*File) RequestTools ¶
RequestTools records agent approval requests: qualified names, deduped, newest-last. Requesting is not approval — a human still has to approve.
func (*File) RequestedSet ¶
RequestedSet is the lookup form — name → pending request.
func (*File) ResolvedToken ¶
ResolvedToken resolves the gateway bearer token.