scripts

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 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 scripts turns script files into shell commands. Each file is run through an upstream MCP server's code-execution tool (blender-mcp's execute_blender_code, Roblox Studio's execute_luau, ...), with the command's arguments and stdin injected as variables:

# summary: list scene objects as JSON lines
# Prints one {"name", "type"} object per line.
import bpy, json
for o in bpy.data.objects:
    print(json.dumps({"name": o.name, "type": o.type}))

The leading comment block is the command's help; a "summary:" line is its one-line summary and a "server:" line picks the server when several run the same language. Files are re-read on every run, so edits apply immediately.

A file named _lib<ext> (e.g. _lib.luau) is not a command: it is shared code every script of that language gets, as a `lib` table in Luau. Libraries from all folders are concatenated in folder order, so a user folder can add helpers.

Index

Constants

View Source
const CodeMarker = "$code"

CodeMarker is the string in a Binding's Args that the script's code replaces.

Variables

View Source
var Langs = map[string]Lang{
	"python": {Ext: ".py", Comment: "#", Wrap: pythonWrap},
	"luau":   {Ext: ".luau", Comment: "--", Wrap: luauWrap},
}

Functions

func HasCodeMarker

func HasCodeMarker(v any) bool

HasCodeMarker reports whether v holds CodeMarker somewhere.

Types

type Binding

type Binding struct {
	Server Caller
	// Host replaces Server for a native host; Tool is then the host command. The host's
	// stdout, stderr and exit code pass through as they are, so the prefix and filter
	// fields below do not apply.
	Host  HostRunner
	Tool  string // e.g. "execute_blender_code"
	Param string // the tool's code argument, e.g. "code"
	// Args is the tool's whole input, for tools that take the code nested in other
	// arguments: every string equal to CodeMarker becomes the code. It replaces Param.
	Args map[string]any
	Lang string // key of Langs
	// OutputPrefix is stripped from successful output ("Code executed successfully: ").
	OutputPrefix string
	// ErrorPrefix marks output that is really an error, for servers that report
	// exceptions as normal text ("Error executing code: ").
	ErrorPrefix string
	// ErrorTrim is removed from error text (e.g. Studio's internal "file:line: "
	// location prefixes).
	ErrorTrim *regexp.Regexp
	// OutputJQ and ErrorJQ filter output and error text that is JSON, after the prefixes
	// and ErrorTrim, e.g. a list of printed lines (`join("")`) or a quoted message (`.`).
	// Text that is not JSON is kept as it is.
	OutputJQ, ErrorJQ *gojq.Code
}

Binding routes scripts of one language to a server's code tool, or to a native host command that runs code from its stdin.

type Caller

type Caller interface {
	Name() string
	CallTool(ctx context.Context, name string, args map[string]any) (*mcp.CallToolResult, error)
}

Caller is the part of an upstream server a script needs.

type Dir

type Dir struct {
	Label string // shown in help, e.g. "~/.mcp-sh/blender/commands"
	FS    fs.FS
	// Required marks a folder the user named explicitly (commandDirs): a missing one is
	// reported in the source label instead of being skipped silently.
	Required bool
}

Dir is one folder of scripts. Later dirs override earlier ones by command name.

type HostRunner

type HostRunner interface {
	Invoke(ctx context.Context, cmd string, args []string, stdin, cwd string) (host.InvokeResult, error)
}

HostRunner runs code on a native host: the code is the stdin of one host command. *host.Client is one.

type Lang

type Lang struct {
	Ext     string // ".py"
	Comment string // line comment marker, "#"
	// Wrap turns a script body into the code sent to the server, declaring ARGS (list
	// of strings), STDIN and CWD (strings) first, plus the shared library.
	Wrap func(args []string, stdin, cwd, body, lib string) string
}

Lang knows how to recognize and prepare scripts in one language.

type Source

type Source struct {
	Dirs     []Dir
	Bindings []Binding
}

func (*Source) Commands

func (s *Source) Commands(ctx context.Context) ([]engine.Command, error)

Commands scans the folders. A missing folder is not an error: users create them on demand.

func (*Source) Label

func (s *Source) Label() string

Jump to

Keyboard shortcuts

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