Documentation
¶
Overview ¶
Package databases is the connectors' toolbox backend (spec_046_databases, spec_047_connectors): MCP Toolbox for Databases, run inside Blitz's process (third_party/mcp-toolbox/embed), serving a category's connection files (Toolbox YAML: sources, tools, toolsets) as one MCP server, its tools named <prefix>__<tool> (db__shop_list_tables).
A ${NAME} in a file is the Blitz secret NAME, the workspace's own, else the global one; never an environment variable. A workspace's own files reach the global secrets, and their read-only tools run unasked, only once the person trusts them (saved in Studio, or the project's settings trusted).
Index ¶
- Constants
- Variables
- func Names(files []string) []string
- func ReadsOnly(statement string) bool
- func Transport(c config.MCPServerConfig) mcp.Transport
- func Vars(files []string, scope string, lookup func(scope, key string) (string, bool)) map[string]string
- type Backend
- func (Backend) Capabilities() []connectors.Capability
- func (Backend) Check(k *connectors.Kind, c connectors.Connection) []string
- func (Backend) ID() string
- func (Backend) Parse(cat connectors.Category, kinds []connectors.Kind, name, text string) connectors.Connection
- func (Backend) Query(ctx context.Context, env connectors.Env, k *connectors.Kind, ...) (datatable.Table, error)
- func (Backend) ReadSchema(ctx context.Context, env connectors.Env, k *connectors.Kind, ...) ([]connectors.Table, error)
- func (Backend) Render(cat connectors.Category, kind *connectors.Kind, c connectors.Connection) (string, error)
- func (Backend) Serve(s connectors.Serving) []config.MCPServerConfig
- func (Backend) SourceTypes(text string) ([]string, error)
- func (Backend) Test(ctx context.Context, env connectors.Env, k *connectors.Kind, ...) ([]connectors.ToolInfo, error)
- func (Backend) Try(ctx context.Context, env connectors.Env, k *connectors.Kind, ...) (string, bool, error)
Constants ¶
const ID = "toolbox"
ID is the backend's ID, which kinds name, and its in-process server's.
Variables ¶
var MaxSchemaTables = 60
MaxSchemaTables bounds the tables a schema read describes one by one (BigQuery reads each table's metadata).
Functions ¶
func ReadsOnly ¶
ReadsOnly says whether a SQL statement only reads, as Toolbox's tools are marked (a hint: a read-only connection is the guard).
func Transport ¶
func Transport(c config.MCPServerConfig) mcp.Transport
Transport connects to a toolbox server c: each connection loads its files (Args) with their secrets (Env), their file settings (FileSettings, which Serve works out from the workspace's catalog) resolved where each file belongs (baseOf: its workspace, else the home folder), and starts Toolbox, connecting to the databases; closing the connection stops it.
func Vars ¶
func Vars(files []string, scope string, lookup func(scope, key string) (string, bool)) map[string]string
Vars are the values of the files' ${NAME}s that lookup finds (a secrets lookup, as secrets.Vault.Resolve gives) in scope (secrets.AnyScope, or secrets.OnlyWorkspace). The values are remembered for every redactor to mask.
Types ¶
type Backend ¶
type Backend struct{}
Backend is the toolbox backend.
func (Backend) Capabilities ¶
func (Backend) Capabilities() []connectors.Capability
Capabilities are all of them: Toolbox connects, runs tools and queries, and the kinds say how their schema is read.
func (Backend) Check ¶
func (Backend) Check(k *connectors.Kind, c connectors.Connection) []string
Check lists what Toolbox would refuse: a custom file that isn't YAML.
func (Backend) Parse ¶
func (Backend) Parse(cat connectors.Category, kinds []connectors.Kind, name, text string) connectors.Connection
Parse reads a connection file's text into the form: its kind is the one its comment names, else the first of kinds with its source's type.
func (Backend) Query ¶ added in v0.9.4
func (Backend) Query(ctx context.Context, env connectors.Env, k *connectors.Kind, c connectors.Connection, run connectors.QueryRun) (datatable.Table, error)
Query runs run's statement on c as written, on its own connection (spec_059_data DAT-10): read-only when c is, or when run is, and its result read with the driver's column metadata.
func (Backend) ReadSchema ¶
func (Backend) ReadSchema(ctx context.Context, env connectors.Env, k *connectors.Kind, c connectors.Connection) ([]connectors.Table, error)
ReadSchema reads c's tables: by its kind's statement (a query whose rows are table, about, and columns as "name type, …"), or its reader.
func (Backend) Render ¶
func (Backend) Render(cat connectors.Category, kind *connectors.Kind, c connectors.Connection) (string, error)
Render writes c as Toolbox YAML: its source, then its ready-made tools and queries. A secret field always names its secret.
func (Backend) Serve ¶
func (Backend) Serve(s connectors.Serving) []config.MCPServerConfig
Serve is the category's toolbox server, when it has files: in-process, its files in Args and their secrets in Env, offered to every agent; its tools on read-only sources run without asking. A workspace file the person hasn't trusted gets only the workspace's own secrets (its ${NAME}s are kept apart in Env: WorkspaceOnly), and its tools all ask first. A workspace file that doesn't load on its own is left out, and Warn says why, so it can't stop the others being served.
func (Backend) SourceTypes ¶ added in v0.9.1
SourceTypes are the Toolbox source types of every source in a connection file (connectors.SourceLister): an error for a file that isn't YAML, a document with no kind, or a source with no type.
func (Backend) Test ¶
func (Backend) Test(ctx context.Context, env connectors.Env, k *connectors.Kind, c connectors.Connection) ([]connectors.ToolInfo, error)
Test connects to c as written and lists the tools it offers: the error says why it can't be reached.
func (Backend) Try ¶
func (Backend) Try(ctx context.Context, env connectors.Env, k *connectors.Kind, c connectors.Connection, tool string, args map[string]any) (string, bool, error)
Try runs one of c's tools (<connection>_<tool>, or the tool alone) with args and returns what it answered, and whether that's an error.