shed

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 20 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 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

View Source
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

View Source
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.

View Source
var PackageProbeTimeout = 90 * time.Second

PackageProbeTimeout is the longer bound for npx and uvx servers, whose first start downloads the package.

View Source
var ProbeTimeout = 20 * time.Second

ProbeTimeout bounds how long Probe waits for a server.

Functions

func BuildConfig

func BuildConfig(e *registry.Entry, vals Values, scope string) (clients.Config, error)

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

func CellarToOpt(p string) string

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

func CheckApproved(e *registry.Entry) error

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

func CheckCommand(e *registry.Entry) error

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

func EntryEnv(e *registry.Entry) []string

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

func EntryHeaders(e *registry.Entry) (map[string]string, error)

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

func ExecArgs(e *registry.Entry, refs []SecretRef) []string

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

func ExecEnv(extra map[string]string, refs []SecretRef) []string

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

func HeadersArgs(e *registry.Entry, refs []SecretRef, plain map[string]string) []string

HeadersArgs builds the arguments of `toolshed headers` (after the binary).

func LiteralSecretHeaders added in v0.2.0

func LiteralSecretHeaders(e *registry.Entry) []string

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

func Orphans(reg *registry.Registry, installed map[string]*clients.Installation) []string

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

func SecretHeader(name string) bool

SecretHeader guesses from an HTTP header's name whether it carries a credential.

func SecretName added in v0.2.0

func SecretName(key string) bool

SecretName guesses from an env var's name whether it holds a secret.

func SecretValue added in v0.2.2

func SecretValue(v string) bool

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

func SelfPath() (string, error)

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.

func Unwrap added in v0.1.3

func Unwrap(cfg clients.Config) (cmd []string, refs map[string]string, wrapped bool)

Unwrap returns the command a registration really runs. Tools with secrets are registered as `toolshed exec <id> --secret KEY=group ... -- <command>`; for those it returns the command after "--", the secrets it gets (key → keyring group) and wrapped=true.

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.

func (HeadersCall) Headers added in v0.2.0

func (c HeadersCall) Headers() (map[string]string, error)

Headers resolves the call: secrets from the keyring, then the templates.

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.

func (Health) HasErrors added in v0.1.3

func (h Health) HasErrors() bool

HasErrors reports whether any finding is an Error.

func (Health) OK added in v0.1.3

func (h Health) OK() bool

OK reports whether nothing at all was found.

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

func Imports(reg *registry.Registry, installed map[string]*clients.Installation) []Import

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

func (im *Import) Build() registry.Entry

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.

func Install

func Install(e *registry.Entry, vals Values, opts InstallOptions) (Result, error)

Install stores secrets, builds the client config and registers the tool with every target client. It fails if any client fails.

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.

func Probe

func Probe(ctx context.Context, e *registry.Entry) ([]Tool, error)

Probe starts (or connects to) a server, performs the MCP handshake and returns the tools it advertises. It is the "does this actually work?" check: if Probe succeeds, Claude Code and Codex will be able to talk to it.

type Values

type Values map[string]string

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.

Jump to

Keyboard shortcuts

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