Help us shape the future of Go! Take the 2026 Go Developer Survey

codemode

package
v0.2.24 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 15 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 CallKey

func CallKey(ctx context.Context) string

CallKey returns the replay-stable key of the host or MCP call running in ctx: the call's position within its thread, prefixed by the fan-out branches that led to it.

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.CallValue (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
	// CallValue is required and returns the tool's Starlark value.
	CallValue func(ctx context.Context, args map[string]any) (starlark.Value, error)
}

HostTool is a non-MCP builtin (e.g. read, glob). CallValue includes permission enforcement.

type ToolCallObserver

type ToolCallObserver interface {
	ObserveToolCall(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