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

builtinutil

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RedactionModeRedact replaces matching text and records an annotation.
	RedactionModeRedact = "redact"
	// RedactionModeAnnotate records findings without mutating payloads.
	RedactionModeAnnotate = "annotate"

	// RedactionScopeRequest scans request arguments.
	RedactionScopeRequest = "request"
	// RedactionScopeResponse scans response text and structured content.
	RedactionScopeResponse = "response"
	// RedactionScopeBoth scans request and response payloads.
	RedactionScopeBoth = "both"
)
View Source
const (
	// ToolGuardModeBlock blocks matching tool calls.
	ToolGuardModeBlock = "block"
	// ToolGuardModeAnnotate records matching tool calls without blocking.
	ToolGuardModeAnnotate = "annotate"
)

Variables

This section is empty.

Functions

func AppendReport

func AppendReport(ctx *DataContext, report *common.EventAnnotation)

AppendReport appends an annotation report, initializing the annotation part.

func BlockWithTextResult

func BlockWithTextResult(ctx *DataContext, options BlockResultOptions)

BlockWithTextResult injects an MCP error result and marks the event failed and modified.

func EncodeContext

func EncodeContext(ctx *DataContext) ([]byte, error)

EncodeContext encodes a built-in processor DataContext.

func MarkModified

func MarkModified(ctx *DataContext)

MarkModified marks the processor event as modified.

func ReplaceRequestArgumentStrings

func ReplaceRequestArgumentStrings(ctx *DataContext, replace func(TextNode) TextReplacement) (bool, error)

ReplaceRequestArgumentStrings replaces or removes string values in request arguments.

func ReplaceResultText

func ReplaceResultText(ctx *DataContext, replace func(TextNode) TextReplacement) bool

ReplaceResultText replaces or removes text content blocks in payload.result.content.

func ReplaceStructuredContentStrings

func ReplaceStructuredContentStrings(ctx *DataContext, replace func(TextNode) TextReplacement) bool

ReplaceStructuredContentStrings replaces or removes string values in structured content.

func RequestArgumentTextBytes

func RequestArgumentTextBytes(ctx *DataContext) int

RequestArgumentTextBytes counts bytes from all request argument strings.

func ResultTextBytes

func ResultTextBytes(ctx *DataContext) int

ResultTextBytes counts bytes from result text content and structured content strings.

func TotalScannedTextBytes

func TotalScannedTextBytes(ctx *DataContext) int

TotalScannedTextBytes follows the current built-in convention: result text when a result exists, otherwise request argument text.

func WalkRequestArgumentValues

func WalkRequestArgumentValues(ctx *DataContext, visit func(ArgumentNode)) error

WalkRequestArgumentValues visits all JSON values in payload.request.Params.arguments. Paths are relative to payload.request.Params.arguments.

func WalkRequestArguments

func WalkRequestArguments(ctx *DataContext, visit func(TextNode)) error

WalkRequestArguments visits all string values in payload.request.Params.arguments.

func WalkResultText

func WalkResultText(ctx *DataContext, visit func(TextNode))

WalkResultText visits text content blocks in payload.result.content.

func WalkStructuredContent

func WalkStructuredContent(ctx *DataContext, visit func(TextNode))

WalkStructuredContent visits all string values in payload.result.structuredContent.

Types

type AnnotationPart

type AnnotationPart struct {
	Reports []common.EventAnnotation `json:"reports,omitempty"`
}

AnnotationPart contains processor-supplied event reports.

type ArgumentNode

type ArgumentNode struct {
	Path   string
	Value  any
	Text   string
	Scalar bool
}

ArgumentNode identifies one request argument JSON value.

type BlockResultOptions

type BlockResultOptions struct {
	Processor         string
	Message           string
	Status            int
	StructuredContent map[string]any
}

BlockResultOptions controls the MCP error result injected by a built-in processor.

type DataContext

type DataContext struct {
	Version     string              `json:"version"`
	Event       *common.MetaContext `json:"event,omitempty"`
	Payload     *PayloadPart        `json:"payload,omitempty"`
	Routing     *RoutingPart        `json:"routing,omitempty"`
	Auth        *common.AuthContext `json:"auth,omitempty"`
	Annotations *AnnotationPart     `json:"annotations,omitempty"`
}

DataContext mirrors the processor JSON contract for built-in processors. It intentionally lives outside internal/processor to avoid a dispatch import cycle.

func DecodeContext

func DecodeContext(input []byte) (*DataContext, error)

DecodeContext decodes one serialized built-in processor DataContext.

type PathBoundaryOptions

type PathBoundaryOptions struct {
	AllowedRoots     []string
	RelativeBaseRoot string
	ArgumentPaths    []string
	DeniedPaths      []string
}

PathBoundaryOptions controls lexical filesystem path guard behavior.

type PayloadPart

type PayloadPart struct {
	Request         *mcp.CallToolRequest `json:"request,omitempty"`
	OriginalRequest *mcp.CallToolRequest `json:"original_request,omitempty"`
	Result          *mcp.CallToolResult  `json:"result,omitempty"`
	OriginalResult  *mcp.CallToolResult  `json:"original_result,omitempty"`
}

PayloadPart holds tool-call request/result payloads.

type RedactionOptions

type RedactionOptions struct {
	Processor string
	Mode      string
	Scope     string
	Category  string
	Severity  string
	Message   string
	Rules     []RedactionRule
}

RedactionOptions controls common regex redaction behavior.

type RedactionResult

type RedactionResult struct {
	Matched     bool
	Modified    bool
	MatchCount  int
	Findings    []common.EventAnnotationFinding
	RuleNames   []string
	Paths       []string
	Annotations []common.EventAnnotation
}

RedactionResult summarizes one redaction pass.

func ApplyPatternRedactions

func ApplyPatternRedactions(ctx *DataContext, options *RedactionOptions) (*RedactionResult, error)

ApplyPatternRedactions applies regex redaction rules and appends one annotation report when at least one match is found.

type RedactionRule

type RedactionRule struct {
	Name        string
	Pattern     string
	Replacement string
	Regex       *regexp.Regexp
}

RedactionRule describes one compiled literal-replacement regex rule.

func CompileRedactionRules

func CompileRedactionRules(rules []RedactionRule) ([]RedactionRule, error)

CompileRedactionRules compiles rule patterns for use by ApplyPatternRedactions.

type RoutingPart

type RoutingPart struct {
	ServerName         string `json:"server_name"`
	ToolName           string `json:"tool_name"`
	OriginalServerName string `json:"original_server_name"`
	OriginalToolname   string `json:"original_tool_name"`
}

RoutingPart holds routing data for a proxied call.

type TextNode

type TextNode struct {
	Path string
	Text string
}

TextNode identifies one string value found in processor input.

type TextReplacement

type TextReplacement struct {
	Text string
	Keep bool
}

TextReplacement is returned by string mutation callbacks.

func DropText

func DropText() TextReplacement

DropText returns a replacement that removes a string value where removal is supported.

func KeepText

func KeepText(text string) TextReplacement

KeepText returns a replacement that keeps a string value.

type ToolGuardArgumentRule

type ToolGuardArgumentRule struct {
	Path    string
	Pattern string
	Regex   *regexp.Regexp
}

ToolGuardArgumentRule matches request argument paths, scalar values, or both.

type ToolGuardOptions

type ToolGuardOptions struct {
	Processor string
	Mode      string
	Rules     []ToolGuardRule
}

ToolGuardOptions controls generic tool-call guard behavior.

type ToolGuardResult

type ToolGuardResult struct {
	Matched     bool
	Blocked     bool
	RuleName    string
	ToolName    string
	Findings    []common.EventAnnotationFinding
	Annotations []common.EventAnnotation
}

ToolGuardResult summarizes one guard pass.

func ApplyToolGuard

func ApplyToolGuard(ctx *DataContext, options ToolGuardOptions) (*ToolGuardResult, error)

ApplyToolGuard evaluates deny rules against request-phase tool calls.

type ToolGuardRule

type ToolGuardRule struct {
	Name          string
	Category      string
	Severity      string
	Message       string
	ToolPatterns  []string
	ArgumentRules []ToolGuardArgumentRule
	PathBoundary  *PathBoundaryOptions
}

ToolGuardRule describes one deny rule for tool calls.

func CompileToolGuardRules

func CompileToolGuardRules(rules []ToolGuardRule) ([]ToolGuardRule, error)

CompileToolGuardRules compiles regexes in guard rules.

Jump to

Keyboard shortcuts

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