Documentation
¶
Overview ¶
Package schemagate keeps SQL from being written against a table whose columns the agent has not read.
A search hit names a table and describes it. It does not list the table's columns, so an agent that goes from a search hit straight to SQL writes the column names it expects. A wrong guess fails ("Column cannot be resolved"). A guess that happens to name a real column, such as filtering on id when the record id is p_id, returns rows that look right and are wrong, and nothing reports the mistake.
The gate does two things on the SQL tools (trino_query, trino_execute, trino_export), and on no other tool:
- The first statement a session runs against a table whose schema it has not read is refused before it runs (#2386). The refusal carries every such table's columns, types and catalog descriptions, and delivering them counts as the read, so the same statement resent runs.
- A statement that fails because a column or a type is wrong comes back with the columns of each table it names (#2387).
A read is trino_describe_table of the table, fetch of its mcp:dataset reference, a DESCRIBE or SHOW COLUMNS statement, or either of the deliveries above. Reads are kept in the search gate's shared store, under the same discovery scope, for as long as a search is remembered.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wire ¶
func Wire(db *sql.DB, ttl time.Duration, toolkits ToolkitLister, sem semantic.Provider, refuse bool) (mw mcp.Middleware, stop func())
Wire assembles the gate the platform installs: reads kept for ttl in the search gate's store, schemas read through the live Trino toolkits, curation from semantic. It returns the middleware and the function that stops its cleanup loop.
Types ¶
type Column ¶
type Column struct {
Name string
Type string
Comment string
Description string
GlossaryTerms []string
}
Column is one column of a table, as the engine and the catalog describe it.
type Config ¶
type Config struct {
// Store keeps which tables a scope has read. Required.
Store searchgate.Store
// Describer reads a table's columns. Required.
Describer Describer
// Semantic adds the catalog's column descriptions and glossary terms.
// Optional.
Semantic semantic.Provider
// Require refuses a statement against an unread table. When false, the
// gate still adds columns to a failed statement's error.
Require bool
}
Config assembles a Gate.
type Describer ¶
type Describer interface {
// Namespace resolves a connection name (empty: the default connection)
// to the connection and its default catalog and schema.
Namespace(connection string) (Namespace, bool)
// Describe returns a table's columns on a connection.
Describe(ctx context.Context, connection, catalog, schema, table string) ([]Column, error)
}
Describer reads table schemas from the query engine.
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate is the schema gate.
func (*Gate) Middleware ¶
func (g *Gate) Middleware() mcp.Middleware
Middleware returns the receiving middleware. It reads PlatformContext, so it is registered inner to the tool-call middleware (which has authenticated the caller and authorized the tool and the connection), and outer to the error contract, so the error it reads is the normalized one.
func (*Gate) StartCleanup ¶
StartCleanup evicts expired reads every interval until stop closes. In a deployment that runs the search gate too, its cleanup clears the same table; this one keeps a deployment with the search gate off from accumulating them.
type Namespace ¶
Namespace is a connection and the catalog and schema an unqualified table name resolves in on it.
type ToolkitLister ¶
ToolkitLister lists the live toolkits.
type TrinoDescriber ¶
type TrinoDescriber struct {
Toolkits ToolkitLister
}
TrinoDescriber reads schemas through the live Trino toolkits: the connection a statement runs on, under the same engine user the statement itself runs as. Toolkits are listed on every call, because connections are added and removed while the platform runs.
func (TrinoDescriber) Describe ¶
func (d TrinoDescriber) Describe(ctx context.Context, connection, catalog, schema, table string) ([]Column, error)
Describe returns a table's columns on a connection.
func (TrinoDescriber) Namespace ¶
func (d TrinoDescriber) Namespace(connection string) (Namespace, bool)
Namespace resolves a connection name, empty for the default connection, to its name and default catalog and schema. A Trino connection's name is both the name a call binds and the instance name a catalog reference carries (connid reads a connection lister's name as both), so a fetch of mcp:dataset:(trino,<name>,...) and a statement on <name> meet on one key.