script

package
v0.69.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package script provides a Starlark-based script execution engine for orchestrating MCP tool calls. It allows agents to send scripts that call multiple tools and return aggregated results in a single round-trip.

Index

Constants

View Source
const DefaultStepLimit uint64 = 100_000

DefaultStepLimit is the default maximum number of Starlark execution steps.

View Source
const ExecuteToolScriptName = "execute_tool_script"

ExecuteToolScriptName is the name of the virtual tool exposed by the script middleware.

Variables

View Source
var ErrStepLimitExceeded = core.ErrStepLimitExceeded

ErrStepLimitExceeded is matched (with errors.Is) by the error Execute returns when the script, or a callable it ran under parallel(), used up its step budget. The error message itself is the interpreter's.

Functions

func GenerateToolDescription

func GenerateToolDescription(tools []Tool) string

GenerateToolDescription creates a dynamic description for the execute_tool_script tool, listing all available tools and their calling conventions.

Types

type Config

type Config struct {
	// StepLimit is the maximum number of Starlark execution steps per script.
	// Prevents infinite loops and runaway computation.
	// Zero uses DefaultStepLimit (100,000).
	StepLimit uint64

	// ParallelMax is the maximum number of concurrent goroutines that
	// parallel() can spawn. Zero means unlimited.
	ParallelMax int

	// OnStats, when non-nil, is called once per Execute with what the
	// execution did, whether it succeeded or failed. It runs on the Execute
	// goroutine just before Execute returns, so it must be cheap.
	OnStats func(Stats)
}

Config holds script execution parameters. A nil Config passed to New uses sensible defaults for all fields.

type Executor

type Executor interface {
	// Execute runs a Starlark script with optional named data arguments
	// injected as top-level variables. Tools are already bound from
	// construction and available as callable functions within the script.
	Execute(ctx context.Context, script string, data map[string]interface{}) (*mcp.CallToolResult, error)

	// ToolDescription returns the dynamic description for the
	// execute_tool_script virtual tool definition, listing all available
	// tools and their calling conventions.
	ToolDescription() string
}

Executor runs Starlark scripts and describes the virtual tool.

Scripts can call any tool bound at construction time, use loops and conditionals, fan out with parallel(), and return aggregated results. The returned CallToolResult is ready for direct serialization into a JSON-RPC response by the middleware layer.

func New

func New(tools []Tool, cfg *Config) Executor

New creates an Executor bound to the given tools and configuration. A nil cfg uses defaults (DefaultStepLimit, unlimited parallelism, no timeout).

type Stats added in v0.69.0

type Stats struct {
	// Steps is the number of Starlark execution steps, summed over the
	// script and every callable it ran under parallel().
	Steps uint64
	// ParallelCalls is the number of parallel() calls the script made.
	ParallelCalls int
	// ParallelTasks is the number of callables those parallel() calls
	// started, summed over all of them.
	ParallelTasks int
}

Stats describes what one Execute call did. It carries no script content.

type Tool

type Tool struct {
	// Name is the MCP tool name (e.g., "github-fetch-prs").
	Name string

	// Description is the human-readable tool description.
	Description string

	// Call invokes the tool with the given arguments and returns the MCP result.
	// Arguments are always a string-keyed map. When scripts use positional
	// arguments, they are converted to "arg0", "arg1", etc.
	//
	// The caller is responsible for enforcing per-call timeouts (e.g., by
	// wrapping ctx with context.WithTimeout in the closure). The engine
	// passes the context through but does not apply additional deadlines.
	Call func(ctx context.Context, arguments map[string]interface{}) (*mcp.CallToolResult, error)
}

Tool bundles an MCP tool's metadata with a callback for invoking it.

The middleware layer constructs these with Call closures that route invocations through the middleware chain, ensuring authz and other policies are enforced on inner tool calls.

Directories

Path Synopsis
internal
builtins
Package builtins provides Starlark builtin functions for the script engine.
Package builtins provides Starlark builtin functions for the script engine.
conversions
Package conversions provides bidirectional type conversion between Go values and Starlark values, MCP result parsing, and tool name sanitization.
Package conversions provides bidirectional type conversion between Go values and Starlark values, MCP result parsing, and tool name sanitization.
core
Package core provides the Starlark script execution engine.
Package core provides the Starlark script execution engine.

Jump to

Keyboard shortcuts

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