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 …`, `gemini mcp add -s user …`, `grok 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. Cursor has no `mcp add` (cursor.com/docs/cli/mcp, read 2026-11-29: list, list-tools, login, enable, disable), so its Connect merges one entry into the documented ~/.cursor/mcp.json, keeping every other key in its order (ADR-115).
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
- Variables
- func AddArgs(agent, exe string) []string
- func RemoveArgs(agent string) []string
- func Stable(exe string) bool
- type CLIError
- type Registrar
- func (g *Registrar) Connect(ctx context.Context, agent string) (Status, error)
- func (g *Registrar) Disconnect(ctx context.Context, agent string) (Status, error)
- func (g *Registrar) Executable() (string, error)
- func (g *Registrar) Starts(agent, configDir string) bool
- func (g *Registrar) Status(agent string) Status
- func (g *Registrar) Statuses() []Status
- type Status
Constants ¶
const ( Claude = "claude" Codex = "codex" Gemini = "gemini" Grok = "grok" Cursor = "cursor" )
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 ¶
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, codex, gemini, grok or cursor")
ErrUnknownAgent is a Connect or Disconnect for an agent not in Agents.
var Name = map[string]string{Claude: "Claude Code", Codex: "Codex", Gemini: "Gemini CLI", Grok: "Grok Build", Cursor: "Cursor"}
Name is the name the screens use for each agent.
Functions ¶
func AddArgs ¶
AddArgs is the argv after the agent's CLI that registers exe. Gemini CLI's is `gemini mcp add [options] <name> <commandOrUrl> [args...]`, its scope "project" unless -s user; Grok's is Codex's spelling (docs.x.ai/build/features/mcp-servers: `grok mcp add filesystem -- npx …`).
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.
func (*Registrar) Starts ¶ added in v0.206.0
Starts reports whether the agent's own user config already starts a caprock MCP server — registered by Connect, by hand, or for Claude Code by Caprock's plugin — read from configDir for a subscription's Claude Code or Codex (ADR-048), "" for the default. A session Caprock starts is then given no second one (ADR-115): the plugin's server has another name than `caprock`, and Claude Code would start both.
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.