Documentation
¶
Index ¶
- Constants
- func AttemptID(ctx context.Context) string
- func ClientSurface(ctx context.Context) string
- func GenerateCorrelationID() string
- func GenerateRequestID() string
- func GetCorrelationID(ctx context.Context) string
- func GetOrGenerateRequestID(providedID string) string
- func GetRequestID(ctx context.Context) string
- func IsValidRequestID(id string) bool
- func RunHeader(ctx context.Context) (string, bool)
- func ToolResultEnvelope(ctx context.Context) bool
- func ValidRunName(s string) bool
- func WithAttemptID(ctx context.Context, id string) context.Context
- func WithClientSurface(ctx context.Context, surface string) context.Context
- func WithCorrelationID(ctx context.Context, correlationID string) context.Context
- func WithMetadata(ctx context.Context, source RequestSource) context.Context
- func WithRequestID(ctx context.Context, requestID string) context.Context
- func WithRequestMeta(ctx context.Context, meta RequestMeta) context.Context
- func WithRequestSource(ctx context.Context, source RequestSource) context.Context
- func WithRunHeader(ctx context.Context, raw string) context.Context
- func WithToolResultEnvelope(ctx context.Context) context.Context
- type ContextKey
- type Mount
- type RequestMeta
- type RequestSource
Constants ¶
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 )
const MaxRunNameLen = 128
MaxRunNameLen is the longest accepted run name, in characters.
const RunNameHeader = "X-MCPProxy-Run"
RunNameHeader carries a caller-chosen label for one run of work (Spec 124 FR-003). It is a label, never a credential: it only splits the caller's own activity into named work sessions, and it is never forwarded upstream.
Variables ¶
This section is empty.
Functions ¶
func ClientSurface ¶ added in v0.74.0
ClientSurface returns the surface recorded by WithClientSurface, or "".
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 ¶
GetCorrelationID retrieves the correlation ID from context
func GetOrGenerateRequestID ¶
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 ¶
GetRequestID retrieves the request ID from context
func IsValidRequestID ¶
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 ValidRunName ¶ added in v0.74.0
ValidRunName reports whether s is an acceptable run name: 1 to MaxRunNameLen printable characters. Control characters, invalid UTF-8 and the empty string are refused.
func WithAttemptID ¶ added in v0.74.0
WithAttemptID records the request id a dispatch path minted for one tool call attempt. Every activity row of that attempt carries it, including a limiter rejection, which would otherwise fall back to the transport request id that several attempts of one HTTP request share (Spec 124 D2).
func WithClientSurface ¶ added in v0.74.0
WithClientSurface records which first-party surface made a REST call ("cli", "webui", "tray") or "rest" for anything else. It names the client of a call that has no MCP clientInfo (Spec 124 FR-002).
func WithCorrelationID ¶
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 ¶
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 WithRunHeader ¶ added in v0.74.0
WithRunHeader stores the raw X-MCPProxy-Run header value. It is stored unvalidated so the reader can tell "absent" from "present but invalid" and log the latter (FR-004). An empty value stores nothing.
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.
type RequestMeta ¶ added in v0.68.0
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