Documentation
¶
Overview ¶
Package connectors is how Blitz's agents reach the systems a team works with (spec_047_connectors): databases now, email and others later. A connector is described, not coded: a category (Databases) and its kinds (PostgreSQL, SQLite…) are YAML descriptors, the built-in ones embedded and more read from <config>/connectors/kinds and a workspace's .agents/connectors/kinds. A kind names the backend that serves it, a Go Backend registered at start (Toolbox for databases), and the capabilities it offers (test, try, queries, schema, query-builder), which the backend must have.
A connection is one file, <name>.yaml, in <config>/connectors/<category> (every workspace) or .agents/connectors/<category> (this one), written by the kind's backend; its secret settings are Blitz secrets, never in the file. Each category's connections are served to the agents as one MCP server per backend.
Index ¶
- Constants
- Variables
- func AllFiles(d Dirs) []string
- func Backends() []string
- func Check(b Backend, k *Kind, c Connection) []string
- func Delete(cat Catalog, d Dirs, r Ref) error
- func Dir(prefixDir, workspace, scope string) string
- func Fingerprint(files []string) string
- func GlobalDir(prefixDir string) string
- func HasSecret(d Dirs, cat Category, c Connection, field string) bool
- func Hash(file string) string
- func IsOrg(scope string) bool
- func Key(scope, category, name string) string
- func KindComment(kind string) string
- func KindOf(text string) string
- func Prepare(cat Catalog, env Env, conn Connection) (Backend, *Kind, Connection, error)
- func Register(b Backend)
- func ResolvePath(p, base string) (string, bool)
- func SecretKey(cat Category, connection, field string) string
- func SecretRef(cat Category, connection, field string) string
- func TryTool(ctx context.Context, cat Catalog, env Env, conn Connection, tool string, ...) (string, bool, error)
- func ValidName(name string) bool
- func With(servers []config.MCPServerConfig, o ServeOptions) []config.MCPServerConfig
- func WorkspaceDir(workspace string) string
- type Backend
- type Capability
- type Catalog
- type Category
- type Column
- type Connection
- type Dirs
- type Env
- type Field
- type Kind
- type Param
- type Query
- type QuerySpec
- type ReadOnly
- type ReadyTool
- type Ref
- type SchemaReader
- type SchemaSpec
- type ServeOptions
- type Serving
- type Table
- type Tester
- type Text
- type ToolInfo
- type Tryer
Constants ¶
const ( FieldText = "text" FieldNumber = "number" FieldSecret = "secret" FieldList = "list" FieldPath = "path" )
Field types.
const ( Positional = "$1" Named = "@name" )
Placeholder styles.
const ( ScopeWorkspace = config.ConnectorScopeWorkspace ScopeGlobal = config.ConnectorScopeGlobal // ScopeOrgLocked and ScopeOrgDefault are the organization's catalog's // layers (spec_053 EN-30): read-only here. ScopeOrgLocked = config.ConnectorScopeOrgLocked ScopeOrgDefault = config.ConnectorScopeOrgDefault )
Scopes.
const ( OriginBuiltin = "builtin" OriginGlobal = ScopeGlobal OriginWorkspace = ScopeWorkspace )
Origins of descriptors.
const ( KindsFolder = config.ConnectorKindsFolder CategoriesFolder = config.ConnectorCategoriesFolder )
Descriptor folders, in a connectors folder.
const Folder = config.ConnectorsFolder
Folder is the connectors' folder, in the config folder and in a workspace's .agents: its kinds and categories folders hold descriptors, and a folder per category its connections.
Variables ¶
var Capabilities = []Capability{Test, Try, Queries, Schema, QueryBuilder}
Capabilities are every capability, in the order they're shown.
var ErrNoTables = errors.New("no tables")
ErrNoTables is a schema read that found no table it could read.
var ErrOrgOwned = errors.New("this connection is your organization's: its Admins change it, through a review")
ErrOrgOwned is the refusal to change one of the organization's connections: its Admins change it, through a review.
var ErrUnknown = errors.New("no such connection")
ErrUnknown is a connection that isn't there.
var FieldTypes = []string{FieldText, FieldNumber, FieldSecret, FieldList, FieldPath}
FieldTypes are the types a field can have ("" is text).
var ParamTypes = []string{"string", "integer", "float", "boolean"}
ParamTypes are the types a parameter may have.
var Scopes = []string{ScopeOrgDefault, ScopeGlobal, ScopeWorkspace, ScopeOrgLocked}
Scopes are the connection scopes, the global one first: what Dirs lists in order.
var TestTimeout = 20 * time.Second
TestTimeout bounds connecting to a connection to test, try or read it.
Functions ¶
func AllFiles ¶
AllFiles are every descriptor and connection file the connectors in d read, for the settings watch.
func Check ¶
func Check(b Backend, k *Kind, c Connection) []string
Check lists what keeps c, of kind k (nil for a custom one), from being written: its name, its kind's required and number settings, and what its backend says.
func Delete ¶
Delete removes a connection and its secrets: every secret its category's kinds could have given it, so none is left behind even when its file can't be read.
func Fingerprint ¶
Fingerprint changes when the files do (added, removed, changed).
func HasSecret ¶
func HasSecret(d Dirs, cat Category, c Connection, field string) bool
HasSecret says whether a connection's secret field has a value, in its own scope.
func Hash ¶
Hash is a connection file's content hash, which a trust decision records ("" when it can't be read).
func KindComment ¶
KindComment is the line that names a file's kind.
func Prepare ¶
func Prepare(cat Catalog, env Env, conn Connection) (Backend, *Kind, Connection, error)
Prepare is c as the backend writes it for a test, try or schema read: its kind and backend, and its secret settings naming their secrets when a value is typed or kept.
func Register ¶
func Register(b Backend)
Register makes a backend available to kinds; a package registers its own in init.
func ResolvePath ¶
ResolvePath is p, a path setting's value (a field of type path), as it opens: a relative one against base (the workspace's folder for a workspace connection, the home folder for a global one), ~/ as the home folder; a value that isn't a file's path (SQLite's :memory:, a file: URI, a ${NAME} filled later) is left as it is (false).
func SecretKey ¶
SecretKey is the Blitz secret a connection's secret field is kept as: DB_SHOP_PASSWORD (the category's SecretPrefix, the name, the field).
func SecretRef ¶
SecretRef is the placeholder a connection file names a secret field's value by: ${DB_SHOP_PASSWORD}.
func TryTool ¶
func TryTool(ctx context.Context, cat Catalog, env Env, conn Connection, tool string, args map[string]any) (string, bool, error)
TryTool runs one of conn's tools as written, with args.
func ValidName ¶
ValidName says whether name can name a connection or a query: lower case letters, digits and _, starting with a letter, at most 40.
func With ¶
func With(servers []config.MCPServerConfig, o ServeOptions) []config.MCPServerConfig
With is servers with the workspace's connector servers in place of any in-process ones there: each category's connection files that are on, served by their backends. A server of the user's own with a connector server's name wins, and Warn says so.
func WorkspaceDir ¶
WorkspaceDir is a workspace's connectors folder.
Types ¶
type Backend ¶
type Backend interface {
// ID is the name kinds give it (toolbox).
ID() string
// Capabilities are what its kinds may offer.
Capabilities() []Capability
// Parse reads a connection file (name, its text) into the form, kinds
// being the category's kinds it serves; one it can't describe is
// Custom.
Parse(cat Category, kinds []Kind, name, text string) Connection
// Check lists what keeps c, of kind k (nil for a custom one), from
// being written, beyond its name and required settings.
Check(k *Kind, c Connection) []string
// Render writes c, of kind k (nil for a custom one), as its file; its
// secret settings name their secrets.
Render(cat Category, k *Kind, c Connection) (string, error)
// Serve is the MCP servers for a category's connection files; none
// when there are none.
Serve(s Serving) []config.MCPServerConfig
}
Backend serves kinds of connectors: it writes and reads their files and turns a category's files into MCP servers. What else it can do is the optional interfaces below (Tester, Tryer, SchemaReader), which Capabilities lists.
type Capability ¶
type Capability string
Capability is something a kind of connector can do, beyond being served to the agents.
const ( // Test connects to a connection as written and lists its tools. Test Capability = "test" // Try runs one of a connection's tools as written. Try Capability = "try" // Queries are the user's own tools, a statement with parameters each. Queries Capability = "queries" // Schema reads what a connection holds: its tables and their columns. Schema Capability = "schema" // QueryBuilder drafts a query from what the user describes, from the // schema, with the sql-query skill (needs Schema and Queries). QueryBuilder Capability = "query-builder" )
The capabilities.
type Catalog ¶
Catalog is what connectors there are: the categories and their kinds, built-in first, then the global descriptors and the workspace's. A descriptor that can't be used is listed with its problem.
func Load ¶
Load reads the catalog for a workspace ("" for the global one alone). A global or workspace descriptor adds a category or a kind; one with the ID of one there already isn't used, so a workspace can't change what a built-in kind means. It's read again only when a descriptor file changes (catalogs).
type Category ¶
type Category struct {
ID string `yaml:"id"`
Name Text `yaml:"name"`
Hint Text `yaml:"hint"`
// Icon is a Material Design icon's name, without mdi (database).
Icon string `yaml:"icon"`
// Server is its MCP server's name, in /mcp and mcp(<server>:…) rules.
Server string `yaml:"server"`
// Prefix namespaces its tools: db__shop_list_tables.
Prefix string `yaml:"prefix"`
// SecretPrefix starts its connections' secrets: DB_SHOP_PASSWORD.
SecretPrefix string `yaml:"secretPrefix"`
// Backend serves its files that name no kind (hand-written ones).
Backend string `yaml:"backend"`
Origin string `yaml:"-"`
Path string `yaml:"-"`
Problem string `yaml:"-"`
}
Category is a group of kinds of connectors (Databases, Email): Studio lists connections by category, and each category's are one MCP server per backend.
type Connection ¶
type Connection struct {
// Name is the file's name; its tools are named <name>_<tool>.
Name string
Category string
// Scope is workspace (.agents/connectors/<category>), global, or the
// organization's (org-locked, org-default).
Scope string
Path string
// Kind is its kind's ID ("" for a custom file the backend can't say).
Kind string
// Description is what it holds, for the agents.
Description string
// Settings are the kind's fields; a secret one names its secret.
Settings map[string]string
// ReadOnly connections can't change what they're connected to.
ReadOnly bool
// Tools are the ready-made tools switched on, by ID.
Tools []string
Queries []Query
// Custom files are more than the form describes: edited as text.
Custom bool
// Text is the file.
Text string
// Problem is why it can't be read ("" when it can).
Problem string
// Trusted says the person trusted it (Serving.Trusted): a global one,
// or a workspace one saved in Studio or with trusted project settings.
Trusted bool
// On says it's served in this workspace: the person can turn any
// connection off there, a global one too (CON-17).
On bool
}
Connection is one connection file, as Studio's form shows it.
func List ¶
func List(cat Catalog, d Dirs) []Connection
List reads the connections, every category's, the global ones first.
func MakeGlobal ¶
func MakeGlobal(d Dirs, category, name string) (Connection, []string, error)
MakeGlobal moves the workspace's connection name, of category, to the global folder with its secrets (CON-19), so every workspace has it: problems, with nothing moved, when its kind or category is the workspace's own descriptor, it's a custom file, or a global one has its name. ErrUnknown when it isn't there.
func Parse ¶
func Parse(cat Catalog, c Category, name, text string) Connection
Parse reads a category's connection file text into the form, by its backend.
func Save ¶
func Save(cat Catalog, d Dirs, conn Connection, values map[string]string, previous string) (Connection, []string, error)
Save writes conn in its scope's folder, in place of previous (its old name, "" for a new one), keeping the secret values given (by field) as Blitz secrets in that scope; problems, with nothing written, when it can't be saved.
type Dirs ¶
Dirs is where connections are: the settings folder (Prefix, "" for ~/.blitz) for the global ones and a workspace ("" for none) for its own.
func (Dirs) ConnectionDir ¶
ConnectionDir is a category's connections folder in a scope ("" for the workspace's with no workspace).
func (Dirs) SecretScope ¶
SecretScope is the secrets scope of a connection scope's.
type Env ¶
Env is where a connection is tested, tried or read: its folders, its category, and the secret values typed into the form (by field) in place of the kept ones.
type Field ¶
type Field struct {
// Key is its name in the file (host, port, project…).
Key string `yaml:"key"`
Label Text `yaml:"label"`
Help Text `yaml:"help"`
// Type is text (the default), number (a whole number), secret (kept as
// a Blitz secret, the file naming it), list (comma-separated) or path.
Type string `yaml:"type"`
Required bool `yaml:"required"`
// Default is used when it's left empty.
Default string `yaml:"default"`
}
Field is a setting a kind takes.
type Kind ¶
type Kind struct {
ID string `yaml:"id"`
Category string `yaml:"category"`
Name Text `yaml:"name"`
Hint Text `yaml:"hint"`
// Backend serves it (toolbox).
Backend string `yaml:"backend"`
// Source is the backend's own type for it (a Toolbox source type).
Source string `yaml:"source"`
Fields []Field `yaml:"fields"`
ReadOnly *ReadOnly `yaml:"readOnly"`
Tools []ReadyTool `yaml:"tools"`
Queries *QuerySpec `yaml:"queries"`
Schema *SchemaSpec `yaml:"schema"`
Capabilities []Capability `yaml:"capabilities"`
// Order places it among its category's kinds, lower first (the
// simplest to set up first); kinds without one come after, in the
// order they're read.
Order int `yaml:"order"`
// Origin is builtin, global or workspace; Path its file ("" built in).
Origin string `yaml:"-"`
Path string `yaml:"-"`
Problem string `yaml:"-"`
}
Kind is a kind of connector: a descriptor.
func (Kind) SecretFields ¶
SecretFields are k's fields kept as secrets (a password).
type Param ¶
type Param struct {
Name string
// Type is string, integer, float or boolean.
Type string
Description string
}
Param is a query's parameter.
type QuerySpec ¶
type QuerySpec struct {
// Type is the backend's tool type for one (postgres-sql).
Type string `yaml:"type"`
// Dialect is the SQL they're in, for the query builder (PostgreSQL).
Dialect string `yaml:"dialect"`
// Placeholders is how a statement names its parameters: $1 (by
// position) or @name.
Placeholders string `yaml:"placeholders"`
Hint Text `yaml:"hint"`
Example string `yaml:"example"`
}
QuerySpec is how a kind's own queries are written.
type ReadOnly ¶
type ReadOnly struct {
Key string `yaml:"key"`
Value any `yaml:"value"`
// Hint says what read-only means for it.
Hint Text `yaml:"hint"`
}
ReadOnly is how a kind is made read-only: Key set to Value in its file. A kind without it can't be.
type ReadyTool ¶
type ReadyTool struct {
ID string `yaml:"id"`
// Type is the backend's own (a Toolbox tool type).
Type string `yaml:"type"`
// Statement makes it a query (a backend's SQL tool).
Statement string `yaml:"statement"`
// About is what it does, for Studio.
About Text `yaml:"about"`
// Agent is what it does, for the agents; {connection} is the
// connection's name and description.
Agent string `yaml:"agent"`
// Writes says it can change what it's connected to: not offered on a
// read-only connection.
Writes bool `yaml:"writes"`
// On says a new connection has it.
On bool `yaml:"on"`
}
ReadyTool is a ready-made tool a kind offers: named <connection>_<id>.
type SchemaReader ¶
type SchemaReader interface {
ReadSchema(ctx context.Context, env Env, k *Kind, c Connection) ([]Table, error)
}
SchemaReader reads a connection's tables and their columns; ErrNoTables when it can read none.
type SchemaSpec ¶
SchemaSpec is how a kind's schema is read: a statement (run as one of its queries) whose rows are the tables, or a reader the backend has.
type ServeOptions ¶
type ServeOptions struct {
Dirs
Trusted func(file string) bool
On func(key string) bool
Warn func(string)
}
ServeOptions is what With serves from: the folders, which workspace files the person trusted (Serving.Trusted; nil: none), which connections are on in the workspace (by Key; nil: all), and where a server it can't serve is said (nil: nowhere).
type Serving ¶
type Serving struct {
Category Category
Dirs
Global []string
Local []string
// Trusted says whether the person trusted a workspace connection file
// (saved it in Studio, or trusted the project's settings): a trusted
// one may use global secrets, and its read-only tools run without
// asking. An untrusted one gets only the workspace's own secrets, and
// every tool asks first. Nil trusts none.
Trusted func(file string) bool
}
Serving is what a backend serves: a category's connection files of its kinds, the global ones then the workspace's.
type Table ¶
type Table struct {
// Name is as a query names it (schema.table, dataset.table).
Name string
// About is its comment or description.
About string
Columns []Column
}
Table is a table (or view) a connection holds, as its schema says.
func ReadSchema ¶
ReadSchema reads conn's tables and their columns: ErrNoTables, saying why, when it can read none.
type Tester ¶
type Tester interface {
Test(ctx context.Context, env Env, k *Kind, c Connection) ([]ToolInfo, error)
}
Tester connects to a connection as written and lists its tools.
type Text ¶
Text is a descriptor's text in English and other languages: written as a string (English) or a map of language tags to text (en, es, fr-CA).
type ToolInfo ¶
type ToolInfo struct {
Name string
Description string
// ReadOnly tools run without asking.
ReadOnly bool
}
ToolInfo is a tool a connection offers.
func TestConnection ¶
TestConnection connects to conn as written and lists its tools.
type Tryer ¶
type Tryer interface {
Try(ctx context.Context, env Env, k *Kind, c Connection, tool string, args map[string]any) (string, bool, error)
}
Tryer runs one of a connection's tools (<connection>_<tool>, or the tool alone) as written, with args: what it answered, and whether that's the tool's error.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package builtin holds the connector descriptors Blitz ships with (spec_047_connectors): categories/<id>.yaml and kinds/<id>.yaml, embedded in the binary.
|
Package builtin holds the connector descriptors Blitz ships with (spec_047_connectors): categories/<id>.yaml and kinds/<id>.yaml, embedded in the binary. |