streamable

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BFFAuthCookie added in v0.15.0

type BFFAuthCookie struct {
	Name     string
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
	SameSite http.SameSite
	MaxAge   int
}

BFFAuthCookie defines cookie attributes for the BFF auth session (opaque grant id).

type BFFCookie added in v0.15.0

type BFFCookie struct {
	Name     string
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
	SameSite http.SameSite
	MaxAge   int
}

BFFCookie defines cookie attributes used to carry the session id.

type Handler

type Handler struct {
	Options
	// contains filtered or unexported fields
}

Handler implements server-side of Streamable-HTTP transport (Model Context Protocol). Single endpoint (URI) is used for handshake, message exchange and streaming. Operation mode is distinguished by HTTP method and Accept header value.

func New

func New(newHandler transport.NewHandler, opts ...Option) *Handler

New constructs Handler with default settings and provided options.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler. POST (no session header) – handshake creates a session, returns session id in header. POST (with Mcp-Session-Id) – JSON-RPC message for the session; response returned sync. GET (with Accept: text/event-stream & Mcp-Session-Id) – opens long-lived streaming connection. DELETE (with Mcp-Session-Id) – terminates session.

type Option

type Option func(*Options)

Option mutates Options.

func WithAuthStore added in v0.15.0

func WithAuthStore(store auth.Store) Option

WithAuthStore configures the durable store for BFF auth grants.

func WithBFFAuthCookie added in v0.15.0

func WithBFFAuthCookie(c *BFFAuthCookie) Option

WithBFFAuthCookie configures the cookie used to carry the BFF auth grant id.

func WithBFFAuthCookieUseTopDomain added in v0.15.0

func WithBFFAuthCookieUseTopDomain(v bool) Option

WithBFFAuthCookieUseTopDomain enables auto Domain=eTLD+1 for the auth cookie when Domain is empty.

func WithBFFCookieSession added in v0.15.0

func WithBFFCookieSession(c *BFFCookie) Option

WithBFFCookieSession enables cookie-based session id for BFF deployments.

func WithBFFCookieUseTopDomain added in v0.15.0

func WithBFFCookieUseTopDomain(v bool) Option

WithBFFCookieUseTopDomain enables auto setting cookie Domain to eTLD+1 derived from request host.

func WithCORSAllowCredentials added in v0.15.0

func WithCORSAllowCredentials(v bool) Option

WithCORSAllowCredentials toggles Access-Control-Allow-Credentials and credentialed requests.

func WithCORSAllowedOrigins added in v0.15.0

func WithCORSAllowedOrigins(origins []string) Option

WithCORSAllowedOrigins sets the allowed origins for CORS (must not be "*" when AllowCredentials is true).

func WithCleanupInterval added in v0.15.0

func WithCleanupInterval(d time.Duration) Option

WithCleanupInterval sets how often the cleanup sweeper runs.

func WithIdleTTL added in v0.15.0

func WithIdleTTL(d time.Duration) Option

WithIdleTTL sets the idle timeout for sessions.

func WithKeepAliveInterval added in v0.16.2

func WithKeepAliveInterval(d time.Duration) Option

WithKeepAliveInterval sets the interval for SSE keepalive frames on the GET stream. Set to 0 or negative to disable.

func WithLogoutAllPath added in v0.15.0

func WithLogoutAllPath(path string) Option

WithLogoutAllPath sets an optional path to revoke the BFF auth grant (logout all sessions).

func WithMaxEventBuffer added in v0.15.0

func WithMaxEventBuffer(n int) Option

WithMaxEventBuffer sets the default event buffer size used for resumability.

func WithMaxLifetime added in v0.15.0

func WithMaxLifetime(d time.Duration) Option

WithMaxLifetime sets the hard cap on session lifetime.

func WithOnSessionClose added in v0.15.0

func WithOnSessionClose(fn func(*base.Session)) Option

WithOnSessionClose registers a hook invoked when a session is finally closed.

func WithOverflowPolicy added in v0.15.0

func WithOverflowPolicy(p base.OverflowPolicy) Option

WithOverflowPolicy sets the event buffer overflow policy.

func WithReconnectGrace added in v0.15.0

func WithReconnectGrace(d time.Duration) Option

WithReconnectGrace sets the grace period during which a detached session is kept for reconnection.

func WithRehydrateOnHandshake added in v0.15.0

func WithRehydrateOnHandshake(v bool) Option

WithRehydrateOnHandshake toggles using the auth cookie to mint a new MCP session when no session id is provided.

func WithRemovalPolicy added in v0.15.0

func WithRemovalPolicy(p base.RemovalPolicy) Option

WithRemovalPolicy sets the session removal policy.

func WithSessionLocation

func WithSessionLocation(loc *session.Location) Option

WithSessionLocation overrides default session location.

func WithSessionStore added in v0.15.0

func WithSessionStore(store base.SessionStore) Option

WithSessionStore injects a custom SessionStore implementation.

func WithURI

func WithURI(uri string) Option

WithURI sets custom URI.

type Options

type Options struct {
	// URI of the endpoint (configurable; empty matches any path when handler is mounted on a specific route)
	URI string

	// SessionLocation defines where session id is transported (header or query param)
	SessionLocation *session.Location

	// Lifecycle controls
	ReconnectGrace  time.Duration
	IdleTTL         time.Duration
	MaxLifetime     time.Duration
	CleanupInterval time.Duration
	MaxEventBuffer  int
	OnSessionClose  func(*base.Session)
	RemovalPolicy   base.RemovalPolicy
	OverflowPolicy  base.OverflowPolicy
	// Optional custom session store (e.g., Redis-backed). Defaults to in-memory.
	Store base.SessionStore

	// BFF cookie-based session id (optional, disabled by default)
	CookieSession *BFFCookie
	// CORS settings for browsers
	AllowedOrigins   []string
	AllowCredentials bool

	// If true and CookieSession.Domain is empty, set cookie Domain to the request's top domain (eTLD+1).
	CookieUseTopDomain bool

	// BFF auth (server-held) grant
	AuthStore              auth.Store
	AuthCookie             *BFFAuthCookie
	AuthCookieUseTopDomain bool
	RehydrateOnHandshake   bool
	LogoutAllPath          string

	// KeepAliveInterval controls emission of SSE keepalive frames on the
	// long-lived GET stream. Zero or negative disables keepalives.
	KeepAliveInterval time.Duration
}

Options exposes configurable attributes of the handler.

Jump to

Keyboard shortcuts

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