Documentation
¶
Overview ¶
Package codemode runs Starlark scripts that call outbound MCP tools.
Index ¶
- Constants
- func BuildCatalog(tools []ToolDesc) (map[string]ToolDesc, error)
- func Run(ctx context.Context, source string, tools []ToolDesc, decide DecideFunc, ...) (string, error)
- func SanitizeTool(mcpToolName string) string
- func StarlarkName(server, mcpToolName string) string
- type CallFunc
- type DecideFunc
- type HostTool
- type ToolCallObserver
- type ToolDesc
Constants ¶
const ( // DefaultConcurrency is the per-call width when concurrency= is omitted. DefaultConcurrency = 16 // MaxConcurrency is the per-call ceiling and the execute-wide in-flight branch cap. MaxConcurrency = 64 )
Variables ¶
This section is empty.
Functions ¶
func BuildCatalog ¶
BuildCatalog maps starlark name -> ToolDesc; fails on starlark name collision.
func Run ¶
func Run(ctx context.Context, source string, tools []ToolDesc, decide DecideFunc, call CallFunc, observe ToolCallObserver, host []HostTool) (string, error)
Run executes Starlark source requiring def main() returning a value. mcp tools use decide+call; host tools use HostTool.Call (caller enforces permissions). observe receives each validated tool call before permission and execution. Returns string result (string as-is; other values JSON; None is error).
func SanitizeTool ¶
SanitizeTool maps non [A-Za-z0-9_] to _; prefixes _ if needed for valid ident start.
func StarlarkName ¶
StarlarkName returns sanitizedserver_sanitizedtool for a tool. Server names may contain '-' and '.' (MCP name charset); Starlark needs [A-Za-z0-9_].
Types ¶
type DecideFunc ¶
DecideFunc is per-call permission like bash. subject is "server.tool" (raw MCP tool name). Return nil to allow; error to deny/fail the Starlark builtin.
type HostTool ¶
type HostTool struct {
Name string
InputSchema map[string]any
// Call returns a string result. Used when CallValue is nil.
Call func(ctx context.Context, args map[string]any) (string, error)
// CallValue returns a Starlark value. When set, it is preferred over Call.
CallValue func(ctx context.Context, args map[string]any) (starlark.Value, error)
}
HostTool is a non-MCP builtin (e.g. read, glob). Call includes permission enforcement.
type ToolCallObserver ¶ added in v0.0.46
ToolCallObserver observes a tool call and its Code Mode concurrency path.