feat(mcp): session id store

This commit is contained in:
Mathias Bergqvist
2026-05-04 20:40:53 +02:00
parent abaf5e8b1d
commit cf2017e687
2 changed files with 62 additions and 0 deletions

40
internal/mcp/session.go Normal file
View File

@@ -0,0 +1,40 @@
package mcp
import (
"crypto/rand"
"encoding/hex"
"sync"
)
type SessionStore struct {
mu sync.RWMutex
m map[string]struct{}
}
func NewSessionStore() *SessionStore {
return &SessionStore{m: make(map[string]struct{})}
}
func (s *SessionStore) Issue() string {
b := make([]byte, 16)
_, _ = rand.Read(b)
id := hex.EncodeToString(b)
s.mu.Lock()
s.m[id] = struct{}{}
s.mu.Unlock()
return id
}
func (s *SessionStore) Valid(id string) bool {
s.mu.RLock()
defer s.mu.RUnlock()
_, ok := s.m[id]
return ok
}
func (s *SessionStore) Drop(id string) {
s.mu.Lock()
delete(s.m, id)
s.mu.Unlock()
}