session

package
v0.1.15-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package session provides context helpers for MCP session management.

Index

Constants

View Source
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

func ExtractBearerToken(r *http.Request) string

ExtractBearerToken extracts JWT token from Authorization header

func GetUserTokenHash

func GetUserTokenHash(ctx context.Context) string

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

func WithUserTokenHash

func WithUserTokenHash(ctx context.Context, hash string) context.Context

WithUserTokenHash adds the hashed user token to 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

Jump to

Keyboard shortcuts

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