connector

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNamespaceNotFound is returned when a namespace derived from the
	// request context has no connectors registered.
	ErrNamespaceNotFound = errors.New("namespace not found")

	// ErrConnectorNotFound is returned when the requested connector name is
	// missing in the namespace map.
	ErrConnectorNotFound = errors.New("connector not found")
)

Functions

This section is empty.

Types

type AddOutput

type AddOutput struct {
	Status      string `json:"status"`
	Error       string `json:"error,omitempty"`
	State       string `json:"state,omitempty"`
	CallbackURL string `json:"callbackURL,omitempty"`
	Connector   string `json:"connector,omitempty"`
}

AddOutput conveys the result of attempting to register a connector via the dbSetConnection tool.

type Config

type Config struct {
	Policy            *policy.Policy
	DefaultConnectors []*Namespaced
	CallbackBaseURL   string

	BackendForFrontend *auth.BackendForFrontend `json:"backendForFrontend,omitempty"  yaml:"backendForFrontend,omitempty"`

	// SecretBaseLocation specifies the base URL where connection secrets should
	// be stored. It can be any scheme supported by scy (e.g. mem://, file://,
	// gsecret://, vault://, ...). The default is an in-memory AFS path:
	//   mem://localhost/mcp-sqlkit/.secret/
	// The final secret location for a connector is constructed as:
	//   <SecretBaseLocation>/<driver>/<dbname>/<namespace>[.json]
	// ensuring secrets are isolated per driver, database name and caller
	// namespace. The optional .json suffix is appended for non-file schemes.
	SecretBaseLocation string
}

type ConnectionInput

type ConnectionInput struct {
	Name    string `json:"name" description:"Connector name"`
	Driver  string `` /* 129-byte string literal not displayed */
	Host    string `json:"host,omitempty" description:"Host"`
	Port    int    `json:"port,omitempty" description:"Port"`
	Project string `json:"project,omitempty" description:"Project"`
	Db      string `json:"db,omitempty" description:"DB/Dataset"`
	Options string `json:"options,omitempty" description:"Options"`
}

ConnectionInput is the structure the user supplies when adding a new connector. It purposefully omits sensitive data like secrets.

func (*ConnectionInput) Expand

func (i *ConnectionInput) Expand(dsn string) string

func (*ConnectionInput) Init

func (i *ConnectionInput) Init(config *meta.Config)

func (*ConnectionInput) Validate

func (i *ConnectionInput) Validate(config *meta.Config) error

type Connector

type Connector struct {
	Name    string        `json:"name" yaml:"name"`
	DSN     string        `json:"dsn" yaml:"dsn"`
	Driver  string        `json:"driver" yaml:"driver"`
	Secrets *scy.Resource `json:"secrets,omitempty" yaml:"secrets,omitempty" internal:"true"`
	// contains filtered or unexported fields
}

func (*Connector) Close

func (c *Connector) Close() error

func (*Connector) Db

func (c *Connector) Db(ctx context.Context) (*sql.DB, error)

func (*Connector) ExpandDSN

func (c *Connector) ExpandDSN(ctx context.Context) (string, error)

func (*Connector) SetSecrets

func (c *Connector) SetSecrets(secrets *scy.Service)

type Connectors

type Connectors struct {
	*syncmap.Map[string, *Connector]
}

func NewConnectors

func NewConnectors() *Connectors

type ListInput

type ListInput struct {
	Pattern string `json:"pattern"`
}

ListInput represents parameters for the List tool. Currently it is empty but defined for forward-compatibility with possible future filters.

type ListOutput

type ListOutput struct {
	Data   []interface{} `json:"data,omitempty"`
	Status string        `json:"status"`
	Error  string        `json:"error,omitempty"`
}

ListOutput represents result returned by the List tool.

type Manager

type Manager struct {
	Config *Config
	// contains filtered or unexported fields
}

func NewManager

func NewManager(cfg *Config, authSvc *auth.Service, secrets *scy.Service) *Manager

func (*Manager) CancelPending

func (c *Manager) CancelPending(ctx context.Context, uuid string) error

CancelPending aborts a pending secret submission. Waiting goroutines are released but the connector is NOT activated.

func (*Manager) CompletePending

func (c *Manager) CompletePending(uuid string) error

CompletePending marks pending secret done and activates connector.

func (*Manager) Connection

func (c *Manager) Connection(ctx context.Context, name string) (*Connector, error)

Connection retrieves the Connector by name from the caller's namespace. It does not perform any UI-specific logic – the Service wrapper is responsible for deciding whether to initiate secret elicitation. Typed errors are returned so that the caller can differentiate between the failure reasons.

func (*Manager) Get

func (c *Manager) Get(name string) *Connector

Get returns Connector by name in default namespace (mainly for legacy code without context). This replicates previous behaviour but is placed on the Manager to avoid duplication.

func (*Manager) Pending

func (c *Manager) Pending(uuid string) (*PendingSecret, bool)

Pending retrieves pending entry by UUID.

type Namespace

type Namespace struct {
	Name string
	*Connectors
}

func NewNamespace

func NewNamespace(name string) *Namespace

NewNamespace namespaces

type Namespaced

type Namespaced struct {
	Namespace  string
	Connectors []*Connector
}

type Namespaces

type Namespaces struct {
	*syncmap.Map[string, *Namespace]
}

func NewNamespaces

func NewNamespaces() *Namespaces

type PendingSecret

type PendingSecret struct {
	UUID          string
	Namespace     string
	ConnectorMeta *meta.Config
	Connector     *Connector
	NS            *Namespace

	CallbackURL  string
	CredType     reflect.Type
	MCP          client.Operations
	OAuth2Config *oauth2.Config
	ElicitID     string
	// contains filtered or unexported fields
}

PendingSecret represents a connector awaiting credential submission through the secret-elicitation flow.

type PendingSecrets

type PendingSecrets struct {
	*syncmap.Map[string, *PendingSecret]
}

PendingSecrets is a concurrency-safe collection of pending entries.

func NewPendingSecrets

func NewPendingSecrets() *PendingSecrets

func (*PendingSecrets) Close

func (p *PendingSecrets) Close(uuid string)

Close signals completion to waiting goroutines.

type Service

type Service struct {
	*Manager
	// contains filtered or unexported fields
}

func NewService

func NewService(manager *Manager, mcp client.Operations) *Service

NewService builds a connector Service

func (*Service) AddConnection

func (s *Service) AddConnection(ctx context.Context, input *ConnectionInput) (*AddOutput, error)

AddConnection orchestrates creation/upsert of a connector with a two-step elicitation flow: (1) form for non-secret parameters when missing; (2) out-of- band browser flow for secrets. It returns an AddOutput describing the state.

func (*Service) Connection

func (s *Service) Connection(ctx context.Context, name string) (*Connector, error)

func (*Service) GeneratePendingSecret

func (s *Service) GeneratePendingSecret(ctx context.Context, connector *Connector) (*PendingSecret, error)

func (*Service) List

func (s *Service) List(ctx context.Context) []*Connector

List returns all connectors visible in the caller's namespace.

func (*Service) ListConnectors

func (s *Service) ListConnectors(ctx context.Context, input *ListInput) *ListOutput

ListConnectors produces ListOutput with all available connectors. It is a convenience wrapper used by the MCP toolbox tool registration.

func (*Service) Namespace added in v0.2.0

func (s *Service) Namespace(ctx context.Context) (string, error)

Namespace returns the caller namespace derived from auth token when enabled.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context, name string)

Remove deletes a connector from the caller's namespace.

func (*Service) Set

func (s *Service) Set(ctx context.Context, connector *Connector) (*AddOutput, error)

Set registers or updates a connector in the caller's namespace. If its secret already exists, the connector becomes ACTIVE immediately. Otherwise it is placed in PENDING_SECRET state and, provided the client supports the MCP Elicit protocol, a browser flow is initiated to collect the secret value. The method never returns the secret and therefore is safe over MCP RPC.

func (*Service) UpsertConnection

func (s *Service) UpsertConnection(ctx context.Context, input *ConnectionInput) error

UpsertConnection registers or updates a connector based on structured input that deliberately excludes credential fields. The method validates the input against driver metadata, expands the server-side DSN template and delegates to Service.Add which handles secret elicitation.

type UpdateOutput

type UpdateOutput AddOutput

UpdateOutput is an alias kept for symmetry with AddOutput.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL