Documentation
¶
Overview ¶
Package discovery provides lazy per-user capability discovery for vMCP servers.
This package handles context-based storage and retrieval of discovered backend capabilities within request-scoped contexts. The discovery process occurs asynchronously when a request arrives, and results are cached in the context to avoid redundant aggregation operations during request handling.
Package discovery provides lazy per-user capability discovery for vMCP servers.
This package implements per-request capability discovery with user-specific authentication context, enabling truly multi-tenant operation where different users may see different capabilities based on their permissions.
Package discovery provides lazy per-user capability discovery for vMCP servers.
Capabilities are discovered at session initialization and cached in the session for its lifetime. This ensures deterministic behavior and prevents notification spam from redundant capability updates when backends haven't changed.
Future enhancement: Add manager-level capability cache to share discoveries across sessions, plus separate background refresh worker (not in middleware request path) that periodically rediscovers capabilities, detects changes via hash comparison, and pushes updates to active sessions via MCP tools/list_changed notifications. Middleware flow remains unchanged - still just retrieves from session cache on subsequent requests.
Index ¶
- Variables
- func DiscoveredCapabilitiesFromContext(ctx context.Context) (*aggregator.AggregatedCapabilities, bool)
- func Middleware(manager Manager, backends []vmcp.Backend, ...) func(http.Handler) http.Handler
- func WithDiscoveredCapabilities(ctx context.Context, capabilities *aggregator.AggregatedCapabilities) context.Context
- type DefaultManager
- type Manager
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAggregatorNil is returned when aggregator is nil. ErrAggregatorNil = errors.New("aggregator cannot be nil") // ErrDiscoveryFailed is returned when capability discovery fails. ErrDiscoveryFailed = errors.New("capability discovery failed") // ErrNoIdentity is returned when user identity is not found in context. ErrNoIdentity = errors.New("user identity not found in context") )
Functions ¶
func DiscoveredCapabilitiesFromContext ¶
func DiscoveredCapabilitiesFromContext(ctx context.Context) (*aggregator.AggregatedCapabilities, bool)
DiscoveredCapabilitiesFromContext retrieves discovered capabilities from the context. Returns (nil, false) if capabilities are not found in the context.
func Middleware ¶
func Middleware( manager Manager, backends []vmcp.Backend, sessionManager *transportsession.Manager, ) func(http.Handler) http.Handler
Middleware performs capability discovery on session initialization and retrieves cached capabilities for subsequent requests. Must be placed after auth middleware.
Initialize requests (no session ID): discovers capabilities and stores in context. Subsequent requests: retrieves routing table from VMCPSession and reconstructs context.
Returns HTTP 504 for timeouts, HTTP 503 for discovery errors.
func WithDiscoveredCapabilities ¶
func WithDiscoveredCapabilities(ctx context.Context, capabilities *aggregator.AggregatedCapabilities) context.Context
WithDiscoveredCapabilities returns a new context with discovered capabilities attached. If capabilities is nil, the original context is returned unchanged.
Types ¶
type DefaultManager ¶
type DefaultManager struct {
// contains filtered or unexported fields
}
DefaultManager is the default implementation of Manager.
func (*DefaultManager) Discover ¶
func (m *DefaultManager) Discover(ctx context.Context, backends []vmcp.Backend) (*aggregator.AggregatedCapabilities, error)
Discover performs capability aggregation with per-user caching. Results are cached by (user, backend-set) combination for improved performance.
The context must contain an authenticated user identity (set by auth middleware). Returns ErrNoIdentity if user identity is not found in context.
func (*DefaultManager) Stop ¶ added in v0.6.6
func (m *DefaultManager) Stop()
Stop gracefully stops the manager and cleans up resources. This method is safe to call multiple times.
type Manager ¶
type Manager interface {
// Discover performs capability aggregation for the given backends with user context.
Discover(ctx context.Context, backends []vmcp.Backend) (*aggregator.AggregatedCapabilities, error)
// Stop gracefully stops the manager and cleans up resources.
Stop()
}
Manager performs capability discovery with user context.
func NewManager ¶
func NewManager(agg aggregator.Aggregator) (Manager, error)
NewManager creates a new discovery manager with the given aggregator.