Documentation
¶
Overview ¶
Package session provides context helpers for MCP session management.
Index ¶
- Constants
- func ExtractBearerToken(r *http.Request) string
- func GetUserTokenHash(ctx context.Context) string
- func WithPulsarSessionManager(ctx context.Context, manager *PulsarSessionManager) context.Context
- func WithUserTokenHash(ctx context.Context, hash string) context.Context
- type CachedSession
- type PulsarSessionManager
- type PulsarSessionManagerConfig
Constants ¶
const ( // PulsarSessionManagerKey is used to store the session manager in context PulsarSessionManagerKey contextKey = "pulsar_session_manager" // UserTokenHashKey stores the user's JWT token hash for debugging UserTokenHashKey contextKey = "user_token_hash" )
Variables ¶
This section is empty.
Functions ¶
func ExtractBearerToken ¶
ExtractBearerToken extracts JWT token from Authorization header
func GetUserTokenHash ¶
GetUserTokenHash retrieves the hashed user token from context
func WithPulsarSessionManager ¶
func WithPulsarSessionManager(ctx context.Context, manager *PulsarSessionManager) context.Context
WithPulsarSessionManager adds the session manager to the context
Types ¶
type CachedSession ¶
type CachedSession struct {
Session *pulsar.Session
TokenHash string
LastAccess time.Time
CreatedAt time.Time
// contains filtered or unexported fields
}
CachedSession wraps a Pulsar session with metadata
type PulsarSessionManager ¶
type PulsarSessionManager struct {
// contains filtered or unexported fields
}
PulsarSessionManager manages per-user Pulsar sessions with LRU eviction
func GetPulsarSessionManager ¶
func GetPulsarSessionManager(ctx context.Context) *PulsarSessionManager
GetPulsarSessionManager retrieves the session manager from context
func NewPulsarSessionManager ¶
func NewPulsarSessionManager( config *PulsarSessionManagerConfig, globalSession *pulsar.Session, logger *logrus.Logger, ) *PulsarSessionManager
NewPulsarSessionManager creates a new session manager
func (*PulsarSessionManager) GetOrCreateSession ¶
func (m *PulsarSessionManager) GetOrCreateSession(_ context.Context, token string) (*pulsar.Session, error)
GetOrCreateSession retrieves or creates a Pulsar session for the given token
func (*PulsarSessionManager) HashTokenForLog ¶
func (m *PulsarSessionManager) HashTokenForLog(token string) string
HashTokenForLog returns a short hash prefix for logging
func (*PulsarSessionManager) SessionCount ¶
func (m *PulsarSessionManager) SessionCount() int
SessionCount returns the current number of cached sessions
func (*PulsarSessionManager) Stop ¶
func (m *PulsarSessionManager) Stop()
Stop stops the session manager and cleans up all sessions
type PulsarSessionManagerConfig ¶
type PulsarSessionManagerConfig struct {
// MaxSessions is the maximum number of sessions to keep in the cache
MaxSessions int
// SessionTTL is how long a session can remain idle before eviction
SessionTTL time.Duration
// CleanupInterval is how often to run the cleanup goroutine
CleanupInterval time.Duration
// BaseContext provides default Pulsar connection parameters (without token)
BaseContext pulsar.PulsarContext
}
PulsarSessionManagerConfig holds configuration for the session manager
func DefaultPulsarSessionManagerConfig ¶
func DefaultPulsarSessionManagerConfig() *PulsarSessionManagerConfig
DefaultPulsarSessionManagerConfig returns sensible defaults