Documentation
¶
Overview ¶
Package trino provides a Trino toolkit adapter for the MCP data platform.
Package trino provides a Trino toolkit adapter for the MCP data platform.
Index ¶
- type AnnotationConfig
- type Config
- type ConnectionDescription
- type ConnectionRequiredMiddleware
- type CostEstimationConfig
- type ElicitationConfig
- type ElicitationDeclinedError
- type ElicitationMiddleware
- func (*ElicitationMiddleware) After(_ context.Context, _ *trinotools.ToolContext, result *mcp.CallToolResult, ...) (*mcp.CallToolResult, error)
- func (em *ElicitationMiddleware) Before(ctx context.Context, tc *trinotools.ToolContext) (context.Context, error)
- func (em *ElicitationMiddleware) SetSemanticProvider(p semantic.Provider)
- type ExportAsset
- type ExportAssetRef
- type ExportAssetStore
- type ExportConfig
- type ExportDeps
- type ExportProvenance
- type ExportProvenanceCall
- type ExportS3Client
- type ExportShareCreator
- type ExportUserContext
- type ExportVersion
- type ExportVersionStore
- type Formatter
- type MultiConfig
- type PIIConsentConfig
- type ProgressInjector
- type ReadOnlyInterceptor
- type Toolkit
- func (t *Toolkit) AddConnection(name string, config map[string]any) error
- func (t *Toolkit) Client() *trinoclient.Client
- func (t *Toolkit) Close() error
- func (t *Toolkit) Config() Config
- func (t *Toolkit) Connection() string
- func (t *Toolkit) HasConnection(name string) bool
- func (*Toolkit) Kind() string
- func (t *Toolkit) ListConnections() []toolkit.ConnectionDetail
- func (t *Toolkit) Name() string
- func (t *Toolkit) RegisterTools(s *mcp.Server)
- func (t *Toolkit) RemoveConnection(name string) error
- func (t *Toolkit) SetExportDeps(deps ExportDeps)
- func (t *Toolkit) SetQueryProvider(provider query.Provider)
- func (t *Toolkit) SetSemanticProvider(provider semantic.Provider)
- func (t *Toolkit) Tools() []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnnotationConfig ¶ added in v0.20.0
type AnnotationConfig struct {
ReadOnlyHint *bool `yaml:"read_only_hint"`
DestructiveHint *bool `yaml:"destructive_hint"`
IdempotentHint *bool `yaml:"idempotent_hint"`
OpenWorldHint *bool `yaml:"open_world_hint"`
}
AnnotationConfig holds tool annotation overrides from configuration.
type Config ¶
type Config struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"` // #nosec G117 -- Trino credential from admin YAML config
Catalog string `yaml:"catalog"`
Schema string `yaml:"schema"`
SSL bool `yaml:"ssl"`
SSLVerify bool `yaml:"ssl_verify"`
Timeout time.Duration `yaml:"timeout"`
DefaultLimit int `yaml:"default_limit"`
MaxLimit int `yaml:"max_limit"`
ReadOnly bool `yaml:"read_only"`
ConnectionName string `yaml:"connection_name"`
Description string `yaml:"description"` // Human-readable description of this connection's purpose
Titles map[string]string `yaml:"titles"`
Descriptions map[string]string `yaml:"descriptions"`
Annotations map[string]AnnotationConfig `yaml:"annotations"`
// ProgressEnabled enables progress notifications for query execution.
// Injected by the platform from progress.enabled config.
ProgressEnabled bool `yaml:"progress_enabled"`
// Elicitation configures user confirmation for expensive operations.
// Injected by the platform from elicitation config.
Elicitation ElicitationConfig `yaml:"elicitation"`
}
Config holds Trino toolkit configuration.
type ConnectionDescription ¶ added in v0.26.0
ConnectionDescription holds display information about a connection for error messages when the connection parameter is missing.
type ConnectionRequiredMiddleware ¶ added in v0.26.0
type ConnectionRequiredMiddleware struct {
// contains filtered or unexported fields
}
ConnectionRequiredMiddleware rejects tool calls that omit the connection parameter when multiple Trino connections are configured. The error message lists all available connections with their descriptions so the LLM can choose the correct one.
func NewConnectionRequiredMiddleware ¶ added in v0.26.0
func NewConnectionRequiredMiddleware(connections []ConnectionDescription) *ConnectionRequiredMiddleware
NewConnectionRequiredMiddleware creates a middleware that enforces explicit connection selection. The connections slice describes all available backends.
func (*ConnectionRequiredMiddleware) After ¶ added in v0.26.0
func (*ConnectionRequiredMiddleware) After( _ context.Context, _ *trinotools.ToolContext, result *mcp.CallToolResult, handlerErr error, ) (*mcp.CallToolResult, error)
After is a no-op — validation happens before execution.
func (*ConnectionRequiredMiddleware) Before ¶ added in v0.26.0
func (m *ConnectionRequiredMiddleware) Before(ctx context.Context, tc *trinotools.ToolContext) (context.Context, error)
Before checks that the connection parameter is set for tools that need it.
type CostEstimationConfig ¶ added in v0.21.0
type CostEstimationConfig struct {
Enabled bool `yaml:"enabled"`
RowThreshold int64 `yaml:"row_threshold"`
}
CostEstimationConfig configures query cost estimation.
type ElicitationConfig ¶ added in v0.21.0
type ElicitationConfig struct {
// Enabled is the master switch for all elicitation features.
Enabled bool `yaml:"enabled"`
// CostEstimation configures query cost estimation and confirmation.
CostEstimation CostEstimationConfig `yaml:"cost_estimation"`
// PIIConsent configures PII access consent.
PIIConsent PIIConsentConfig `yaml:"pii_consent"`
}
ElicitationConfig configures elicitation triggers for the Trino toolkit.
type ElicitationDeclinedError ¶ added in v0.21.0
type ElicitationDeclinedError struct {
Reason string
}
ElicitationDeclinedError indicates the user declined an elicitation request. This error is returned when the user explicitly declines or cancels a confirmation prompt (cost estimation, PII consent, etc.).
func (*ElicitationDeclinedError) Error ¶ added in v0.21.0
func (e *ElicitationDeclinedError) Error() string
func (*ElicitationDeclinedError) ErrorCategory ¶ added in v0.21.0
func (*ElicitationDeclinedError) ErrorCategory() string
ErrorCategory implements middleware.CategorizedError.
type ElicitationMiddleware ¶ added in v0.21.0
type ElicitationMiddleware struct {
// contains filtered or unexported fields
}
ElicitationMiddleware intercepts Trino query execution to request user confirmation when queries exceed cost thresholds or access PII data. It implements trinotools.ToolMiddleware.
func (*ElicitationMiddleware) After ¶ added in v0.21.0
func (*ElicitationMiddleware) After( _ context.Context, _ *trinotools.ToolContext, result *mcp.CallToolResult, handlerErr error, ) (*mcp.CallToolResult, error)
After is a no-op — elicitation happens before query execution.
func (*ElicitationMiddleware) Before ¶ added in v0.21.0
func (em *ElicitationMiddleware) Before(ctx context.Context, tc *trinotools.ToolContext) (context.Context, error)
Before checks cost and PII triggers before query execution. Returns an error to abort the query if the user declines.
func (*ElicitationMiddleware) SetSemanticProvider ¶ added in v0.21.0
func (em *ElicitationMiddleware) SetSemanticProvider(p semantic.Provider)
SetSemanticProvider updates the semantic provider (called after toolkit init).
type ExportAsset ¶ added in v1.56.0
type ExportAsset struct {
ID string
OwnerID string
OwnerEmail string
Name string
Description string
ContentType string
S3Bucket string
S3Key string
SizeBytes int64
Tags []string
Provenance ExportProvenance
SessionID string
IdempotencyKey string
}
ExportAsset is the asset data needed for insert.
type ExportAssetRef ¶ added in v1.56.0
ExportAssetRef is returned by idempotency key lookup.
type ExportAssetStore ¶ added in v1.56.0
type ExportAssetStore interface {
InsertExportAsset(ctx context.Context, asset ExportAsset) error
GetByIdempotencyKey(ctx context.Context, ownerID, key string) (*ExportAssetRef, error)
}
ExportAssetStore is the subset of portal.AssetStore needed by trino_export. Defined here to avoid import cycles (portal → registry → trino).
type ExportConfig ¶ added in v1.56.0
type ExportConfig struct {
MaxRows int `yaml:"max_rows"`
MaxBytes int64 `yaml:"max_bytes"`
DefaultTimeout time.Duration `yaml:"default_timeout"`
MaxTimeout time.Duration `yaml:"max_timeout"`
}
ExportConfig holds configuration for the trino_export tool.
type ExportDeps ¶ added in v1.56.0
type ExportDeps struct {
AssetStore ExportAssetStore
VersionStore ExportVersionStore
S3Client ExportS3Client
S3Bucket string
S3Prefix string
BaseURL string
Config ExportConfig
// GetUserContext extracts user identity from the request context.
// Injected by the platform to avoid importing middleware.
GetUserContext func(ctx context.Context) *ExportUserContext
// GetProvenanceCalls extracts provenance tool calls from the request context.
// Injected by the platform to avoid importing middleware.
GetProvenanceCalls func(ctx context.Context) []ExportProvenanceCall
}
ExportDeps holds portal-side dependencies injected into the Trino toolkit. All types are defined locally to avoid import cycles (portal → registry → trino).
type ExportProvenance ¶ added in v1.56.0
type ExportProvenance struct {
ToolCalls []ExportProvenanceCall
SessionID string
UserID string
}
ExportProvenance records provenance for an exported asset.
type ExportProvenanceCall ¶ added in v1.56.0
ExportProvenanceCall represents a tool call in the provenance chain.
type ExportS3Client ¶ added in v1.56.0
type ExportS3Client interface {
PutObject(ctx context.Context, bucket, key string, data []byte, contentType string) error
}
ExportS3Client is the subset of portal.S3Client needed by trino_export.
type ExportShareCreator ¶ added in v1.56.0
type ExportShareCreator interface {
}
ExportShareCreator creates public share links for exported assets.
type ExportUserContext ¶ added in v1.56.0
ExportUserContext holds user identity extracted from the request context.
type ExportVersion ¶ added in v1.56.0
type ExportVersion struct {
ID string
AssetID string
S3Key string
S3Bucket string
ContentType string
SizeBytes int64
CreatedBy string
ChangeSummary string
}
ExportVersion is the version data for creating a new version.
type ExportVersionStore ¶ added in v1.56.0
type ExportVersionStore interface {
CreateExportVersion(ctx context.Context, version ExportVersion) (int, error)
}
ExportVersionStore is the subset of portal.VersionStore needed by trino_export.
type Formatter ¶ added in v1.56.0
type Formatter interface {
// Format serializes columns and rows into the target format.
Format(columns []string, rows [][]any) ([]byte, error)
// ContentType returns the MIME type for the formatted output.
ContentType() string
// FileExtension returns the file extension (including dot) for the format.
FileExtension() string
}
Formatter converts query results into a specific output format.
type MultiConfig ¶ added in v0.26.0
type MultiConfig struct {
// DefaultConnection is the name of the default connection.
DefaultConnection string
// Instances maps connection names to their parsed configurations.
Instances map[string]Config
}
MultiConfig holds configuration for a multi-connection Trino toolkit.
func ParseMultiConfig ¶ added in v0.26.0
ParseMultiConfig builds a MultiConfig from the aggregate factory's instance map.
type PIIConsentConfig ¶ added in v0.21.0
type PIIConsentConfig struct {
Enabled bool `yaml:"enabled"`
}
PIIConsentConfig configures PII access consent.
type ProgressInjector ¶ added in v0.20.0
type ProgressInjector struct{}
ProgressInjector is a trinotools.ToolMiddleware that creates an mcpProgressNotifier per-request from the ServerSession and progress token stored in context by MCPToolCallMiddleware.
func (*ProgressInjector) After ¶ added in v0.20.0
func (*ProgressInjector) After( _ context.Context, _ *trinotools.ToolContext, result *mcp.CallToolResult, handlerErr error, ) (*mcp.CallToolResult, error)
After is a no-op — progress notifications are sent during tool execution, not after.
func (*ProgressInjector) Before ¶ added in v0.20.0
func (*ProgressInjector) Before(ctx context.Context, _ *trinotools.ToolContext) (context.Context, error)
Before reads the server session and progress token from context and, if both are present, creates an mcpProgressNotifier and stores it in context via trinotools.WithProgressNotifier.
type ReadOnlyInterceptor ¶ added in v0.2.0
type ReadOnlyInterceptor struct{}
ReadOnlyInterceptor blocks write operations when read_only mode is enabled. It delegates write detection to the upstream mcp-trino IsWriteSQL function.
func NewReadOnlyInterceptor ¶ added in v0.2.0
func NewReadOnlyInterceptor() *ReadOnlyInterceptor
NewReadOnlyInterceptor creates a new read-only query interceptor.
func (*ReadOnlyInterceptor) Intercept ¶ added in v0.2.0
func (*ReadOnlyInterceptor) Intercept(_ context.Context, sql string, _ trinotools.ToolName) (string, error)
Intercept checks if the query is a write operation and blocks it in read-only mode.
type Toolkit ¶
type Toolkit struct {
// contains filtered or unexported fields
}
Toolkit wraps mcp-trino toolkit for the platform.
func NewMulti ¶ added in v0.26.0
func NewMulti(cfg MultiConfig) (*Toolkit, error)
NewMulti creates a multi-connection Trino toolkit that routes requests to the correct backend based on the "connection" parameter in each tool call. This replaces the previous pattern of creating N separate single-client toolkits that would clobber each other's tool registrations.
func (*Toolkit) AddConnection ¶ added in v1.48.0
AddConnection adds a named connection at runtime. Requires multi-connection mode (created via NewMulti).
func (*Toolkit) Client ¶
func (t *Toolkit) Client() *trinoclient.Client
Client returns the underlying Trino client for direct use.
func (*Toolkit) Connection ¶ added in v0.12.1
Connection returns the connection name for audit logging.
func (*Toolkit) HasConnection ¶ added in v1.48.0
HasConnection returns true if a connection with the given name exists.
func (*Toolkit) ListConnections ¶ added in v0.26.0
func (t *Toolkit) ListConnections() []toolkit.ConnectionDetail
ListConnections returns details for all connections managed by this toolkit. Implements toolkit.ConnectionLister.
func (*Toolkit) RegisterTools ¶
RegisterTools registers Trino tools with the MCP server. The platform provides a unified list_connections tool, so the per-toolkit trino_list_connections is excluded.
func (*Toolkit) RemoveConnection ¶ added in v1.48.0
RemoveConnection removes a named connection at runtime. Requires multi-connection mode (created via NewMulti).
func (*Toolkit) SetExportDeps ¶ added in v1.56.0
func (t *Toolkit) SetExportDeps(deps ExportDeps)
SetExportDeps injects portal dependencies for trino_export.
func (*Toolkit) SetQueryProvider ¶
SetQueryProvider sets the query execution provider for enrichment.
func (*Toolkit) SetSemanticProvider ¶
SetSemanticProvider sets the semantic metadata provider for enrichment.