Documentation
¶
Overview ¶
Package shed implements toolshed's operations (install, uninstall, exec, probe) on top of the registry, the client adapters and the keyring. The CLI and the TUI are both thin front ends over this package.
Index ¶
- Constants
- Variables
- func BuildConfig(e *registry.Entry, vals Values, scope string) (clients.Config, error)
- func CellarToOpt(p string) string
- func Changes(e *registry.Entry, inst *clients.Installation) []string
- func CheckApproved(e *registry.Entry) error
- func CheckCommand(e *registry.Entry) error
- func EntryEnv(e *registry.Entry) []string
- func EntryHeaders(e *registry.Entry) (map[string]string, error)
- func ExecArgs(e *registry.Entry, refs []SecretRef) []string
- func ExecEnv(extra map[string]string, refs []SecretRef) []string
- func HeadersArgs(e *registry.Entry, refs []SecretRef, plain map[string]string) []string
- func LiteralSecretHeaders(e *registry.Entry) []string
- func Orphans(reg *registry.Registry, installed map[string]*clients.Installation) []string
- func SecretHeader(name string) bool
- func SecretName(key string) bool
- func SecretValue(v string) bool
- func SelfPath() (string, error)
- func Targets(e *registry.Entry, opts InstallOptions) []string
- func Uninstall(reg *registry.Registry, e *registry.Entry, inst *clients.Installation, ...) error
- func Unwrap(cfg clients.Config) (cmd []string, refs map[string]string, wrapped bool)
- type DoctorOptions
- type Finding
- type HeadersCall
- type Health
- type Import
- type ImportResult
- type ImportVar
- type InstallOptions
- type Result
- type SecretRef
- type Tool
- type Values
Constants ¶
const ( Warning = "warning" Error = "error" )
Problem levels: a Warning still works but needs attention, an Error means the tool won't work (or isn't what you approved) until it's fixed.
Variables ¶
var ErrPending = errors.New("added by your agent and not approved yet")
ErrPending is returned for tools an agent added that the user hasn't approved yet.
var PackageProbeTimeout = 90 * time.Second
PackageProbeTimeout is the longer bound for npx and uvx servers, whose first start downloads the package.
var ProbeTimeout = 20 * time.Second
ProbeTimeout bounds how long Probe waits for a server.
Functions ¶
func BuildConfig ¶
BuildConfig produces the client registration for an entry. Secret values are written to the keyring and the server is wrapped in `toolshed exec`; without a keyring they fall back to plain env vars in the client config.
For project scope the wrapper is the bare `toolshed` command rather than this binary's absolute path, because .mcp.json is shared through the repository and teammates have toolshed installed in other places.
func CellarToOpt ¶
CellarToOpt rewrites /…/Cellar/<formula>/<version>/rest to /…/opt/<formula>/rest.
func Changes ¶ added in v0.1.3
func Changes(e *registry.Entry, inst *clients.Installation) []string
Changes describes how an installed tool's registry entry differs from what Claude Code and Codex currently run for it: a different command or URL, different fixed environment, or secrets from a different keyring entry.
It exists because a registry can change underneath an installed tool (a teammate edits a shared registry, a toolshed release updates an example), and re-installing would then hand the tool's keyring secrets to a command the user never looked at. Callers show these changes and ask first.
Values the user typed (non-secret inputs) and toolshed's own path aren't compared: those change for harmless reasons.
func CheckApproved ¶ added in v0.1.2
CheckApproved refuses tools an agent added until the user has seen what they run and approved them. Install and Probe both call it, so no front end (CLI, TUI, MCP) can start an unapproved command.
func CheckCommand ¶
CheckCommand verifies a local server's command can be found, so a typo fails at install instead of as a silent "failed to connect" in the client.
func EntryEnv ¶
EntryEnv is ExecEnv for running an entry directly (used by Probe): fixed env, input defaults, and the entry's secrets from the keyring.
func EntryHeaders ¶ added in v0.2.0
EntryHeaders resolves a remote entry's headers for Probe: the values it's installed with, its secrets from the keyring, and input defaults.
func ExecArgs ¶
ExecArgs builds the self-contained arguments for `toolshed exec`:
exec <id> --secret KEY=group ... -- <command> <args...>
Everything exec needs is in the arguments, so a registered server keeps working even if the registry file moves or isn't visible to the client.
func ExecEnv ¶
ExecEnv returns the environment for running a server: the current environment plus extra fixed values, with secrets from the keyring filled in for any key not already set (explicit env always wins).
func HeadersArgs ¶ added in v0.2.0
HeadersArgs builds the arguments of `toolshed headers` (after the binary).
func LiteralSecretHeaders ¶ added in v0.2.0
LiteralSecretHeaders lists headers that look like they carry a credential (Authorization, X-Api-Key, Cookie, …) but have the value written in, not as ${KEY}. That value would end up in the registry file in plain text.
func Orphans ¶ added in v0.1.3
Orphans returns servers registered through `toolshed exec` that are no longer in the registry (deleted or renamed there): they still work, but toolshed can't update or uninstall them by name anymore.
func SecretHeader ¶ added in v0.2.0
SecretHeader guesses from an HTTP header's name whether it carries a credential.
func SecretName ¶ added in v0.2.0
SecretName guesses from an env var's name whether it holds a secret.
func SecretValue ¶ added in v0.2.2
SecretValue guesses from a value whether it's a secret whatever its name: a URL with a password in it (postgresql://app:hunter2@db/app).
func SelfPath ¶
SelfPath is the absolute path of the running toolshed binary, with Homebrew's versioned Cellar path rewritten to the stable opt symlink so registrations survive `brew upgrade`.
func Targets ¶
func Targets(e *registry.Entry, opts InstallOptions) []string
Targets returns the clients an install would write to.
func Uninstall ¶
func Uninstall(reg *registry.Registry, e *registry.Entry, inst *clients.Installation, purge bool) error
Uninstall removes the tool from every client it's registered in. With purge it also deletes its secrets, except groups still used by another installed tool.
Types ¶
type DoctorOptions ¶ added in v0.1.3
type DoctorOptions struct {
Start bool // start every server and list its tools (slow for npx/uvx)
Parallel int // servers started at once; default 4
}
DoctorOptions controls Doctor.
type Finding ¶ added in v0.1.3
type Finding struct {
Level string `json:"level"`
Text string `json:"text"`
Fix string `json:"fix,omitempty"` // a command to run
}
Finding is one problem doctor found, with what to do about it.
type HeadersCall ¶ added in v0.2.0
type HeadersCall struct {
Self string // the toolshed binary it runs
ID string //
Templates map[string]string // header name → template
Secrets map[string]string // key → keyring group
Values map[string]string // non-secret key → value
}
HeadersCall is a parsed `toolshed headers` helper.
func ParseHeadersArgs ¶ added in v0.2.0
func ParseHeadersArgs(args []string) (HeadersCall, error)
ParseHeadersArgs parses the arguments of `toolshed headers` (after "headers").
func UnwrapHeaders ¶ added in v0.2.0
func UnwrapHeaders(helper string) (HeadersCall, bool)
UnwrapHeaders recognises a headers helper toolshed registered.
type Health ¶ added in v0.1.3
type Health struct {
ID string `json:"id"`
Clients []string `json:"clients"`
Tools int `json:"tools"` // tools the server offers; -1 when it wasn't started
Findings []Finding `json:"findings"`
}
Health is doctor's report on one installed tool.
func Doctor ¶ added in v0.1.3
func Doctor(ctx context.Context, reg *registry.Registry, installed map[string]*clients.Installation, opts DoctorOptions) []Health
Doctor checks every installed tool in the registry:
- the registry entry still matches what the clients run (Changes);
- a `toolshed exec` wrapper points at a toolshed binary that exists;
- the command is on PATH, and its secrets are in the keyring;
- npx/uvx packages are pinned;
- with opts.Start, the server starts and lists its tools.
Tools whose entry changed aren't started: that would run a command the user hasn't accepted.
type Import ¶ added in v0.2.0
type Import struct {
Name string // the name it's registered under
Rename bool // Entry.ID differs from Name: re-register under the ID, remove the old name
Entry registry.Entry // what to add to the registry
Values Values // its current env values: the inputs to install with
Vars []ImportVar // its env vars, for the user to sort into secrets and fixed env
Inst *clients.Installation
Clients []string // the clients to re-register it in
Notes []string // things the user should know (a client left alone, …)
Skip string // why it can't be imported, if it can't
}
Import is a server registered in Claude Code or Codex that toolshed doesn't manage yet, turned into a registry entry.
func Imports ¶ added in v0.2.0
Imports finds the servers Claude Code and Codex have that aren't in the registry, including ones registered through `toolshed exec` whose entry was deleted (their secrets are already in the keyring). Sorted by name.
func (*Import) Apply ¶ added in v0.2.0
func (im *Import) Apply(install bool) (ImportResult, error)
Apply imports im as the user sorted its vars: it re-installs the server where it is (unless install is false, its command is missing, or a secret is gone from the keyring), removes an old name, and adds it to the registry. The CLI and the TUI both use it.
func (*Import) Build ¶ added in v0.2.0
Build turns the vars (as the user sorted them) into the entry's inputs and the values to install with. Every var becomes an input, not fixed env, so no value ever lands in the registry file (which may be shared): secrets go to the keyring, the rest stay in the clients' config, just like values typed at `toolshed install`.
type ImportResult ¶ added in v0.2.0
type ImportResult struct {
Entry registry.Entry
Installed bool // re-registered through toolshed (false: only added to the registry)
Moved []string // secrets now in the keyring
Notes []string // why it wasn't installed, client notes, …
}
ImportResult is what Apply did.
type ImportVar ¶ added in v0.2.0
type ImportVar struct {
Key string
Value string
Secret bool // the guess (SecretName); callers let the user change it
}
ImportVar is one environment variable of an imported server.
type InstallOptions ¶
type InstallOptions struct {
Scope string // Claude: "user" (default), "local" or "project"
CodexScope string // Codex: "user" or "project"; defaults to project when Scope is, else user
Clients []string // targets; empty means every available client the entry supports
}
InstallOptions controls where a tool is installed.
func KeepScopes ¶ added in v0.2.0
func KeepScopes(inst *clients.Installation) InstallOptions
KeepScopes is the InstallOptions for installing a tool again exactly where it is now: the same clients, each at its current scope.
type Result ¶ added in v0.2.0
type Result struct {
Clients []string // the clients it's now registered in
Notes []string // things the user should know
}
Result is what Install did.
type SecretRef ¶
type SecretRef struct{ Key, Group string }
SecretRef names a keyring entry to load into the environment.
type Tool ¶
type Tool struct {
Name string
Description string
Destructive bool // the server says this tool may modify or delete things
}
Tool is one tool a server advertises.
type Values ¶
Values maps input keys to the values the user chose.
func Resolve ¶
func Resolve(e *registry.Entry, inst *clients.Installation, overrides Values) (Values, []registry.Input)
Resolve fills in input values from, in order: explicit overrides, the currently installed config (so updates keep earlier choices), the keyring (secrets), and defaults. It returns the values plus the required inputs that are still missing, which the caller should prompt for.