reqcontext

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RequestIDHeader is the HTTP header name for request IDs
	RequestIDHeader = "X-Request-Id"

	// MaxRequestIDLength is the maximum allowed length for a request ID
	MaxRequestIDLength = 256
)

Variables

This section is empty.

Functions

func GenerateCorrelationID

func GenerateCorrelationID() string

GenerateCorrelationID generates a new unique correlation ID

func GenerateRequestID

func GenerateRequestID() string

GenerateRequestID generates a new UUID v4 request ID

func GetCorrelationID

func GetCorrelationID(ctx context.Context) string

GetCorrelationID retrieves the correlation ID from context

func GetOrGenerateRequestID

func GetOrGenerateRequestID(providedID string) string

GetOrGenerateRequestID returns the provided ID if valid, otherwise generates a new one. This is the main entry point for request ID handling in middleware.

func GetRequestID

func GetRequestID(ctx context.Context) string

GetRequestID retrieves the request ID from context

func IsValidRequestID

func IsValidRequestID(id string) bool

IsValidRequestID checks if a request ID matches the allowed pattern. Valid IDs contain only alphanumeric characters, dashes, and underscores, and are between 1 and 256 characters long.

func ToolResultEnvelope added in v0.72.0

func ToolResultEnvelope(ctx context.Context) bool

func WithCorrelationID

func WithCorrelationID(ctx context.Context, correlationID string) context.Context

WithCorrelationID adds a correlation ID to the context

func WithMetadata

func WithMetadata(ctx context.Context, source RequestSource) context.Context

WithMetadata adds both correlation ID and request source to context

func WithRequestID

func WithRequestID(ctx context.Context, requestID string) context.Context

WithRequestID adds a request ID to the context

func WithRequestMeta added in v0.68.0

func WithRequestMeta(ctx context.Context, meta RequestMeta) context.Context

WithRequestMeta stores meta on the context.

func WithRequestSource

func WithRequestSource(ctx context.Context, source RequestSource) context.Context

WithRequestSource adds request source to the context

func WithToolResultEnvelope added in v0.72.0

func WithToolResultEnvelope(ctx context.Context) context.Context

WithToolResultEnvelope opts a REST tool call into the full MCP result shape.

Types

type ContextKey

type ContextKey string

ContextKey is the type for context keys to avoid collisions

const (
	// CorrelationIDKey is the context key for correlation IDs
	CorrelationIDKey ContextKey = "correlation_id"

	// RequestSourceKey is the context key for request source
	RequestSourceKey ContextKey = "request_source"

	// RequestIDKey is the context key for request IDs (X-Request-Id header)
	RequestIDKey ContextKey = "request_id"

	// LoggerKey is the context key for request-scoped logger
	LoggerKey ContextKey = "logger"
)
const RequestMetaKey ContextKey = "request_meta"

RequestMetaKey is the context key for RequestMeta.

type Mount added in v0.68.0

type Mount string

Mount names the HTTP mount a request entered through. It is fixed by the mount point (Spec 107 T050), never by a header.

const (
	// MountMCP is the /mcp* family (the MCP proxy surface).
	MountMCP Mount = "mcp"
	// MountAPI is the /api/v1 group and /events (the REST API).
	MountAPI Mount = "api"
)

type RequestMeta added in v0.68.0

type RequestMeta struct {
	ClientIP string
	Mount    Mount
}

RequestMeta is the per-request metadata the audit line needs (Spec 107 PR-D): the client IP as resolved through the trusted-proxy rule and the mount the request arrived on. RemoteAddr lives only on *http.Request, so the edition-neutral httpapi middleware stores it here.

func GetRequestMeta added in v0.68.0

func GetRequestMeta(ctx context.Context) (RequestMeta, bool)

GetRequestMeta returns the stored meta and whether one was set.

type RequestSource

type RequestSource string

RequestSource indicates where the request originated

const (
	// SourceRESTAPI indicates request came from HTTP REST API
	SourceRESTAPI RequestSource = "REST_API"

	// SourceCLI indicates request came from CLI command
	SourceCLI RequestSource = "CLI"

	// SourceMCP indicates request came from MCP protocol
	SourceMCP RequestSource = "MCP"

	// SourceInternal indicates internal/background operation
	SourceInternal RequestSource = "INTERNAL"

	// SourceUnknown indicates source could not be determined
	SourceUnknown RequestSource = "UNKNOWN"
)

func GetRequestSource

func GetRequestSource(ctx context.Context) RequestSource

GetRequestSource retrieves the request source from context

Jump to

Keyboard shortcuts

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