storage

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package storage provides persistent state used by the composite server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DSNSelector

type DSNSelector func(context.Context) string

DSNSelector selects the complete effective configuration's DSN for the request that creates a stateful MCP session.

type Dialect

type Dialect string

Dialect identifies a supported database family.

const (
	DialectSQLite   Dialect = "sqlite"
	DialectPostgres Dialect = "postgres"
	DialectMySQL    Dialect = "mysql"
)

type EventAdapter

type EventAdapter struct {
	// contains filtered or unexported fields
}

EventAdapter binds each MCP session to the store selected by its first stream. Later requests cannot move that session to another database.

func NewEventAdapter

func NewEventAdapter(registry *Registry, selectDSN DSNSelector) *EventAdapter

NewEventAdapter creates a session-affine event-store adapter.

func (*EventAdapter) After

func (a *EventAdapter) After(ctx context.Context, sessionID, streamID string, index int) iter.Seq2[[]byte, error]

After replays from the store permanently bound to sessionID.

func (*EventAdapter) Append

func (a *EventAdapter) Append(ctx context.Context, sessionID, streamID string, data []byte) error

Append writes to the store permanently bound to sessionID.

func (*EventAdapter) Open

func (a *EventAdapter) Open(ctx context.Context, sessionID, streamID string) error

Open binds sessionID on first use and opens streamID in that store.

func (*EventAdapter) SessionClosed

func (a *EventAdapter) SessionClosed(ctx context.Context, sessionID string) error

SessionClosed removes persisted events and releases the session binding.

type Options

type Options struct {
	// DataDirectory overrides the platform data directory used by an empty DSN.
	DataDirectory string
	// EventTTL controls how long inactive streams are retained.
	EventTTL time.Duration
	// MaxEventBytes bounds retained event payload bytes across all streams.
	MaxEventBytes int64
	// MaxOpenConns bounds PostgreSQL and MySQL pool size.
	MaxOpenConns int
	// MaxIdleConns bounds idle PostgreSQL and MySQL connections.
	MaxIdleConns int
	// ConnMaxLifetime limits connection reuse. The default remains below common
	// MySQL and proxy idle limits.
	ConnMaxLifetime time.Duration
	// Now is used for retention decisions. It defaults to time.Now.
	Now func() time.Time
}

Options controls database pooling and event retention.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry lazily opens and deduplicates stores by a non-reversible DSN digest. It owns every store it returns.

func NewRegistry

func NewRegistry(options Options) *Registry

NewRegistry creates a storage registry.

func (*Registry) Close

func (r *Registry) Close() error

Close closes all stores owned by the registry.

func (*Registry) Get

func (r *Registry) Get(ctx context.Context, dsn string) (Store, error)

Get returns the one opened store for dsn.

type SQLStore

type SQLStore struct {
	// contains filtered or unexported fields
}

SQLStore is a database/sql-backed Store.

func Open

func Open(ctx context.Context, dsn string, options Options) (*SQLStore, error)

Open classifies and opens a supported SQL store, verifies it, and applies all dialect migrations before returning it to callers.

func (*SQLStore) After

func (s *SQLStore) After(ctx context.Context, sessionID, streamID string, index int) iter.Seq2[[]byte, error]

After returns a stable snapshot strictly after index. It checks the purge watermark before reading any rows so callers never receive partial replay.

func (*SQLStore) Append

func (s *SQLStore) Append(ctx context.Context, sessionID, streamID string, data []byte) error

Append atomically allocates the next stream index and records data.

func (*SQLStore) Close

func (s *SQLStore) Close() error

Close releases the database pool.

func (*SQLStore) DB

func (s *SQLStore) DB() *sql.DB

DB returns the underlying database handle for repository integrations.

func (*SQLStore) Dialect

func (s *SQLStore) Dialect() Dialect

Dialect returns the store's database family.

func (*SQLStore) Open

func (s *SQLStore) Open(ctx context.Context, sessionID, streamID string) error

Open prepares a stream for ordered event storage.

func (*SQLStore) Prune

func (s *SQLStore) Prune(ctx context.Context) error

Prune removes expired streams and enough of the oldest event payloads to enforce the configured size bound. The newest event is retained even when a single payload is larger than the bound.

func (*SQLStore) SessionClosed

func (s *SQLStore) SessionClosed(ctx context.Context, sessionID string) error

SessionClosed removes all streams for a session. Repeated calls are safe.

type Store

type Store interface {
	mcp.EventStore
	Prune(context.Context) error
	Close() error
}

Store is an opened persistent store.

Directories

Path Synopsis
Package migrations embeds and applies storage schema migrations.
Package migrations embeds and applies storage schema migrations.

Jump to

Keyboard shortcuts

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