Documentation
¶
Overview ¶
Package mcp provides SQLite-backed storage for MCP server configurations.
Index ¶
- type ConfigLookupFunc
- type GlobalStore
- func (g *GlobalStore) Add(cfg *ServerConfig) error
- func (g *GlobalStore) Get(name string) (*ServerConfig, error)
- func (g *GlobalStore) List() ([]*ServerConfig, error)
- func (g *GlobalStore) Path() string
- func (g *GlobalStore) Remove(name string) error
- func (g *GlobalStore) SetEnabled(name string, enabled bool) error
- func (g *GlobalStore) Upsert(cfg *ServerConfig) error
- type LayeredView
- type PostgresStore
- func (p *PostgresStore) Add(cfg *ServerConfig) error
- func (p *PostgresStore) Close() error
- func (p *PostgresStore) Get(name string) (*ServerConfig, error)
- func (p *PostgresStore) InitSchema() error
- func (p *PostgresStore) List() ([]*ServerConfig, error)
- func (p *PostgresStore) Remove(name string) error
- func (p *PostgresStore) SetEnabled(name string, enabled bool) error
- func (p *PostgresStore) UpdateEnv(name string, env map[string]string) error
- type Scope
- type ScopedServer
- type ServerConfig
- type Store
- func (s *Store) Add(cfg *ServerConfig) error
- func (s *Store) Close() error
- func (s *Store) Get(name string) (*ServerConfig, error)
- func (s *Store) List() ([]*ServerConfig, error)
- func (s *Store) Remove(name string) error
- func (s *Store) SetConfigLookup(fn ConfigLookupFunc)
- func (s *Store) SetEnabled(name string, enabled bool) error
- func (s *Store) UpdateEnv(name string, env map[string]string) error
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigLookupFunc ¶
type ConfigLookupFunc func(name string) *ServerConfig
ConfigLookupFunc resolves a server config by name from an external source (e.g., the unified tool store). Returns nil if not found.
type GlobalStore ¶ added in v0.2.0
type GlobalStore struct {
// contains filtered or unexported fields
}
GlobalStore is a JSON-file-backed registry of user-trusted MCP servers. It lives at ~/.bc/mcps.json and is shared across all bc workspaces. Concurrency is handled with a file read/write under a mutex; a serving process that needs ticker-level freshness should re-read on each access.
func NewGlobalStore ¶ added in v0.2.0
func NewGlobalStore(path string) *GlobalStore
NewGlobalStore returns a GlobalStore backed by the given path. The parent directory is created on first write. Missing files are treated as empty registries (List returns nil).
func (*GlobalStore) Add ¶ added in v0.2.0
func (g *GlobalStore) Add(cfg *ServerConfig) error
Add inserts a new server config; fails when a name collision exists.
func (*GlobalStore) Get ¶ added in v0.2.0
func (g *GlobalStore) Get(name string) (*ServerConfig, error)
Get returns a single server config by name; nil when absent.
func (*GlobalStore) List ¶ added in v0.2.0
func (g *GlobalStore) List() ([]*ServerConfig, error)
List returns every registered server config.
func (*GlobalStore) Path ¶ added in v0.2.0
func (g *GlobalStore) Path() string
Path returns the on-disk path for the JSON file.
func (*GlobalStore) Remove ¶ added in v0.2.0
func (g *GlobalStore) Remove(name string) error
Remove deletes a server by name.
func (*GlobalStore) SetEnabled ¶ added in v0.2.0
func (g *GlobalStore) SetEnabled(name string, enabled bool) error
SetEnabled flips the enabled flag on an existing server.
func (*GlobalStore) Upsert ¶ added in v0.2.0
func (g *GlobalStore) Upsert(cfg *ServerConfig) error
Upsert replaces an existing entry or adds it when not present.
type LayeredView ¶ added in v0.2.0
type LayeredView struct {
Global *GlobalStore
Workspace *Store
}
LayeredView composes the global registry with an optional per-workspace Store. Reads merge the two with workspace-overrides winning; writes go to whichever layer the caller selects via the scope argument. This view is read-mostly and intentionally thin — handlers continue to use either GlobalStore or *Store directly depending on scope.
func (*LayeredView) Get ¶ added in v0.2.0
func (v *LayeredView) Get(name string) (*ServerConfig, Scope, error)
Get returns the workspace entry when present, else the global.
func (*LayeredView) List ¶ added in v0.2.0
func (v *LayeredView) List() ([]*ServerConfig, error)
List returns the union of both layers, workspace wins on name collision. Each returned ServerConfig has no Scope field (the ServerConfig struct is used on-disk too); callers who need the owning scope should call ListScoped.
func (*LayeredView) ListScoped ¶ added in v0.2.0
func (v *LayeredView) ListScoped() ([]ScopedServer, error)
ListScoped returns the union annotated with owning scope. Workspace entries override global when a name collides.
type PostgresStore ¶
type PostgresStore struct {
// contains filtered or unexported fields
}
PostgresStore provides Postgres-backed MCP server config storage.
func NewPostgresStore ¶
func NewPostgresStore(db *sql.DB) *PostgresStore
NewPostgresStore creates a PostgresStore from an existing *sql.DB connection.
func (*PostgresStore) Add ¶
func (p *PostgresStore) Add(cfg *ServerConfig) error
Add inserts a new MCP server configuration.
func (*PostgresStore) Close ¶
func (p *PostgresStore) Close() error
Close closes the database connection. Close is a no-op — the shared DB is owned by the caller.
func (*PostgresStore) Get ¶
func (p *PostgresStore) Get(name string) (*ServerConfig, error)
Get returns an MCP server config by name.
func (*PostgresStore) InitSchema ¶
func (p *PostgresStore) InitSchema() error
InitSchema creates the MCP tables in Postgres if they don't exist.
func (*PostgresStore) List ¶
func (p *PostgresStore) List() ([]*ServerConfig, error)
List returns all MCP server configurations.
func (*PostgresStore) Remove ¶
func (p *PostgresStore) Remove(name string) error
Remove deletes an MCP server config by name.
func (*PostgresStore) SetEnabled ¶
func (p *PostgresStore) SetEnabled(name string, enabled bool) error
SetEnabled enables or disables an MCP server config. If the server is not yet in the database but a ConfigLookupFunc is set, the full config is resolved and inserted before applying the toggle.
type Scope ¶ added in v0.2.0
type Scope string
Scope reports which layer of a LayeredStore owns an MCP server config.
type ScopedServer ¶ added in v0.2.0
type ScopedServer struct {
Config *ServerConfig
Scope Scope
}
ScopedServer pairs a ServerConfig with the Scope that owns it.
type ServerConfig ¶
type ServerConfig struct {
CreatedAt time.Time `json:"created_at"`
Env map[string]string `json:"env,omitempty"`
Name string `json:"name"`
Transport Transport `json:"transport"`
Command string `json:"command,omitempty"`
URL string `json:"url,omitempty"`
Args []string `json:"args,omitempty"`
Enabled bool `json:"enabled"`
}
ServerConfig represents an MCP server configuration. Env values should use ${secret:NAME} references (resolved at runtime via pkg/secret) rather than storing sensitive values directly.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store provides MCP server config storage backed by SQLite or Postgres.
func NewStore ¶
NewStore creates a new MCP store for the given workspace path. Uses the shared workspace database; returns an error if unavailable.
func OpenStore ¶
OpenStore opens the MCP store using the shared workspace database. Uses the shared driver type to determine the backend (timescale or sqlite).
func (*Store) Add ¶
func (s *Store) Add(cfg *ServerConfig) error
Add inserts a new MCP server configuration.
func (*Store) Close ¶
Close closes the database connection. No-op when using shared bc.db — CloseShared() handles that.
func (*Store) Get ¶
func (s *Store) Get(name string) (*ServerConfig, error)
Get returns an MCP server config by name.
func (*Store) List ¶
func (s *Store) List() ([]*ServerConfig, error)
List returns all MCP server configurations.
func (*Store) SetConfigLookup ¶
func (s *Store) SetConfigLookup(fn ConfigLookupFunc)
SetConfigLookup registers a fallback function that resolves server configs not yet present in the database (e.g., servers defined only in settings or the unified tool store). Used by SetEnabled to auto-insert config-only servers on first toggle.
func (*Store) SetEnabled ¶
SetEnabled enables or disables an MCP server config. If the server is not yet in the database but a ConfigLookupFunc is set, the full config is resolved and inserted before applying the toggle.
func (*Store) UpdateEnv ¶ added in v0.2.0
UpdateEnv replaces the env map for a named MCP server. Keys with empty values are dropped so the UI can "remove" a variable by clearing it. Returns an error if the server doesn't exist (writes never auto-create the row — use Add for that).
The mutation runs inside a transaction so a partial failure rolls back to the original env (important for the Postgres path, which internally replaces the row).