Documentation
¶
Index ¶
- Constants
- Variables
- type CleanupHook
- type Config
- type KiteConnect
- type KiteSessionData
- type MCPSession
- type Manager
- func (m *Manager) CleanupExpiredSessions() int
- func (m *Manager) ClearSession(sessionID string)
- func (m *Manager) ClearSessionData(sessionID string) error
- func (m *Manager) CompleteSession(mcpSessionID, kiteRequestToken string) error
- func (m *Manager) ForceInstrumentsUpdate() error
- func (m *Manager) GenerateSession() string
- func (m *Manager) GetActiveSessionCount() int
- func (m *Manager) GetInstrumentsStats() instruments.UpdateStats
- func (m *Manager) GetOrCreateSession(mcpSessionID string) (*KiteSessionData, bool, error)
- func (m *Manager) GetSession(mcpSessionID string) (*KiteSessionData, error)
- func (m *Manager) HandleKiteCallback() func(w http.ResponseWriter, r *http.Request)
- func (m *Manager) SessionLoginURL(mcpSessionID string) (string, error)
- func (m *Manager) SessionManager() *SessionRegistry
- func (m *Manager) SessionSigner() *SessionSigner
- func (m *Manager) Shutdown()
- func (m *Manager) StopCleanupRoutine()
- func (m *Manager) UpdateInstrumentsConfig(config *instruments.UpdateConfig)
- func (m *Manager) UpdateSessionSignerExpiry(duration time.Duration)
- type SessionRegistry
- func (sm *SessionRegistry) AddCleanupHook(hook CleanupHook)
- func (sm *SessionRegistry) CleanupExpiredSessions() int
- func (sm *SessionRegistry) Generate() string
- func (sm *SessionRegistry) GenerateWithData(data any) string
- func (sm *SessionRegistry) GetOrCreateSessionData(sessionID string, createDataFn func() any) (data any, isNew bool, err error)
- func (sm *SessionRegistry) GetSession(sessionID string) (*MCPSession, error)
- func (sm *SessionRegistry) GetSessionData(sessionID string) (any, error)
- func (sm *SessionRegistry) GetSessionDuration() time.Duration
- func (sm *SessionRegistry) ListActiveSessions() []*MCPSession
- func (sm *SessionRegistry) SetSessionDuration(duration time.Duration)
- func (sm *SessionRegistry) StartCleanupRoutine(ctx context.Context)
- func (sm *SessionRegistry) StopCleanupRoutine()
- func (sm *SessionRegistry) Terminate(sessionID string) (isNotAllowed bool, err error)
- func (sm *SessionRegistry) UpdateSessionData(sessionID string, data any) error
- func (sm *SessionRegistry) Validate(sessionID string) (isTerminated bool, err error)
- type SessionSigner
- func (s *SessionSigner) GetSecretKey() []byte
- func (s *SessionSigner) SetSignatureExpiry(duration time.Duration)
- func (s *SessionSigner) SignRedirectParams(sessionID string) (string, error)
- func (s *SessionSigner) SignSessionID(sessionID string) string
- func (s *SessionSigner) ValidateSessionID(sessionID string) error
- func (s *SessionSigner) VerifyRedirectParams(redirectParams string) (string, error)
- func (s *SessionSigner) VerifySessionID(signedParam string) (string, error)
- type TemplateData
Constants ¶
const ( // Default session configuration DefaultSessionDuration = 12 * time.Hour DefaultCleanupInterval = 30 * time.Minute )
const ( // Default expiry for signed session parameters (30 minutes) DefaultSignatureExpiry = 30 * time.Minute // Maximum allowed clock skew for signature validation MaxClockSkew = 5 * time.Minute )
Variables ¶
var ( ErrSessionNotFound = errors.New("MCP session not found or Kite session not associated, try to login again") ErrInvalidSessionID = errors.New("invalid MCP session ID, please try logging in again") )
Functions ¶
This section is empty.
Types ¶
type CleanupHook ¶
type CleanupHook func(session *MCPSession)
CleanupHook is called when a session is terminated or expires
type Config ¶
type Config struct {
APIKey string // required
APISecret string // required
Logger *slog.Logger // required
InstrumentsConfig *instruments.UpdateConfig // optional - defaults to instruments.DefaultUpdateConfig()
InstrumentsManager *instruments.Manager // optional - if provided, skips creating new instruments manager
SessionSigner *SessionSigner // optional - if nil, creates new session signer
}
Config holds configuration for creating a new kc Manager
type KiteConnect ¶
type KiteConnect struct {
// Add fields here
Client *kiteconnect.Client // TODO: this can be made private ?
}
KiteConnect wraps the Kite Connect client
func NewKiteConnect ¶
func NewKiteConnect(apiKey string) *KiteConnect
NewKiteConnect creates a new KiteConnect instance
type KiteSessionData ¶
type KiteSessionData struct {
Kite *KiteConnect
}
type MCPSession ¶
type Manager ¶
type Manager struct {
Logger *slog.Logger
Instruments *instruments.Manager
// contains filtered or unexported fields
}
func NewManager ¶
NewManager creates a new manager with default configuration Deprecated: Use New(Config{APIKey: apiKey, APISecret: apiSecret, Logger: logger}) instead
func (*Manager) CleanupExpiredSessions ¶
CleanupExpiredSessions manually triggers cleanup of expired MCP sessions
func (*Manager) ClearSession ¶
func (*Manager) ClearSessionData ¶
ClearSessionData clears the session data without terminating the session
func (*Manager) CompleteSession ¶
func (*Manager) ForceInstrumentsUpdate ¶
ForceInstrumentsUpdate forces an immediate instruments update
func (*Manager) GenerateSession ¶
GenerateSession creates a new MCP session with Kite data and returns the session ID
func (*Manager) GetActiveSessionCount ¶
GetActiveSessionCount returns the number of active sessions
func (*Manager) GetInstrumentsStats ¶
func (m *Manager) GetInstrumentsStats() instruments.UpdateStats
GetInstrumentsStats returns current instruments update statistics
func (*Manager) GetOrCreateSession ¶
func (m *Manager) GetOrCreateSession(mcpSessionID string) (*KiteSessionData, bool, error)
GetOrCreateSession retrieves an existing Kite session or creates a new one atomically
func (*Manager) GetSession ¶
func (m *Manager) GetSession(mcpSessionID string) (*KiteSessionData, error)
func (*Manager) HandleKiteCallback ¶
func (m *Manager) HandleKiteCallback() func(w http.ResponseWriter, r *http.Request)
HandleKiteCallback returns an HTTP handler for Kite authentication callbacks
func (*Manager) SessionLoginURL ¶
func (*Manager) SessionManager ¶
func (m *Manager) SessionManager() *SessionRegistry
SessionManager returns the MCP session manager instance
func (*Manager) SessionSigner ¶
func (m *Manager) SessionSigner() *SessionSigner
SessionSigner returns the session signer instance
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown gracefully shuts down the manager and all its components
func (*Manager) StopCleanupRoutine ¶
func (m *Manager) StopCleanupRoutine()
StopCleanupRoutine stops the background cleanup routine
func (*Manager) UpdateInstrumentsConfig ¶
func (m *Manager) UpdateInstrumentsConfig(config *instruments.UpdateConfig)
UpdateInstrumentsConfig updates the instruments manager configuration
func (*Manager) UpdateSessionSignerExpiry ¶
UpdateSessionSignerExpiry updates the signature expiry duration
type SessionRegistry ¶
type SessionRegistry struct {
// contains filtered or unexported fields
}
func NewSessionRegistry ¶
func NewSessionRegistry(logger *slog.Logger) *SessionRegistry
NewSessionRegistry creates a new registry that manages MCP sessions and their associated Kite data
func NewSessionRegistryWithDuration ¶
func NewSessionRegistryWithDuration(duration time.Duration, logger *slog.Logger) *SessionRegistry
NewSessionRegistryWithDuration creates a new session registry with custom duration
func (*SessionRegistry) AddCleanupHook ¶
func (sm *SessionRegistry) AddCleanupHook(hook CleanupHook)
AddCleanupHook adds a cleanup function for the Kite session to be called when MCP sessions are terminated
func (*SessionRegistry) CleanupExpiredSessions ¶
func (sm *SessionRegistry) CleanupExpiredSessions() int
CleanupExpiredSessions removes expired MCP sessions from memory and their associated Kite data
func (*SessionRegistry) Generate ¶
func (sm *SessionRegistry) Generate() string
Generate creates a new MCP session ID and stores it in memory
func (*SessionRegistry) GenerateWithData ¶
func (sm *SessionRegistry) GenerateWithData(data any) string
GenerateWithData creates a new MCP session ID with associated Kite data and stores it in memory
func (*SessionRegistry) GetOrCreateSessionData ¶
func (sm *SessionRegistry) GetOrCreateSessionData(sessionID string, createDataFn func() any) (data any, isNew bool, err error)
GetOrCreateSessionData atomically validates session and retrieves/creates data to eliminate TOCTOU races
func (*SessionRegistry) GetSession ¶
func (sm *SessionRegistry) GetSession(sessionID string) (*MCPSession, error)
GetSession retrieves a MCP session by ID (helper method)
func (*SessionRegistry) GetSessionData ¶
func (sm *SessionRegistry) GetSessionData(sessionID string) (any, error)
GetSessionData retrieves the Kite data for a MCP session
func (*SessionRegistry) GetSessionDuration ¶
func (sm *SessionRegistry) GetSessionDuration() time.Duration
GetSessionDuration returns the configured MCP session duration
func (*SessionRegistry) ListActiveSessions ¶
func (sm *SessionRegistry) ListActiveSessions() []*MCPSession
ListActiveSessions returns all non-terminated MCP sessions (helper method)
func (*SessionRegistry) SetSessionDuration ¶
func (sm *SessionRegistry) SetSessionDuration(duration time.Duration)
SetSessionDuration updates the MCP session duration for new sessions
func (*SessionRegistry) StartCleanupRoutine ¶
func (sm *SessionRegistry) StartCleanupRoutine(ctx context.Context)
StartCleanupRoutine starts background cleanup goroutines for expired MCP sessions
func (*SessionRegistry) StopCleanupRoutine ¶
func (sm *SessionRegistry) StopCleanupRoutine()
StopCleanupRoutine stops background cleanup goroutines for MCP sessions
func (*SessionRegistry) Terminate ¶
func (sm *SessionRegistry) Terminate(sessionID string) (isNotAllowed bool, err error)
Terminate marks a MCP session ID as terminated and cleans up associated Kite session
func (*SessionRegistry) UpdateSessionData ¶
func (sm *SessionRegistry) UpdateSessionData(sessionID string, data any) error
UpdateSessionData updates the Kite data for an existing MCP session
type SessionSigner ¶
type SessionSigner struct {
// contains filtered or unexported fields
}
SessionSigner handles HMAC signing and verification of session parameters
func NewSessionSigner ¶
func NewSessionSigner() (*SessionSigner, error)
NewSessionSigner creates a new session signer with a random secret key
func NewSessionSignerWithKey ¶
func NewSessionSignerWithKey(secretKey []byte) *SessionSigner
NewSessionSignerWithKey creates a new session signer with a provided secret key
func (*SessionSigner) GetSecretKey ¶
func (s *SessionSigner) GetSecretKey() []byte
GetSecretKey returns the secret key (for testing purposes only)
func (*SessionSigner) SetSignatureExpiry ¶
func (s *SessionSigner) SetSignatureExpiry(duration time.Duration)
SetSignatureExpiry sets the expiry duration for signed session parameters
func (*SessionSigner) SignRedirectParams ¶
func (s *SessionSigner) SignRedirectParams(sessionID string) (string, error)
SignRedirectParams creates a signed redirect parameter string for Kite authentication
func (*SessionSigner) SignSessionID ¶
func (s *SessionSigner) SignSessionID(sessionID string) string
SignSessionID creates a signed session parameter with timestamp and HMAC signature
func (*SessionSigner) ValidateSessionID ¶
func (s *SessionSigner) ValidateSessionID(sessionID string) error
ValidateSessionID performs basic validation on a session ID format
func (*SessionSigner) VerifyRedirectParams ¶
func (s *SessionSigner) VerifyRedirectParams(redirectParams string) (string, error)
VerifyRedirectParams verifies signed redirect parameters and extracts the session ID
func (*SessionSigner) VerifySessionID ¶
func (s *SessionSigner) VerifySessionID(signedParam string) (string, error)
VerifySessionID verifies a signed session parameter and extracts the session ID
type TemplateData ¶
type TemplateData struct {
Title string
}
TemplateData holds data for template rendering