Help us shape the future of Go! Take the 2026 Go Developer Survey

middleware

package
v0.91.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const MCPSessionIDHeader = "Mcp-Session-Id"

MCPSessionIDHeader is the header MCP clients use to carry a session ID. The MCP spec requires a client that receives it to send it on all its subsequent requests.

Variables

This section is empty.

Functions

func ActivityHTTPMiddleware added in v0.88.0

func ActivityHTTPMiddleware(activityClient *activity.Client, source runtime.RequestSource) func(http.Handler) http.Handler

ActivityHTTPMiddleware emits the request_time_ms usage metric for HTTP API requests that don't pass through the gRPC interceptor (e.g. the custom REST API and MCP). Together with the gRPC interceptors this gives one request event per API call across all surfaces, tagged with the given source. Billing logic (which sources count, distinct embedded users, etc.) is applied downstream in the metrics project.

func ActivityStreamServerInterceptor added in v0.31.0

func ActivityStreamServerInterceptor(activityClient *activity.Client) grpc.StreamServerInterceptor

func ActivityUnaryServerInterceptor added in v0.31.0

func ActivityUnaryServerInterceptor(activityClient *activity.Client) grpc.UnaryServerInterceptor

func CacheControlMiddleware added in v0.86.1

func CacheControlMiddleware(next http.Handler) http.Handler

CacheControlMiddleware sets a default Cache-Control header of "no-store, no-cache, must-revalidate". Handlers that need different caching behavior (e.g. static assets) can override it by calling w.Header().Set("Cache-Control", ...) before their first write.

func Check added in v0.42.0

func Check(checkFn CheckFunc, next http.Handler) httputil.Handler

Check is a middleware that only calls the next handler if the checkFn succeeds. If the checkFn fails, the error is written to the response as per the behavior of httputil.Handler.

func MCPSessionIDMiddleware

func MCPSessionIDMiddleware(next http.Handler) http.Handler

MCPSessionIDMiddleware issues and preserves the Mcp-Session-Id header for a stateless MCP server. Since go-sdk v1.8, a stateless streamable HTTP handler neither reads nor sets the header, since the MCP spec is moving to sessionless servers (see SEP-2567). Rill nonetheless keys its AI sessions on the header, so that all the requests of one client connection share a session. A request without the header gets a new session ID, which is set on the request for the wrapped handler to read, and every response carries the session ID the request was served with. A request with a malformed session ID is rejected: the spec restricts session IDs to visible ASCII, and the length bound protects the catalog, which stores the ID as the AI session's ID.

func TimeoutMCPMiddleware added in v0.78.0

func TimeoutMCPMiddleware(fn func(method, tool string) time.Duration) mcp.Middleware

func TimeoutStreamServerInterceptor

func TimeoutStreamServerInterceptor(fn func(method string) time.Duration) grpc.StreamServerInterceptor

func TimeoutUnaryServerInterceptor

func TimeoutUnaryServerInterceptor(fn func(method string) time.Duration) grpc.UnaryServerInterceptor

func TraceMiddleware added in v0.78.0

func TraceMiddleware(next http.Handler) http.Handler

traceMiddleware adds trace ID headers to the response if a trace is in progress

Types

type CheckFunc added in v0.42.0

type CheckFunc func(req *http.Request) error

Jump to

Keyboard shortcuts

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