embed

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0, Apache-2.0 Imports: 75 Imported by: 1 module, 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 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

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

View Source
var ErrNoQuery = errors.New("this kind of source can't be queried here")

ErrNoQuery means a source Query can't run statements on.

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

func ConvertConfig(ctx context.Context, raw []byte) ([]byte, error)

ConvertConfig converts configuration file to flat format and rewrites toolsets to the group kind.

func GetPathsFromConfigFolder

func GetPathsFromConfigFolder(ctx context.Context, folderPath string) ([]string, error)

GetPathsFromConfigFolder loads all YAML files from a directory and merges them

func ReadOnlySources

func ReadOnlySources(cfg Config) []string

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

func ReadOnlyTools(cfg Config) []string

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

func ReadsOnly(statement string) bool

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

type Column struct {
	Name        string
	DBType      string
	Length      *int64
	Nullable    *bool
	Description string
}

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

func Load(ctx context.Context, files []string, env map[string]string) (Config, error)

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

func (p *ConfigParser) LoadAndMergeConfigs(ctx context.Context, filePaths []string) (Config, error)

LoadAndMergeConfigs loads multiple YAML files and merges them

func (*ConfigParser) ParseConfig

func (p *ConfigParser) ParseConfig(ctx context.Context, raw []byte) (Config, error)

ParseConfig parses one configuration file's content.

type QueryOptions added in v0.9.4

type QueryOptions struct {
	Params   []any
	MaxRows  int
	MaxBytes int
	Billed   func(bytes int64) error
	// AccessToken is the caller's own, for a source that queries as each
	// caller (BigQuery's useClientOAuth): the query runs as them.
	AccessToken string
}

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

type Result struct {
	Columns   []Column
	Rows      [][]any
	Truncated bool
}

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

func Start(ctx context.Context, cfg Config, logOut io.Writer) (*Session, error)

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

func (s *Session) Close() error

Close stops the server: its MCP session ends and its sources' connections close.

func (*Session) Read

func (s *Session) Read(p []byte) (int, error)

Read reads the server's MCP messages.

func (*Session) Write

func (s *Session) Write(p []byte) (int, error)

Write sends the server MCP messages.

Jump to

Keyboard shortcuts

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