codemode

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package codemode runs Starlark scripts that call outbound MCP tools.

Index

Constants

View Source
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

func BuildCatalog(tools []ToolDesc) (map[string]ToolDesc, error)

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

func SanitizeTool(mcpToolName string) string

SanitizeTool maps non [A-Za-z0-9_] to _; prefixes _ if needed for valid ident start.

func StarlarkName

func StarlarkName(server, mcpToolName string) string

StarlarkName returns sanitizedserver_sanitizedtool for a tool. Server names may contain '-' and '.' (MCP name charset); Starlark needs [A-Za-z0-9_].

Types

type CallFunc

type CallFunc func(ctx context.Context, server, name string, args map[string]any) (string, error)

CallFunc invokes MCP CallTool. server and name are raw MCP names.

type DecideFunc

type DecideFunc func(ctx context.Context, subject string, args map[string]any) error

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

type ToolCallObserver func(ctx context.Context, path []string, name string, args map[string]any)

ToolCallObserver observes a tool call and its Code Mode concurrency path.

type ToolDesc

type ToolDesc struct {
	Server, Name, Description string
	InputSchema               map[string]any
}

ToolDesc is one MCP tool available inside a script / definitions listing.

Jump to

Keyboard shortcuts

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