Documentation
¶
Index ¶
- Constants
- type Backend
- type BackendConfig
- type BackendError
- type ColumnInfo
- type Config
- type Duration
- type ExampleBackend
- func (b *ExampleBackend) Close() error
- func (b *ExampleBackend) DBIdentity(ctx context.Context, _ any) (map[string]any, error)
- func (b *ExampleBackend) DescribeTable(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
- func (b *ExampleBackend) ExecQuery(ctx context.Context, query string) (map[string]any, error)
- func (b *ExampleBackend) FindRelationships(ctx context.Context, hI dto.HierarchyInput) (string, error)
- func (b *ExampleBackend) GetForeignKeys(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
- func (b *ExampleBackend) Greet(ctx context.Context, args dto.GreetInput) (string, error)
- func (b *ExampleBackend) ListMethods(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
- func (b *ExampleBackend) ListProviders(ctx context.Context) ([]map[string]any, error)
- func (b *ExampleBackend) ListResources(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
- func (b *ExampleBackend) ListServices(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
- func (b *ExampleBackend) ListTables(ctx context.Context, hI dto.HierarchyInput) ([]map[string]interface{}, error)
- func (b *ExampleBackend) ListTablesJSON(ctx context.Context, input dto.ListTablesInput) ([]map[string]interface{}, error)
- func (b *ExampleBackend) ListTablesJSONPage(ctx context.Context, input dto.ListTablesPageInput) (map[string]interface{}, error)
- func (b *ExampleBackend) Ping(ctx context.Context) error
- func (b *ExampleBackend) PromptWriteSafeSelectTool(ctx context.Context, args dto.HierarchyInput) (string, error)
- func (b *ExampleBackend) ReadTableResource(ctx context.Context, hI dto.HierarchyInput) ([]map[string]interface{}, error)
- func (b *ExampleBackend) RunQuery(ctx context.Context, args dto.QueryInput) (string, error)
- func (b *ExampleBackend) RunQueryJSON(ctx context.Context, input dto.QueryJSONInput) ([]map[string]interface{}, error)
- func (b *ExampleBackend) ServerInfo(ctx context.Context, _ any) (dto.ServerInfoOutput, error)
- func (b *ExampleBackend) ValidateQuery(ctx context.Context, query string) ([]map[string]any, error)
- type Field
- type MCPClient
- type MCPServer
- type Provider
- type QueryResult
- type Resource
- type SchemaProvider
- type ServerConfig
- type Service
Constants ¶
const ( MCPClientTypeHTTP = "http" MCPClientTypeSTDIO = "stdio" )
const ( ExplainerForeignKeyStackql = "At present, foreign keys are not meaningfully supported in stackql." ExplainerFindRelationships = "At present, relationship finding is not meaningfully supported in stackql." ExplainerPromptWriteSafeSelectTool = `` /* 257-byte string literal not displayed */ )
const (
DefaultHTTPServerAddress = "127.0.0.1:9876"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Ping verifies the backend connection is active.
Ping(ctx context.Context) error
// Close gracefully shuts down the backend connection.
Close() error
// Server and environment info
ServerInfo(ctx context.Context, args any) (dto.ServerInfoOutput, error)
// Current DB identity details
DBIdentity(ctx context.Context, args any) (map[string]any, error)
Greet(ctx context.Context, args dto.GreetInput) (string, error)
// Execute a SQL query with typed input (preferred)
RunQuery(ctx context.Context, args dto.QueryInput) (string, error)
// Execute a SQL query that does not return rows
ExecQuery(ctx context.Context, query string) (map[string]any, error)
// Execute a SQL query that does not return rows
ValidateQuery(ctx context.Context, query string) ([]map[string]any, error)
// Execute a SQL query and return JSON rows with typed input (preferred)
RunQueryJSON(ctx context.Context, input dto.QueryJSONInput) ([]map[string]interface{}, error)
// Prompt: guidelines for writing safe SELECT queries
PromptWriteSafeSelectTool(ctx context.Context, args dto.HierarchyInput) (string, error)
// List tables in a schema with optional filters and return JSON rows
ListTablesJSON(ctx context.Context, input dto.ListTablesInput) ([]map[string]interface{}, error)
// List tables with pagination and filters
ListTablesJSONPage(ctx context.Context, input dto.ListTablesPageInput) (map[string]interface{}, error)
// List all schemas in the database
ListProviders(ctx context.Context) ([]map[string]any, error)
ListServices(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
ListResources(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
ListMethods(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
// Get detailed information about a table
DescribeTable(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
// Get foreign key information for a table
GetForeignKeys(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
// Find both explicit and implied relationships for a table
FindRelationships(ctx context.Context, hI dto.HierarchyInput) (string, error)
}
func NewExampleBackend ¶
NewExampleBackend creates a new example backend instance.
type BackendConfig ¶
type BackendConfig struct {
// Type specifies the backend type ("tcp", "memory").
Type string `json:"type" yaml:"type"`
// AppName is an optional application name describing the backend.
// In the first instance, this is stackql.
// **Possible** future use case for the backing db (e.g., "postgres", "mysql", etc).
AppName string `json:"app_name" yaml:"app_name"`
// ConnectionString contains the connection details for the backend.
// Format depends on the backend type.
ConnectionString string `json:"dsn" yaml:"dsn"`
// MaxConnections limits the number of backend connections.
MaxConnections int `json:"max_connections" yaml:"max_connections"`
// ConnectionTimeout specifies the timeout for backend connections.
ConnectionTimeout Duration `json:"connection_timeout" yaml:"connection_timeout"`
// QueryTimeout specifies the timeout for individual queries.
QueryTimeout Duration `json:"query_timeout" yaml:"query_timeout"`
}
BackendConfig contains configuration for the backend connection.
type BackendError ¶
type BackendError struct {
// Code is a machine-readable error code.
Code string `json:"code"`
// Message is a human-readable error message.
Message string `json:"message"`
// Details contains additional context about the error.
Details map[string]interface{} `json:"details,omitempty"`
}
BackendError represents an error that occurred in the backend.
func (*BackendError) Error ¶
func (e *BackendError) Error() string
type ColumnInfo ¶
type ColumnInfo interface {
// GetName returns the column name as returned by the query.
GetName() string
// GetType returns the data type of the column (e.g., "string", "int64", "float64").
GetType() string
// IsNullable indicates whether the column can contain null values.
IsNullable() bool
}
ColumnInfo provides metadata about a result column.
func NewColumnInfo ¶
func NewColumnInfo(name, colType string, nullable bool) ColumnInfo
NewColumnInfo creates a new ColumnInfo instance.
type Config ¶
type Config struct {
// Server contains server-specific configuration.
Server ServerConfig `json:"server" yaml:"server"`
// Backend contains backend-specific configuration.
Backend BackendConfig `json:"backend" yaml:"backend"`
}
Config represents the complete configuration for the MCP server.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a configuration with sensible defaults.
func DefaultHTTPConfig ¶
func DefaultHTTPConfig() *Config
func DefaultSSEConfig ¶
func DefaultSSEConfig() *Config
func LoadFromJSON ¶
LoadFromJSON loads configuration from JSON data.
func LoadFromYAML ¶
LoadFromYAML loads configuration from YAML data.
func (*Config) GetBackendConnectionString ¶
func (*Config) GetServerAddress ¶
func (*Config) GetServerTransport ¶
func (*Config) IsTcpBackend ¶
type Duration ¶
Duration is a wrapper around time.Duration that can be marshaled to/from JSON and YAML.
func (Duration) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (Duration) MarshalYAML ¶
MarshalYAML implements yaml.Marshaler.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
func (*Duration) UnmarshalYAML ¶
UnmarshalYAML implements yaml.Unmarshaler.
type ExampleBackend ¶
type ExampleBackend struct {
// contains filtered or unexported fields
}
ExampleBackend is a simple implementation of the Backend interface for demonstration purposes. This shows how to implement the Backend interface without depending on StackQL internals.
func (*ExampleBackend) Close ¶
func (b *ExampleBackend) Close() error
Close implements the Backend interface.
func (*ExampleBackend) DBIdentity ¶
Please adjust all below to sensible signatures in keeping with what is above. Do it now!
func (*ExampleBackend) DescribeTable ¶
func (b *ExampleBackend) DescribeTable(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
func (*ExampleBackend) FindRelationships ¶
func (b *ExampleBackend) FindRelationships(ctx context.Context, hI dto.HierarchyInput) (string, error)
func (*ExampleBackend) GetForeignKeys ¶
func (b *ExampleBackend) GetForeignKeys(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
func (*ExampleBackend) Greet ¶
func (b *ExampleBackend) Greet(ctx context.Context, args dto.GreetInput) (string, error)
func (*ExampleBackend) ListMethods ¶
func (b *ExampleBackend) ListMethods(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
func (*ExampleBackend) ListProviders ¶
func (*ExampleBackend) ListResources ¶
func (b *ExampleBackend) ListResources(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
func (*ExampleBackend) ListServices ¶
func (b *ExampleBackend) ListServices(ctx context.Context, hI dto.HierarchyInput) ([]map[string]any, error)
func (*ExampleBackend) ListTables ¶
func (b *ExampleBackend) ListTables(ctx context.Context, hI dto.HierarchyInput) ([]map[string]interface{}, error)
func (*ExampleBackend) ListTablesJSON ¶
func (b *ExampleBackend) ListTablesJSON(ctx context.Context, input dto.ListTablesInput) ([]map[string]interface{}, error)
func (*ExampleBackend) ListTablesJSONPage ¶
func (b *ExampleBackend) ListTablesJSONPage(ctx context.Context, input dto.ListTablesPageInput) (map[string]interface{}, error)
func (*ExampleBackend) Ping ¶
func (b *ExampleBackend) Ping(ctx context.Context) error
Ping implements the Backend interface.
func (*ExampleBackend) PromptWriteSafeSelectTool ¶
func (b *ExampleBackend) PromptWriteSafeSelectTool(ctx context.Context, args dto.HierarchyInput) (string, error)
func (*ExampleBackend) ReadTableResource ¶
func (b *ExampleBackend) ReadTableResource(ctx context.Context, hI dto.HierarchyInput) ([]map[string]interface{}, error)
func (*ExampleBackend) RunQuery ¶
func (b *ExampleBackend) RunQuery(ctx context.Context, args dto.QueryInput) (string, error)
func (*ExampleBackend) RunQueryJSON ¶
func (b *ExampleBackend) RunQueryJSON(ctx context.Context, input dto.QueryJSONInput) ([]map[string]interface{}, error)
func (*ExampleBackend) ServerInfo ¶
func (b *ExampleBackend) ServerInfo(ctx context.Context, _ any) (dto.ServerInfoOutput, error)
func (*ExampleBackend) ValidateQuery ¶ added in v0.9.266
type Field ¶
type Field interface {
// GetName returns the field identifier.
GetName() string
// GetType returns the field data type.
GetType() string
// IsRequired indicates if this field is mandatory for certain operations.
IsRequired() bool
// GetDescription returns human-readable documentation for the field.
GetDescription() string
}
Field represents a field within a resource.
type MCPClient ¶
type MCPServer ¶
func NewExampleBackendServer ¶
func NewMCPServerWithExampleBackend ¶
NewMCPServerWithExampleBackend creates a new MCP server with an example backend. This is a convenience function for testing and demonstration purposes.
type Provider ¶
type Provider interface {
// GetName returns the provider identifier (e.g., "aws", "google").
GetName() string
// GetVersion returns the provider version.
GetVersion() string
// GetServices returns all services available in this provider.
GetServices() []Service
}
Provider represents a StackQL provider with its services and resources.
func NewProvider ¶
NewProvider creates a new Provider instance.
type QueryResult ¶
type QueryResult interface {
// GetColumns returns metadata about each column in the result set.
GetColumns() []ColumnInfo
// GetRows returns the actual data returned by the query.
GetRows() [][]interface{}
// GetRowsAffected returns the number of rows affected by DML operations.
GetRowsAffected() int64
// GetExecutionTime returns the time taken to execute the query in milliseconds.
GetExecutionTime() int64
}
QueryResult represents the result of a query execution.
func NewQueryResult ¶
func NewQueryResult(columns []ColumnInfo, rows [][]interface{}, rowsAffected, executionTime int64) QueryResult
NewQueryResult creates a new QueryResult instance.
type Resource ¶
type Resource interface {
// GetName returns the resource identifier (e.g., "instances", "buckets").
GetName() string
// GetMethods returns the available operations for this resource.
GetMethods() []string
// GetFields returns the available fields in this resource.
GetFields() []Field
}
Resource represents a queryable resource.
type SchemaProvider ¶
type SchemaProvider interface {
// GetProviders returns all available providers (e.g., aws, google, azure).
GetProviders() []Provider
}
SchemaProvider represents the metadata structure of available resources.
func NewSchemaProvider ¶
func NewSchemaProvider(providers []Provider) SchemaProvider
NewSchemaProvider creates a new SchemaProvider instance.
type ServerConfig ¶
type ServerConfig struct {
// Name is the server name advertised to clients.
Name string `json:"name" yaml:"name"`
// Transport specifies the transport configuration for the server.
Transport string `json:"transport" yaml:"transport"`
// Address is the server Address advertised to clients.
Address string `json:"address" yaml:"address"`
// Scheme is the protocol scheme used by the server.
Scheme string `json:"scheme" yaml:"scheme"`
// Version is the server version advertised to clients.
Version string `json:"version" yaml:"version"`
TLSCertFile string `json:"tls_cert_file,omitempty" yaml:"tls_cert_file,omitempty"`
TLSKeyFile string `json:"tls_key_file,omitempty" yaml:"tls_key_file,omitempty"`
TransportCfg map[string]any `json:"transport_cfg,omitempty" yaml:"transport_cfg,omitempty"`
// Description is a human-readable description of the server.
Description string `json:"description" yaml:"description"`
// MaxConcurrentRequests limits the number of concurrent client requests.
MaxConcurrentRequests int `json:"max_concurrent_requests" yaml:"max_concurrent_requests"`
// RequestTimeout specifies the timeout for individual requests.
RequestTimeout Duration `json:"request_timeout" yaml:"request_timeout"`
IsReadOnly *bool `json:"read_only,omitempty" yaml:"read_only,omitempty"`
}
ServerConfig contains configuration for the MCP server itself.
type Service ¶
type Service interface {
// GetName returns the service identifier (e.g., "ec2", "compute").
GetName() string
// GetResources returns all resources available in this service.
GetResources() []Resource
}
Service represents a service within a provider.
func NewService ¶
NewService creates a new Service instance.