Documentation
¶
Overview ¶
Package session manages user sessions across MCP tool calls.
Index ¶
- Constants
- Variables
- func GenerateSessionID() (string, error)
- type Config
- type Session
- type SessionService
- func (s *SessionService) Create(ctx context.Context, identity *auth.Identity) (*Session, error)
- func (s *SessionService) Delete(ctx context.Context, id string) error
- func (s *SessionService) Get(ctx context.Context, id string) (*Session, error)
- func (s *SessionService) Refresh(ctx context.Context, id string) error
- type SessionStore
Constants ¶
const DefaultTimeout = 30 * time.Minute
DefaultTimeout is the default session timeout.
Variables ¶
var ErrSessionNotFound = errors.New("session not found")
ErrSessionNotFound is returned when a session doesn't exist or is expired.
Functions ¶
func GenerateSessionID ¶
GenerateSessionID creates a cryptographically random session ID. Uses crypto/rand for unpredictability (SESS-05 requirement). Returns 64 hex characters (32 bytes).
Types ¶
type Config ¶
type Config struct {
// Timeout is the session expiration duration. Default: 30 minutes.
Timeout time.Duration
}
Config holds session service configuration.
type Session ¶
type Session struct {
// ID is a cryptographically random identifier, 32 bytes hex-encoded.
ID string
// IdentityID references the auth.Identity this session belongs to.
IdentityID string
// IdentityName is the human-readable name of the identity.
IdentityName string
// Roles are cached from the Identity for fast RBAC lookup.
Roles []auth.Role
// CreatedAt is when the session was created (UTC).
CreatedAt time.Time
// ExpiresAt is when the session will expire (UTC).
ExpiresAt time.Time
// LastAccess is the last time the session was used (UTC).
LastAccess time.Time
}
Session tracks an authenticated user's context across tool calls.
type SessionService ¶
type SessionService struct {
// contains filtered or unexported fields
}
SessionService manages session lifecycle.
func NewSessionService ¶
func NewSessionService(store SessionStore, cfg Config) *SessionService
NewSessionService creates a new SessionService with the given store and config.
func (*SessionService) Delete ¶
func (s *SessionService) Delete(ctx context.Context, id string) error
Delete terminates a session.
type SessionStore ¶
type SessionStore interface {
// Create stores a new session.
Create(ctx context.Context, session *Session) error
// Get retrieves a session by ID.
// Returns ErrSessionNotFound if session doesn't exist or is expired.
Get(ctx context.Context, id string) (*Session, error)
// Update saves changes to an existing session.
Update(ctx context.Context, session *Session) error
// Delete removes a session.
Delete(ctx context.Context, id string) error
}
SessionStore provides session persistence. This interface is defined in the domain to avoid circular imports. Implementations: Redis (prod), in-memory (test).