Documentation
¶
Overview ¶
Package mcpreg tells whether `caprock mcp` is registered with the user's coding agents, and registers or removes it when the user clicks Connect or Disconnect (ADR-078).
Nothing here ever runs on its own. Status is a read of the agent's own config file; Connect and Disconnect run the agent's own CLI — `claude mcp add -s user …`, `codex mcp add …` — so the agent writes its config the way it always does, and a format change on its side cannot be corrupted by a writer on ours.
Why the status reads the file instead of asking `claude mcp get caprock`: that command starts Node (about a second) and then health-checks the server by starting it, so every look at the Second Brain screen would launch a `caprock mcp` child under Claude Code. The user-scope servers are a documented top-level key of `~/.claude.json` (`mcpServers`), and Codex's are a documented table of `~/.codex/config.toml` (`[mcp_servers.<name>]`). Both reads are tolerant: a file that cannot be read or parsed reads as "not connected", never as an error on screen.
Index ¶
Constants ¶
const ( Claude = "claude" Codex = "codex" )
The agents Caprock can register itself with.
const ( NotInstalled = "not_installed" // the agent's CLI is not on this machine NotConnected = "not_connected" // installed; no caprock server registered Connected = "connected" // registered, starting this caprock Different = "different" // registered, but starting another command (a stale path) )
The states of one agent's registration.
const ServerName = "caprock"
ServerName is the name Caprock registers under.
Variables ¶
var Agents = []string{Claude, Codex}
Agents is the order the screens list them in.
var ErrNoStablePath = errors.New("this caprock runs from a temporary location; install it (or move the app to Applications) and try again")
ErrNoStablePath is a Connect from a binary whose path will not last: a macOS translocated app, a disk image, or a `go run` build.
var ErrNotInstalled = errors.New("not installed on this machine")
ErrNotInstalled is a Connect for an agent whose CLI is not on this machine.
var ErrUnknownAgent = errors.New("unknown agent: want claude or codex")
ErrUnknownAgent is a Connect or Disconnect for an agent not in Agents.
var Name = map[string]string{Claude: "Claude Code", Codex: "Codex"}
Name is the name the screens use for each agent.
Functions ¶
func RemoveArgs ¶
RemoveArgs is the argv after the agent's CLI that removes the registration.
func Stable ¶
Stable reports whether exe is a path worth writing into an agent's config: not a macOS App Translocation mount, an app on a disk image, or a `go run` build, each of which is gone by the next reboot or sooner. The desktop app's daemon runs from its own copy in the data directory (ADR-040), which is.
Types ¶
type Registrar ¶
type Registrar struct {
// Exe is the caprock binary to register, in the form that survives an
// upgrade.
Exe func() string
// Env is the environment the agents' CLIs run with: the user's login
// shell's (internal/userenv), since the daemon's own PATH under launchd
// has neither claude nor node.
Env func() []string
// CachedEnv is the same environment if already resolved, for the status
// read, which must never wait for a shell profile. May return nil.
CachedEnv func() []string
// Find resolves an agent's CLI to an absolute path, "" when absent.
Find func(name string) string
// Home is the user's home directory.
Home func() (string, error)
// Timeout bounds one CLI run; 0 is a minute.
Timeout time.Duration
// contains filtered or unexported fields
}
Registrar reads and changes the registrations. Fill every func field.
func (*Registrar) Connect ¶
Connect registers this caprock with the agent, for the user (every project). Already connected is a no-op; a registration that starts another command is removed first, then added again with this one.
func (*Registrar) Disconnect ¶
Disconnect removes the caprock registration from the agent's user config. Not registered is a no-op.
func (*Registrar) Executable ¶
Executable is the path Connect registers, with an error when it would not last.
type Status ¶
type Status struct {
Agent string `json:"agent"`
Name string `json:"name"`
State string `json:"state"`
// Command is the command line the agent's config starts, when caprock is
// registered: what "Update path" replaces.
Command string `json:"command,omitempty"`
// Config is the file the status was read from.
Config string `json:"config,omitempty"`
}
Status is one agent's registration as the screens show it.