audit

package
v0.11.673 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package audit holds the MCP-specific audit event shape and the string constants for decisions and failure modes recorded in that shape.

This package intentionally does NOT define the sink interface or any sink implementation -- those live under pkg/sink and are generic across subsystems (audit, future activity/telemetry channels, etc). When new kinds of sinks (file rotation policies, alternative transports, GC) land, they benefit every consumer, not just audit.

Index

Constants

View Source
const (
	DecisionAllow                    = "allow"
	DecisionRefuseImmediate          = "refuse_immediate"
	DecisionNeedsApprovalAccepted    = "needs_approval_accepted"
	DecisionNeedsApprovalDeclined    = "needs_approval_declined"
	DecisionNeedsApprovalCancelled   = "needs_approval_cancelled"
	DecisionNeedsApprovalUnavailable = "needs_approval_unavailable"
)

Decision strings recorded in Event.Decision. These constants are the audit contract; downstream tools may parse the log against these values.

View Source
const (
	FailureModeStrict          = "strict"
	FailureModeStrictMutations = "strict_mutations"
	FailureModeBestEffort      = "best_effort"
)

FailureMode strings. Legal values for the MCP server's audit.failure_mode.

View Source
const (
	FormatJSONL = "jsonl"
	FormatOTel  = "otel"
)

Log formats accepted by audit.format / --mcp.log.format.

View Source
const (
	AttributeSchemaVersion = "1.0.0"
)

The emitted attribute set is a versioned interface (issue #729): bump AttributeSchemaVersion when it changes and update the schema test. The gen_ai.* / mcp.* conventions are Development status in the pinned release.

Variables

This section is empty.

Functions

func NewOTelSink added in v0.11.669

func NewOTelSink(inner sink.Sink, serviceVersion string) sink.Sink

NewOTelSink decorates inner with the OTLP/JSON encoding under the stackql resource and this package's attribute schema scope.

Types

type Event

type Event struct {
	Timestamp  time.Time      `json:"timestamp"`
	Tool       string         `json:"tool"`
	Mode       string         `json:"mode"`
	Decision   string         `json:"decision"`
	QueryClass string         `json:"query_class,omitempty"`
	SQL        string         `json:"sql,omitempty"`
	Args       map[string]any `json:"args,omitempty"`
	DurationMs int64          `json:"duration_ms"`
	Error      string         `json:"error,omitempty"`
	// Wire is transport context serialised only by the OTel encoding.
	Wire WireContext `json:"-"`
}

Event is one record in the MCP audit log. All fields are primitive types so the struct never leaks internal/SDK types across the package boundary.

Event is what flows through a pkg/sink.Sink: the gate middleware constructs it, the sink JSON-marshals it. The sink itself is unaware of the audit semantics; rotating the file, adding a new transport, etc are all done in pkg/sink without touching this file.

func (Event) OTelLogRecords added in v0.11.669

func (e Event) OTelLogRecords() []sink.OTelLogRecord

OTelLogRecords maps the event onto the GenAI / MCP semantic conventions: one record for the tool invocation and, when the call went through the approval gate, one for the elicitation decision. Records of one call share gen_ai.tool.call.id and correlate on the session.

type WireContext added in v0.11.669

type WireContext struct {
	ProtocolVersion string
	SessionID       string
	// TraceParent is the W3C traceparent supplied by the caller in _meta.
	TraceParent string
	// RowsReturned is -1 when the tool does not return rows.
	RowsReturned int
}

WireContext carries per-call transport facts that only the OTel encoding serialises; the JSONL Event stays byte-compatible.

Jump to

Keyboard shortcuts

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