mcpreg

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 11 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 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

View Source
const (
	Claude = "claude"
	Codex  = "codex"
)

The agents Caprock can register itself with.

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

View Source
const ServerName = "caprock"

ServerName is the name Caprock registers under.

Variables

View Source
var Agents = []string{Claude, Codex}

Agents is the order the screens list them in.

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

View Source
var ErrNotInstalled = errors.New("not installed on this machine")

ErrNotInstalled is a Connect for an agent whose CLI is not on this machine.

View Source
var ErrUnknownAgent = errors.New("unknown agent: want claude or codex")

ErrUnknownAgent is a Connect or Disconnect for an agent not in Agents.

View Source
var Name = map[string]string{Claude: "Claude Code", Codex: "Codex"}

Name is the name the screens use for each agent.

Functions

func AddArgs

func AddArgs(agent, exe string) []string

AddArgs is the argv after the agent's CLI that registers exe.

func RemoveArgs

func RemoveArgs(agent string) []string

RemoveArgs is the argv after the agent's CLI that removes the registration.

func Stable

func Stable(exe string) bool

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 CLIError

type CLIError struct {
	Agent  string
	Output string
	Err    error
}

CLIError is a failed run of the agent's CLI, carrying what it printed.

func (*CLIError) Error

func (e *CLIError) Error() string

func (*CLIError) Unwrap

func (e *CLIError) Unwrap() error

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

func (g *Registrar) Connect(ctx context.Context, agent string) (Status, error)

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

func (g *Registrar) Disconnect(ctx context.Context, agent string) (Status, error)

Disconnect removes the caprock registration from the agent's user config. Not registered is a no-op.

func (*Registrar) Executable

func (g *Registrar) Executable() (string, error)

Executable is the path Connect registers, with an error when it would not last.

func (*Registrar) Status

func (g *Registrar) Status(agent string) Status

Status reports one agent's registration.

func (*Registrar) Statuses

func (g *Registrar) Statuses() []Status

Statuses reports every agent's registration.

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.

Jump to

Keyboard shortcuts

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