Documentation
¶
Index ¶
- type BFFAuthCookie
- type BFFCookie
- type Handler
- type Option
- func WithAuthStore(store auth.Store) Option
- func WithBFFAuthCookie(c *BFFAuthCookie) Option
- func WithBFFAuthCookieUseTopDomain(v bool) Option
- func WithBFFCookieSession(c *BFFCookie) Option
- func WithBFFCookieUseTopDomain(v bool) Option
- func WithCORSAllowCredentials(v bool) Option
- func WithCORSAllowedOrigins(origins []string) Option
- func WithCleanupInterval(d time.Duration) Option
- func WithIdleTTL(d time.Duration) Option
- func WithKeepAliveInterval(d time.Duration) Option
- func WithLogoutAllPath(path string) Option
- func WithMaxEventBuffer(n int) Option
- func WithMaxLifetime(d time.Duration) Option
- func WithOnSessionClose(fn func(*base.Session)) Option
- func WithOverflowPolicy(p base.OverflowPolicy) Option
- func WithReconnectGrace(d time.Duration) Option
- func WithRehydrateOnHandshake(v bool) Option
- func WithRemovalPolicy(p base.RemovalPolicy) Option
- func WithSessionLocation(loc *session.Location) Option
- func WithSessionStore(store base.SessionStore) Option
- func WithURI(uri string) Option
- type Options
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
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
WithBFFAuthCookieUseTopDomain enables auto Domain=eTLD+1 for the auth cookie when Domain is empty.
func WithBFFCookieSession ¶ added in v0.15.0
WithBFFCookieSession enables cookie-based session id for BFF deployments.
func WithBFFCookieUseTopDomain ¶ added in v0.15.0
WithBFFCookieUseTopDomain enables auto setting cookie Domain to eTLD+1 derived from request host.
func WithCORSAllowCredentials ¶ added in v0.15.0
WithCORSAllowCredentials toggles Access-Control-Allow-Credentials and credentialed requests.
func WithCORSAllowedOrigins ¶ added in v0.15.0
WithCORSAllowedOrigins sets the allowed origins for CORS (must not be "*" when AllowCredentials is true).
func WithCleanupInterval ¶ added in v0.15.0
WithCleanupInterval sets how often the cleanup sweeper runs.
func WithIdleTTL ¶ added in v0.15.0
WithIdleTTL sets the idle timeout for sessions.
func WithKeepAliveInterval ¶ added in v0.16.2
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
WithLogoutAllPath sets an optional path to revoke the BFF auth grant (logout all sessions).
func WithMaxEventBuffer ¶ added in v0.15.0
WithMaxEventBuffer sets the default event buffer size used for resumability.
func WithMaxLifetime ¶ added in v0.15.0
WithMaxLifetime sets the hard cap on session lifetime.
func WithOnSessionClose ¶ added in v0.15.0
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
WithReconnectGrace sets the grace period during which a detached session is kept for reconnection.
func WithRehydrateOnHandshake ¶ added in v0.15.0
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 ¶
WithSessionLocation overrides default session location.
func WithSessionStore ¶ added in v0.15.0
func WithSessionStore(store base.SessionStore) Option
WithSessionStore injects a custom SessionStore implementation.
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.