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 ¶
const CodeMarker = "$code"
CodeMarker is the string in a Binding's Args that the script's code replaces.
Variables ¶
var Langs = map[string]Lang{
"python": {Ext: ".py", Comment: "#", Wrap: pythonWrap},
"luau": {Ext: ".luau", Comment: "--", Wrap: luauWrap},
}
Functions ¶
func HasCodeMarker ¶
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.