Documentation
¶
Index ¶
- Variables
- type Engine
- func (e *Engine) DeleteSession(ctx context.Context, sess *SessionHandle) error
- func (e *Engine) HandleClientResponse(ctx context.Context, sess *SessionHandle, res *jsonrpc.Response) error
- func (e *Engine) HandleNotification(ctx context.Context, sess *SessionHandle, note *jsonrpc.Request) error
- func (e *Engine) HandleRequest(ctx context.Context, sess *SessionHandle, req *jsonrpc.Request) (*jsonrpc.Response, error)
- func (e *Engine) InitializeSession(ctx context.Context, userID string, req *mcp.InitializeRequest) (*SessionHandle, *mcp.InitializeResult, error)
- func (e *Engine) LoadSession(ctx context.Context, sessID, userID string, requestScopedWriter MessageWriter) (*SessionHandle, error)
- func (e *Engine) PublishToSession(ctx context.Context, sessID, userID string, msg jsonrpc.Message) (string, error)
- func (e *Engine) Run(ctx context.Context) error
- func (e *Engine) StreamSession(ctx context.Context, sess *SessionHandle, lastEventID string, ...) error
- type EngineOption
- type MessageWriter
- type MessageWriterFunc
- type SessionHandle
- func (s *SessionHandle) DeleteData(ctx context.Context, key string) error
- func (s *SessionHandle) GetData(ctx context.Context, key string) ([]byte, bool, error)
- func (s *SessionHandle) GetElicitationCapability() (cap sessions.ElicitationCapability, ok bool)
- func (s *SessionHandle) GetRootsCapability() (cap sessions.RootsCapability, ok bool)
- func (s *SessionHandle) GetSamplingCapability() (cap sessions.SamplingCapability, ok bool)
- func (s *SessionHandle) ProtocolVersion() string
- func (s *SessionHandle) PutData(ctx context.Context, key string, value []byte) error
- func (s *SessionHandle) SessionID() string
- func (s *SessionHandle) State() sessions.SessionState
- func (s *SessionHandle) UserID() string
- type SessionHandleOption
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is the core of an MCP server, coordinating sessions, message routing, and protocol handling. It is protocol-agnostic and can be used with different transport layers (e.g., HTTP, stdio) by implementing the necessary session host and I/O handlers.
func NewEngine ¶
func NewEngine(host sessions.SessionHost, srv mcpservice.ServerCapabilities, opts ...EngineOption) *Engine
func (*Engine) DeleteSession ¶
func (e *Engine) DeleteSession(ctx context.Context, sess *SessionHandle) error
DeleteSession validates ownership, returns the session protocol version for convenience, and deletes the session from the host. Idempotent at the host layer; returns ErrSessionNotFound if not owned or already gone.
func (*Engine) HandleClientResponse ¶
func (e *Engine) HandleClientResponse(ctx context.Context, sess *SessionHandle, res *jsonrpc.Response) error
HandleClientResponse validates the session ownership and forwards a client JSON-RPC response into the Engine rendezvous via the inter-instance fanout. This allows any node to satisfy the waiting request, regardless of where the response was received.
func (*Engine) HandleNotification ¶
func (e *Engine) HandleNotification(ctx context.Context, sess *SessionHandle, note *jsonrpc.Request) error
HandleNotification processes an incoming JSON-RPC notification from a client. It verifies the session and republishes the notification to all instances without actually handling the notification itself. The actual handling is done in the consumer loop for these messages.
func (*Engine) HandleRequest ¶
func (*Engine) InitializeSession ¶
func (e *Engine) InitializeSession(ctx context.Context, userID string, req *mcp.InitializeRequest) (*SessionHandle, *mcp.InitializeResult, error)
InitializeSession handles the MCP initialize handshake, creating a session record, wiring negotiated capabilities, and returning the InitializeResult payload alongside a session handle for subsequent requests.
func (*Engine) LoadSession ¶ added in v0.7.4
func (e *Engine) LoadSession(ctx context.Context, sessID, userID string, requestScopedWriter MessageWriter) (*SessionHandle, error)
LoadSession retrieves and validates session metadata, returning a handle. It verifies the session belongs to the specified user and is not revoked. It also performs a best-effort TTL touch. If a writers are provided, it sets up capabilities according to the session's negotiated capabilities and leverages the relevant writers for outbound messages.
func (*Engine) PublishToSession ¶
func (e *Engine) PublishToSession(ctx context.Context, sessID, userID string, msg jsonrpc.Message) (string, error)
PublishToSession validates ownership and appends a JSON-RPC message to the per-session client-facing stream. Returns the assigned event ID.
func (*Engine) StreamSession ¶
func (e *Engine) StreamSession(ctx context.Context, sess *SessionHandle, lastEventID string, handler sessions.MessageHandlerFunction) error
StreamSession validates the session ownership and subscribes the caller to the per-session client-facing stream starting after lastEventID. It is a thin wrapper over the host that centralizes auth/ownership checks in the Engine.
type EngineOption ¶
type EngineOption func(*Engine)
EngineOption configures a Engine.
func WithHandshakeTTL ¶
func WithHandshakeTTL(d time.Duration) EngineOption
WithHandshakeTTL sets the TTL for a pending session awaiting the client's notifications/initialized message. Default is 30s.
func WithLogger ¶
func WithLogger(l *slog.Logger) EngineOption
WithLogger sets a custom logger for the Engine.
func WithSessionMaxLifetime ¶
func WithSessionMaxLifetime(d time.Duration) EngineOption
WithSessionMaxLifetime sets an absolute maximum lifetime horizon (0 = disabled).
func WithSessionTTL ¶
func WithSessionTTL(d time.Duration) EngineOption
WithSessionTTL overrides the sliding TTL used for sessions.
type MessageWriter ¶
type SessionHandle ¶
type SessionHandle struct {
// contains filtered or unexported fields
}
func NewSessionHandle ¶
func NewSessionHandle(host sessions.SessionHost, meta *sessions.SessionMetadata, opts ...SessionHandleOption) *SessionHandle
func (*SessionHandle) DeleteData ¶ added in v0.7.2
func (s *SessionHandle) DeleteData(ctx context.Context, key string) error
DeleteData removes the key (idempotent).
func (*SessionHandle) GetData ¶ added in v0.7.2
GetData retrieves raw bytes for this session key. Returns ok=false if absent.
func (*SessionHandle) GetElicitationCapability ¶
func (s *SessionHandle) GetElicitationCapability() (cap sessions.ElicitationCapability, ok bool)
func (*SessionHandle) GetRootsCapability ¶
func (s *SessionHandle) GetRootsCapability() (cap sessions.RootsCapability, ok bool)
func (*SessionHandle) GetSamplingCapability ¶
func (s *SessionHandle) GetSamplingCapability() (cap sessions.SamplingCapability, ok bool)
func (*SessionHandle) ProtocolVersion ¶
func (s *SessionHandle) ProtocolVersion() string
func (*SessionHandle) PutData ¶ added in v0.7.2
PutData stores raw bytes for this session key via the SessionHost.
func (*SessionHandle) SessionID ¶
func (s *SessionHandle) SessionID() string
func (*SessionHandle) State ¶
func (s *SessionHandle) State() sessions.SessionState
func (*SessionHandle) UserID ¶
func (s *SessionHandle) UserID() string
type SessionHandleOption ¶
type SessionHandleOption func(*SessionHandle)
func WithElicitationCapability ¶
func WithElicitationCapability(cap sessions.ElicitationCapability) SessionHandleOption
func WithRootsCapability ¶
func WithRootsCapability(cap sessions.RootsCapability) SessionHandleOption
func WithSamplingCapability ¶
func WithSamplingCapability(cap sessions.SamplingCapability) SessionHandleOption