jqfilter

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jqfilter runs a jq program over an already-decoded JSON value in a locked-down sandbox. It backs the MCP server's optional `jq` argument, which lets an agent reshape, filter and aggregate a tool's reply server-side so only the needed data enters its context.

The host process holds the caller's BRON_API_KEY in its environment, so the sandbox is deliberately strict: no environment access (gojq's `env`/`$ENV` resolve to empty), no stdin (`input`/`inputs` are rejected at compile time), no module imports, a wall-clock timeout against runaway programs, and a cap on emitted values so a filter can't blow up the context it is meant to shrink.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultTimeout bounds a single jq evaluation. gojq honours context
	// cancellation between steps, so this bites infinite generators
	// (`repeat(.)`, `range(1e12)`).
	DefaultTimeout = 2 * time.Second

	// DefaultMaxResults caps how many top-level values the program may emit
	// before Run aborts. A jq filter can multiply output (`[range(1e6)]`);
	// the whole point here is to shrink context, so an exploding result is
	// treated as an error, not silently truncated.
	DefaultMaxResults = 10000
)

Defaults applied by Run. Exposed as vars so callers/tests can tighten them.

View Source
var ErrTooManyResults = errors.New("jq produced too many results")

ErrTooManyResults is returned when a program emits more than the cap.

Functions

func Run

func Run(program string, input interface{}) (interface{}, error)

Run compiles and evaluates program against input and returns the produced values. A program emitting exactly one value returns that value unwrapped (the common reshape/filter case); zero values returns nil; multiple values returns a []interface{} stream. Compile errors surface verbatim so a calling agent can correct its own filter.

func RunWithLimits

func RunWithLimits(program string, input interface{}, timeout time.Duration, maxResults int) (interface{}, error)

RunWithLimits is Run with explicit limits — used by tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

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