Documentation
¶
Overview ¶
Package enforcement provides the concrete Enforcement and Activator implementations that compose the safety subsystems (policy, rate limiting, dry-run, truncation, bootstrap) into the MCP server's pluggable interfaces.
This package sits between the protocol core (mcp) and the domain-specific safety packages, keeping both layers decoupled.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gate ¶
Gate implements mcp.Activator using policy and bootstrap.
func (*Gate) IsGroupAllowed ¶
IsGroupAllowed checks whether the policy permits activating a group.
func (*Gate) OnActivate ¶
OnActivate marks tools as visible in the bootstrap layer.
type Pipeline ¶
type Pipeline struct {
Policy *policy.Policy
Bootstrap *bootstrap.Config
RateLimit *ratelimit.RateLimiter
DryRun dryrun.Config
Truncation truncate.Config
}
Pipeline implements mcp.Enforcement by composing the safety subsystems.
func (*Pipeline) AfterCall ¶
AfterCall applies post-processing (truncation) to a successful result.
Tool handlers return typed structs (e.g. ResultEnvelope) which the truncate package's type switch can't walk. We JSON-roundtrip the result into a generic map[string]any / []any tree before calling Truncate so the walker sees the whole structure. The extra marshal cost is acceptable because the server marshals the result for wire transport moments later anyway.
On marshal/unmarshal failure we fail open and return the original result unchanged — dropping a tool response because truncation misbehaved would be worse than returning an over-budget payload.
func (*Pipeline) BeforeCall ¶
func (p *Pipeline) BeforeCall(ctx context.Context, name string, args map[string]any, hints mcp.ToolHints, schema map[string]any, lookupHandler func(string) (mcp.ToolHandler, bool)) (any, func(), error)
BeforeCall runs the enforcement pipeline before a tool handler:
- Schema validation (W2-01)
- Policy gate
- Rate limit acquire
- Dry-run intercept