Documentation
¶
Overview ¶
Package setup connects sourcebolt to the MCP apps (clients) installed for this user: it finds their config files, adds one server entry without touching anything else, keeps a backup, and can undo.
Index ¶
- Variables
- func Backup(path string, now time.Time) (string, error)
- func LatestBackup(path string) (string, error)
- func LookupRaw(doc []byte, key, name string) (json.RawMessage, bool, error)
- func Merge(doc []byte, key, name string, e any) (out []byte, existed bool, err error)
- func Remove(doc []byte, key, name string) ([]byte, error)
- func Restore(path string) (string, error)
- func RestoreEntry(path, key, name string) (string, error)
- func SelfPath(exe func() (string, error), resolve func(string) (string, error)) (string, error)
- func ServerCommand(exe string, env Env) (string, []string, error)
- func WriteFile(path string, data []byte) error
- type Client
- type Entry
- type Env
Constants ¶
This section is empty.
Variables ¶
var ErrNoBackup = errors.New("no sourcebolt backup found")
ErrNoBackup means setup never changed this file (or every change was already undone).
var ErrNotInstalled = errors.New("sourcebolt is not installed")
ErrNotInstalled means sourcebolt runs from a throwaway place (a temp folder or the npx cache) and neither an installed copy nor npx exists, so there is no command an app could keep starting.
var ErrNotJSON = errors.New("the file is not plain JSON (it may contain comments); add the entry by hand")
ErrNotJSON means the file is not plain JSON (comments, trailing commas, or not an object), so it is left alone.
var IDs = []string{"claude-desktop", "claude-code", "cursor", "vscode", "windsurf", "gemini"}
IDs lists the client ids in the order setup asks about them.
Functions ¶
func Backup ¶
Backup copies path to <path>.sourcebolt-backup-<timestamp> before setup changes it. When path does not exist yet, it writes an empty <...>.absent marker so undo can remove the file again.
func LatestBackup ¶
LatestBackup returns the newest backup of path.
func Merge ¶
Merge adds (or replaces) the entry name under the top-level key, and keeps every other byte of the file. existed reports a replaced entry.
func Restore ¶
Restore puts the newest backup back in place of path (or removes path when the backup records that it did not exist) and then deletes that backup, so a second undo goes one step further back.
func RestoreEntry ¶
RestoreEntry undoes only the entry name under key: it puts back the entry the newest backup had, or removes it when the backup had none, and keeps the rest of the current file. It is for files the app keeps rewriting (Claude Code's ~/.claude.json), where restoring the whole file would lose the app's newer state. The used backup is deleted.
func SelfPath ¶
SelfPath returns this program's path with symlinks followed, so a link into the npx cache is seen as the cache. exe is os.Executable and resolve is filepath.EvalSymlinks; a path that cannot be resolved is used as is.
func ServerCommand ¶
ServerCommand picks the command and arguments an MCP app should run to start sourcebolt, given this process's executable (see SelfPath):
- a stable path is used as is;
- from a temp dir, Go build dir or npm/npx folder: an installed copy (installer location, Homebrew, or PATH outside those places);
- otherwise "npx -y sourcebolt serve" when npx is on PATH;
- otherwise ErrNotInstalled.
A versioned Homebrew path (Cellar, Caskroom) changes on every upgrade, so the bin link is preferred, but the path itself is kept when there is none.
Types ¶
type Client ¶
type Client struct {
ID string // --client name
Name string // shown to the user
Path string // user-level config file
Key string // top-level key that holds the servers
Typed bool // entries carry "type": "stdio"
CLI string // the app's own CLI, when on PATH and preferred over editing the file
Installed bool
Docs string // where the path and shape come from
}
Client is one MCP app and where its user-level config lives.
type Entry ¶
type Entry struct {
Type string `json:"type,omitempty"` // "stdio" where the client's format has it
Command string `json:"command"`
Args []string `json:"args"`
}
Entry is one stdio MCP server entry in a client config.
type Env ¶
type Env struct {
GOOS string
Home string // user home directory
AppData string // %APPDATA% (Windows)
XDGConfig string // $XDG_CONFIG_HOME; empty = <home>/.config
Exists func(path string) bool // file or directory exists
LookPath func(string) (string, error) // finds a program on PATH
LocalAppData string // %LOCALAPPDATA% (Windows installer target)
TempDir string // the OS temp dir (go run, unpacked downloads)
HomebrewPrefix string // $HOMEBREW_PREFIX
}
Env is what client discovery reads from the machine. Tests build one without touching the real home directory.