Documentation
¶
Overview ¶
Package embed runs MCP Toolbox for Databases inside Blitz's own process (spec_046_databases): a pruned copy of Toolbox (third_party/mcp-toolbox) with only the databases Blitz offers (Postgres, AlloyDB, SQLite with sqlite-vec, BigQuery), its config parser (config.go, taken from Toolbox's cmd/internal), and Start, which serves one config's tools as MCP over an in-memory pipe for Blitz's MCP client.
Toolbox's command line isn't used: its signal handling, its version check (a call home) and its global OpenTelemetry setup would act on Blitz's process; here none of them runs.
Index ¶
- Constants
- Variables
- func ConvertConfig(ctx context.Context, raw []byte) ([]byte, error)
- func GetPathsFromConfigFolder(ctx context.Context, folderPath string) ([]string, error)
- func ReadOnlySources(cfg Config) []string
- func ReadOnlyTools(cfg Config) []string
- func ReadsOnly(statement string) bool
- type Column
- type Config
- type ConfigParser
- type QueryOptions
- type Result
- type Session
Constants ¶
const Version = "1.14.0"
Version is the Toolbox release this copy was taken from (VERSION, which tools/update_toolbox.sh writes; a test holds them equal).
Variables ¶
var ErrNoQuery = errors.New("this kind of source can't be queried here")
ErrNoQuery means a source Query can't run statements on.
var ErrWrites = errors.New("the connection is read-only: this statement writes")
ErrWrites means a statement that writes, on a read-only source.
Functions ¶
func ConvertConfig ¶
ConvertConfig converts configuration file to flat format and rewrites toolsets to the group kind.
func GetPathsFromConfigFolder ¶
GetPathsFromConfigFolder loads all YAML files from a directory and merges them
func ReadOnlySources ¶
ReadOnlySources are cfg's sources that can't write, by name: SQLite, Postgres and AlloyDB with readOnly (the database refuses a write), and BigQuery with writeMode blocked (or readOnly).
func ReadOnlyTools ¶
ReadOnlyTools are cfg's tools on a read-only source (ReadOnlySources), by name: whatever they say they do, they can't change the database.
func ReadsOnly ¶
ReadsOnly says whether a SQL statement only reads: it starts with SELECT, WITH, EXPLAIN, SHOW, PRAGMA, VALUES, DESCRIBE or TABLE, and has no word that writes, no call to a function that writes or acts (setval, pg_terminate_backend, lo_unlink, dblink_exec, …) and is no PRAGMA that sets a value. It's a hint, not a guard: a read-only source is what stops writes. Studio's readsOnly (apps/desktop/web connectorForm.ts) is a copy for a statement being typed, tested on the same table: change both together.
Types ¶
type Column ¶ added in v0.9.4
Column is a query result's column as its database describes it: its name, the database's type, its declared length (nil when the type has none), whether it may be NULL (nil when the database doesn't say), and its comment in the schema when it comes from a table that has one.
type Config ¶
type Config struct {
Sources server.SourceConfigs `yaml:"sources"`
AuthServices server.AuthServiceConfigs `yaml:"authServices"`
EmbeddingModels server.EmbeddingModelConfigs `yaml:"embeddingModels"`
Tools server.ToolConfigs `yaml:"tools"`
Prompts server.PromptConfigs `yaml:"prompts"`
Resources server.ResourceConfigs `yaml:"resources"`
ResourceTemplates server.ResourceTemplateConfigs `yaml:"resourceTemplates"`
Groups server.GroupConfigs `yaml:"groups"`
}
Config is a parsed Toolbox configuration: its sources, tools, groups and the rest, merged from every file (Blitz: doc comments added).
func Load ¶
Load reads and merges files (Toolbox's YAML: sources, tools, groups), filling each ${NAME} (or ${NAME:default}) from env alone, never from the process's environment: Blitz puts secrets there. A ${NAME} with no value and no default is an error, naming it.
func LoadWith ¶
func LoadWith(ctx context.Context, files []string, env map[string]string, rewrite func(file string, raw []byte) ([]byte, error)) (Config, error)
LoadWith is Load with each file's text given to rewrite first, before its ${NAME}s are filled (nil: as it is). Blitz resolves a connection's relative paths there, against the folder it belongs to, not the service's working directory.
type ConfigParser ¶
type ConfigParser struct {
EnvVars map[string]string
OptionalEnvVars []string
// AllowMissingEnvVars, when true, substitutes the variable name for an unset
// required ${VAR} placeholder instead of erroring. Used by offline flows like
// skills-generate, where source env vars are needed only to satisfy config
// parsing/validation, never to connect. A non-empty placeholder is used (not
// "") so required string fields still pass validation. The served path leaves
// this false so missing config still fails fast.
AllowMissingEnvVars bool
// contains filtered or unexported fields
}
ConfigParser parses configuration files, filling ${NAME} placeholders from EnvVars.
func (*ConfigParser) LoadAndMergeConfigs ¶
LoadAndMergeConfigs loads multiple YAML files and merges them
func (*ConfigParser) ParseConfig ¶
ParseConfig parses one configuration file's content.
type QueryOptions ¶ added in v0.9.4
QueryOptions are a query's parameters (in order) and limits: at most MaxRows rows and about MaxBytes of values (0: no limit), the rest cut. Billed, when set, is told the bytes a billed query (BigQuery's) will read, from a dry run, before it runs; its error stops it.
type Result ¶ added in v0.9.4
Result is a query's columns and rows (each row's values in the columns' order, as the driver read them), and whether a limit cut it.
func Query ¶ added in v0.9.4
func Query(ctx context.Context, cfg Config, source, statement string, opts QueryOptions) (Result, error)
Query runs statement on cfg's source, read-only when the source is, and reads its result with the driver's column metadata (spec_059_data DAT-10), within opts' limits (the rest cut: Truncated). The source is opened for the query and closed after it.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a running Toolbox server's MCP connection: what the client writes goes to the server, and what the server answers is read. Close stops the server and closes its database connections.
func Start ¶
Start initializes cfg's sources (connecting to each: a database that can't be reached is the error) and tools, and serves them as MCP over the returned Session, until Close or ctx is done. Toolbox's log goes to logOut (nil: discarded).
func (*Session) Close ¶
Close stops the server: its MCP session ends and its sources' connections close.