setup

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 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 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

Constants

This section is empty.

Variables

View Source
var ErrNoBackup = errors.New("no sourcebolt backup found")

ErrNoBackup means setup never changed this file (or every change was already undone).

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

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

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

func Backup(path string, now time.Time) (string, error)

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

func LatestBackup(path string) (string, error)

LatestBackup returns the newest backup of path.

func LookupRaw

func LookupRaw(doc []byte, key, name string) (json.RawMessage, bool, error)

LookupRaw returns the entry's JSON text, with every field it has.

func Merge

func Merge(doc []byte, key, name string, e any) (out []byte, existed bool, err error)

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 Remove

func Remove(doc []byte, key, name string) ([]byte, error)

Remove deletes the entry name under the top-level key, if present.

func Restore

func Restore(path string) (string, error)

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

func RestoreEntry(path, key, name string) (string, error)

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

func SelfPath(exe func() (string, error), resolve func(string) (string, error)) (string, error)

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

func ServerCommand(exe string, env Env) (string, []string, error)

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.

func WriteFile

func WriteFile(path string, data []byte) error

WriteFile is writeFile for callers outside the package.

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.

func Clients

func Clients(env Env) []Client

Clients lists every supported client with its config path for env.

func (Client) Entry

func (c Client) Entry(command string, args []string) Entry

Entry is the sourcebolt server entry for this client, running command with args (see ServerCommand).

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.

func Lookup

func Lookup(doc []byte, key, name string) (Entry, bool, error)

Lookup returns the entry name under the top-level key, if any.

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.

func OSEnv

func OSEnv() Env

OSEnv reads the real machine.

Jump to

Keyboard shortcuts

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