Documentation
¶
Index ¶
- Constants
- func ApplyToolResponseFilter(ctx context.Context, filter string, jsonData interface{}) (interface{}, error)
- func CompileToolResponseFilter(filter string) (*gojq.Code, error)
- func ShouldApplyMiddleware(toolName string) bool
- func WrapToolHandler(...) ...
- func WrapToolHandlerWithFilter(...) ...
- type PayloadMetadata
Constants ¶
const DefaultJqTimeout = 5 * time.Second
DefaultJqTimeout is the default timeout for jq query execution (5 seconds) This prevents malformed queries or large payloads from causing hangs
const PayloadPreviewSize = 500
PayloadPreviewSize is the maximum number of characters to include in the payload preview This controls how much of the original payload is returned inline when a payload is stored to disk
const PayloadTruncatedInstructions = "" /* 373-byte string literal not displayed */
PayloadTruncatedInstructions is the message returned to clients when a payload has been truncated and saved to the filesystem
Variables ¶
This section is empty.
Functions ¶
func ApplyToolResponseFilter ¶ added in v0.3.7
func ApplyToolResponseFilter(ctx context.Context, filter string, jsonData interface{}) (interface{}, error)
ApplyToolResponseFilter compiles and applies a jq expression to tool response data.
func CompileToolResponseFilter ¶ added in v0.3.7
CompileToolResponseFilter parses and compiles a jq expression used to transform tool response payloads.
For future parameterized filters that need to incorporate per-call values such as server IDs, session metadata, or user-controlled data, prefer gojq.WithVariables at compile time and pass bindings as variadic arguments to code.RunWithContext:
code, _ := gojq.Compile(query, gojq.WithVariables([]string{"$serverID", "$sessionID"}))
iter := code.RunWithContext(ctx, data, serverID, sessionID)
This is injection-safe: variable values are bound at the Go level and never interpolated into the jq expression string.
func ShouldApplyMiddleware ¶
ShouldApplyMiddleware determines if the middleware should be applied to a tool Currently applies to all tools, but can be configured to filter specific tools
func WrapToolHandler ¶
func WrapToolHandler( handler func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error), toolName string, baseDir string, pathPrefix string, sizeThreshold int, getSessionID func(context.Context) string, ) func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error)
WrapToolHandler wraps a tool handler with jqschema middleware This middleware: 1. Generates a random ID for the query 2. Extracts session ID from context (or uses "default") 3. If payload size > sizeThreshold: saves to {baseDir}/{sessionID}/{queryID}/payload.json and returns metadata 4. If payload size <= sizeThreshold: returns original response directly (no file storage) 5. For large payloads: returns first PayloadPreviewSize chars of payload + jq inferred schema 6. Uses pathPrefix to remap returned payloadPath for clients (if configured)
func WrapToolHandlerWithFilter ¶ added in v0.3.7
func WrapToolHandlerWithFilter( handler func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error), toolName string, baseDir string, pathPrefix string, sizeThreshold int, getSessionID func(context.Context) string, filter string, ) func(context.Context, *sdk.CallToolRequest, interface{}) (*sdk.CallToolResult, interface{}, error)
WrapToolHandlerWithFilter wraps a tool handler with jq response filtering followed by the standard large-payload jqschema middleware behavior.
Types ¶
type PayloadMetadata ¶ added in v0.0.106
type PayloadMetadata struct {
AgentInstructions string `json:"agentInstructions"`
PayloadPath string `json:"payloadPath"`
PayloadPreview string `json:"payloadPreview"`
PayloadSchema interface{} `json:"payloadSchema"`
OriginalSize int `json:"originalSize"`
QueryID string `json:"-"` // Internal use only, not serialized to clients
}
PayloadMetadata represents the metadata response returned when a payload is too large and has been saved to the filesystem