session

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package session provides vMCP session management types and utilities, including the AdmissionQueue used to coordinate concurrent session access.

Index

Constants

View Source
const (

	// MetadataKeyBackendIDs is the transport-session metadata key that holds
	// a comma-separated, sorted list of successfully-connected backend IDs.
	// The key is always written, even as an empty string for zero-backend
	// sessions. Key presence distinguishes an explicit zero-backend state from
	// absent/corrupted metadata in RestoreSession.
	MetadataKeyBackendIDs = "vmcp.backend.ids"

	// MetadataKeyBackendSessionPrefix is the key prefix for per-backend session IDs.
	// Full key: MetadataKeyBackendSessionPrefix + workloadID → backend_session_id.
	// Used by RestoreSession to reconnect backends with the correct session hint.
	MetadataKeyBackendSessionPrefix = "vmcp.backend.session."
)
View Source
const (
	// Legacy: superseded by MetadataKeyIdentityBinding (#5306); invalidated on read.
	MetadataKeyTokenHash = sessiontypes.MetadataKeyTokenHash
	// Legacy: superseded by MetadataKeyIdentityBinding (#5306).
	MetadataKeyTokenSalt = sessiontypes.MetadataKeyTokenSalt

	MetadataKeyIdentityBinding = sessiontypes.MetadataKeyIdentityBinding
)

Re-exports from the types package for convenience. See the types package for authoritative documentation.

Variables

View Source
var (
	// ErrSessionClosed is returned when an operation is attempted on a closed session.
	ErrSessionClosed = errors.New("session is closed")

	// ErrToolNotFound is returned when the requested tool is not in the routing table.
	ErrToolNotFound = errors.New("tool not found in session routing table")

	// ErrResourceNotFound is returned when the requested resource is not in the routing table.
	ErrResourceNotFound = errors.New("resource not found in session routing table")

	// ErrPromptNotFound is returned when the requested prompt is not in the routing table.
	ErrPromptNotFound = errors.New("prompt not found in session routing table")

	// ErrNoBackendClient is returned when the routing table references a backend
	// that has no entry in the connections map. This indicates an internal
	// invariant violation: under normal operation MakeSession always populates
	// both maps together, so this error should never be seen at runtime.
	ErrNoBackendClient = errors.New("no client available for backend")
)

Sentinel errors returned by defaultMultiSession methods.

Functions

This section is empty.

Types

type AdmissionQueue added in v0.10.1

type AdmissionQueue interface {
	// TryAdmit attempts to admit a request. If the queue is open, it returns
	// (true, done) where done must be called when the request completes.
	// If the queue is already closed, it returns (false, nil).
	TryAdmit() (bool, func())

	// CloseAndDrain closes the queue so that subsequent TryAdmit calls return
	// false, then blocks until all currently-admitted requests have called
	// their done function. Idempotent.
	CloseAndDrain()
}

AdmissionQueue controls admission of concurrent requests to a shared resource that can be closed. Once closed, no further requests are admitted and CloseAndDrain blocks until all previously-admitted requests complete.

type Decorator added in v0.12.5

type Decorator func(ctx context.Context, sess MultiSession) (MultiSession, error)

Decorator wraps a MultiSession with additional behavior. It is called after session creation and must return the (possibly decorated) session. On error the caller closes the current session (which may already be wrapped by earlier decorators); the decorator must not close it.

type MultiSession added in v0.10.1

type MultiSession = sessiontypes.MultiSession

MultiSession is an alias for sessiontypes.MultiSession, re-exported here for backward compatibility and convenience.

type MultiSessionFactory added in v0.10.1

type MultiSessionFactory interface {
	// MakeSessionWithID creates a new MultiSession with a specific session ID.
	// This is used by SessionManager to create sessions using the SDK-assigned ID
	// rather than generating a new UUID internally.
	//
	// The id parameter must be non-empty and should be a valid MCP session ID
	// (visible ASCII characters, 0x21 to 0x7E per the MCP specification).
	//
	// Whether the session allows anonymous (nil) caller identity is derived
	// internally from identity via ShouldAllowAnonymous.
	//
	// All other behaviour (partial initialisation, bounded concurrency, etc.)
	// is identical to MakeSession.
	MakeSessionWithID(
		ctx context.Context,
		id string,
		identity *auth.Identity,
		backends []*vmcp.Backend,
	) (MultiSession, error)

	// RestoreSession reconstructs a live MultiSession from persisted metadata.
	// It reconnects to the backends whose IDs are listed in storedMetadata under
	// MetadataKeyBackendIDs, rebuilds the routing table, and reapplies the
	// session-binding decorator from the stored identity binding.
	//
	// Use this when the node-local session cache misses — for example after a
	// pod restart or when a request is routed to a different pod. It is more
	// expensive than a cache hit because it opens new backend connections.
	// Because MCP clients cannot be serialised, sticky sessions (session affinity
	// at the load balancer) minimise how often this path is taken.
	//
	// allBackends is the current backend list from the registry; RestoreSession
	// filters it to the subset originally included in this session.
	RestoreSession(
		ctx context.Context,
		id string,
		storedMetadata map[string]string,
		allBackends []*vmcp.Backend,
	) (MultiSession, error)
}

MultiSessionFactory creates new MultiSessions for connecting clients.

func NewDecoratingFactory added in v0.12.5

func NewDecoratingFactory(base MultiSessionFactory, decorators ...Decorator) MultiSessionFactory

NewDecoratingFactory wraps base, applying decorators in order after each MakeSessionWithID. If no decorators are provided, base is returned unchanged.

func NewSessionFactory added in v0.10.1

NewSessionFactory creates a MultiSessionFactory that connects to backends over HTTP using the given outgoing auth registry.

type MultiSessionFactoryOption added in v0.10.1

type MultiSessionFactoryOption func(*defaultMultiSessionFactory)

MultiSessionFactoryOption configures a defaultMultiSessionFactory.

func WithAggregator added in v0.12.0

WithAggregator configures the factory to apply per-backend tool overrides, conflict resolution, and advertising filters when building sessions. If not set, raw backend tool names are used unchanged.

func WithBackendInitTimeout added in v0.10.1

func WithBackendInitTimeout(d time.Duration) MultiSessionFactoryOption

WithBackendInitTimeout sets the per-backend timeout during MakeSession. Defaults to 30 s.

func WithMaxBackendInitConcurrency added in v0.10.1

func WithMaxBackendInitConcurrency(n int) MultiSessionFactoryOption

WithMaxBackendInitConcurrency sets the maximum number of backends that are initialised concurrently during MakeSession. Defaults to 10.

Directories

Path Synopsis
Package binding is the single owner of the identity-binding format used by vMCP session storage.
Package binding is the single owner of the identity-binding format used by vMCP session storage.
internal
backend
Package backend defines the Session interface for a single persistent backend connection and provides the HTTP-based implementation used in production.
Package backend defines the Session interface for a single persistent backend connection and provides the HTTP-based implementation used in production.
security
Package security provides the session-hijack-prevention decorator for vMCP sessions.
Package security provides the session-hijack-prevention decorator for vMCP sessions.
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
Package optimizerdec provides a MultiSession decorator that replaces the full tool list with two optimizer tools: find_tool and call_tool.
Package optimizerdec provides a MultiSession decorator that replaces the full tool list with two optimizer tools: find_tool and call_tool.
Package types defines shared session interfaces for the vmcp/session package hierarchy.
Package types defines shared session interfaces for the vmcp/session package hierarchy.
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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