resourcelayer

package
v1.100.3 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package resourcelayer assembles the managed-resources layer behind one Handle: the Postgres-backed resource store for human-uploaded reference material, the S3 blob client that holds the file bytes, and the MCP-server registration that makes each resource visible in the SDK's native resources/list.

Construction takes explicit inputs — a *sql.DB and the resolved managed-resources config (the S3 connection name, bucket, URI scheme, and the toolkits config map used to resolve a default S3 instance) — so the subsystem is constructible and testable without a Platform. It imports pkg/resource, pkg/platform/toolkitcfg, the mcp-s3 client + its resource adapter, and the MCP SDK, never pkg/platform. The *sql.DB is a shared foundation owned by the caller and passed in.

The MCP server is NOT captured at construction: the store must exist before the caller wires the resources/read middleware, but the server is created later in the caller's setup, so Register / Unregister / LoadAll take the *mcp.Server per call (the caller passes the server it owns at the moment it registers, after the server exists). A snapshot at construction would freeze a nil server and silently skip every registration.

New returns (nil, nil) when db is nil: managed resources need a database, so a no-DB deployment gets the nil Handle and every accessor and mutation degrades to a no-op. Otherwise it builds the store and — when an S3 connection resolves — the blob client, returning an error only when the referenced connection is missing or its client fails to build. The layer owns no background goroutine, so it needs no Stop/Close; the caller closes the shared *sql.DB.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// S3Connection is the explicit S3 toolkit instance name for blob storage.
	// Empty falls back to the default/first S3 instance resolved from Toolkits.
	S3Connection string
	// S3Bucket is the bucket managed resources are stored in (logged at startup).
	S3Bucket string
	// URIScheme is the URI prefix for resource URIs; empty selects the resource
	// package default.
	URIScheme string
	// Toolkits is the raw toolkits config map, walked to resolve a default S3
	// instance when S3Connection is empty.
	Toolkits map[string]any
}

Config carries the resolved managed-resources values the owner needs to assemble the layer. The caller translates its own config into this shape so this package stays free of the platform's config types and defaulting rules.

type Handle

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

Handle owns the assembled managed-resources layer: the resource store and the S3 blob client. Store and S3Client expose the two backends the caller hands to its REST resources API; Register / Unregister / LoadAll take the *mcp.Server per call (the caller owns it and passes it once the server exists) and are the SDK-registration seams wired as the create/delete callbacks and called once at startup. All methods are nil-safe, so a no-DB deployment (nil Handle) degrades cleanly.

func New

func New(db *sql.DB, cfg Config) (*Handle, error)

New assembles the resource store and — when an S3 connection resolves — the S3 blob client. It returns (nil, nil) when db is nil (managed resources are a no-op without a database). It returns an error when a referenced S3 connection is missing from the toolkits config or its client fails to build. When no S3 connection resolves, blob storage is disabled with a WARN but the store-only layer is still returned so metadata operations work. The "managed resources enabled" INFO is emitted in both cases (with an empty s3_connection when blob storage is off) so the startup log always confirms the feature is active.

func (*Handle) LoadAll

func (h *Handle) LoadAll(server *mcp.Server)

LoadAll registers every existing global managed resource from the store with the given MCP server so they are visible on the first resources/list call. Called once at startup. No-op on a nil Handle, a nil store, or a nil server.

func (*Handle) Register

func (h *Handle) Register(server *mcp.Server, res *resource.Resource)

Register registers a managed resource with the given MCP server so it appears in the SDK's native resource list and triggers notifications/resources/list_changed. The SDK handler is a fallback only — the resources middleware normally intercepts resources/read with auth and the S3 fetch before it runs. No-op on a nil Handle, a nil server, or a nil resource.

func (*Handle) S3Client

func (h *Handle) S3Client() resource.S3Client

S3Client returns the S3 blob client for managed resources, or nil on a nil Handle or when no S3 connection was configured.

func (*Handle) Store

func (h *Handle) Store() resource.Store

Store returns the managed resource store, or nil on a nil Handle (managed resources disabled or no database).

func (*Handle) URIScheme

func (h *Handle) URIScheme() string

URIScheme returns the resolved resource URI scheme (the configured value or the resource package default), or "" on a nil Handle. The caller reads it to configure the resources/read middleware.

func (*Handle) Unregister

func (h *Handle) Unregister(server *mcp.Server, uri string)

Unregister removes a managed resource from the given MCP server's resource list, triggering notifications/resources/list_changed. No-op on a nil Handle or a nil server.

Jump to

Keyboard shortcuts

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