Documentation
¶
Index ¶
- func BuildPromptScriptHandler(scriptPath string, cfg HandlerConfig) (mcplib.PromptHandler, error)
- func BuildResourceScriptHandler(scriptPath, mimeType string, cfg HandlerConfig) (mcplib.ResourceHandler, error)
- func BuildStaticPromptHandler(filePath string) mcplib.PromptHandler
- func BuildStaticResourceHandler(filePath, uri, mimeType string) mcplib.ResourceHandler
- func BuildToolHandler(scriptPath string, cfg HandlerConfig) (mcplib.ToolHandler, error)
- func DecodePromptScriptResponse(response string) *mcplib.PromptResponse
- func ScanPromptsFolder(dir string) ([]scannedPrompt, error)
- func ScanResourcesTree(dir string) ([]scannedResource, error)
- func ScanToolsFolder(toolsFolder string) (map[string]*toolmetadata.ToolMetadata, error)
- func ValidateTool(toolName string, meta *toolmetadata.ToolMetadata, scriptPath string) []string
- type HandlerConfig
- type HandlerOption
- func WithAllowedPaths(paths []string) HandlerOption
- func WithDisabledLibs(names []string) HandlerOption
- func WithLogger(l logger.Logger) HandlerOption
- func WithPackLoader(pl *pack.Loader) HandlerOption
- func WithPlugins(pm *scriptlingplugin.Manager) HandlerOption
- func WithSecrets(r *secretprovider.Registry) HandlerOption
- func WithSetupHook(fn func(*scriptling.Scriptling)) HandlerOption
- type PromptArgument
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildPromptScriptHandler ¶ added in v0.16.1
func BuildPromptScriptHandler(scriptPath string, cfg HandlerConfig) (mcplib.PromptHandler, error)
BuildPromptScriptHandler builds a PromptHandler that runs a Scriptling script. The script receives the prompt arguments as parameters and returns messages via mcp.tool.return_object({"messages": [{"role": ..., "content": ...}]}) (a bare string is treated as a single user message).
func BuildResourceScriptHandler ¶ added in v0.16.1
func BuildResourceScriptHandler(scriptPath, mimeType string, cfg HandlerConfig) (mcplib.ResourceHandler, error)
BuildResourceScriptHandler builds a ResourceHandler that runs a Scriptling script. The script receives the request URI as "__uri" and any template variables as parameters (read via mcp.tool.get_string), and returns the resource content via mcp.tool.return_string / return_object.
func BuildStaticPromptHandler ¶ added in v0.16.1
func BuildStaticPromptHandler(filePath string) mcplib.PromptHandler
BuildStaticPromptHandler returns a PromptHandler whose single user message is the file's content (read fresh each call).
func BuildStaticResourceHandler ¶ added in v0.16.1
func BuildStaticResourceHandler(filePath, uri, mimeType string) mcplib.ResourceHandler
BuildStaticResourceHandler serves a file verbatim: text content for UTF-8 files, base64 blob otherwise. The file is read on every read so content is always current.
func BuildToolHandler ¶ added in v0.16.1
func BuildToolHandler(scriptPath string, cfg HandlerConfig) (mcplib.ToolHandler, error)
BuildToolHandler reads the script once at registration time and returns a ToolHandler that runs a fresh interpreter per invocation. The script receives its parameters via mcp.tool.get_* helpers and returns its result via mcp.tool.return_string / return_object / return_error.
func DecodePromptScriptResponse ¶ added in v0.16.1
func DecodePromptScriptResponse(response string) *mcplib.PromptResponse
DecodePromptScriptResponse interprets a prompt script's return value into a PromptResponse. Accepted shapes: a JSON object {"description":..., "messages": [{"role","content"}]}, a JSON array of messages, or a plain string (single user message).
func ScanPromptsFolder ¶ added in v0.16.0
ScanPromptsFolder scans a prompts folder. A prompt is dynamic when a name.toml (with sibling name.py) is present, or static when only a name.md/name.txt is present. If both exist for a name, the dynamic one wins.
func ScanResourcesTree ¶ added in v0.16.0
ScanResourcesTree walks a resources directory and returns every resource (static or template) it describes.
func ScanToolsFolder ¶
func ScanToolsFolder(toolsFolder string) (map[string]*toolmetadata.ToolMetadata, error)
ScanToolsFolder scans the tools folder for .toml files and returns metadata
func ValidateTool ¶
func ValidateTool(toolName string, meta *toolmetadata.ToolMetadata, scriptPath string) []string
ValidateTool checks if a tool's metadata matches its script
Types ¶
type HandlerConfig ¶ added in v0.16.1
type HandlerConfig struct {
LibDirs []string
AllowedPaths []string // nil = unrestricted
DisabledLibs []string // nil = all built-ins enabled
SecretRegistry *secretprovider.Registry // nil = empty registry
Logger logger.Logger // nil = null logger
PackLoader *pack.Loader // nil = no pack loader
PluginManager *scriptlingplugin.Manager // nil = no plugins
SetupHook func(*scriptling.Scriptling) // optional extra setup applied after standard libs
}
HandlerConfig bundles the runtime context needed to build script-backed MCP tool, resource, and prompt handlers. With the exception of LibDirs, every field is optional: a nil SecretRegistry uses an empty one, a nil Logger uses a null logger, and a nil PackLoader / PluginManager simply skips pack / plugin wiring. Built-in libraries can be selectively disabled via DisabledLibs and the filesystem access of os/pathlib/glob/fs/grep/sed can be constrained with AllowedPaths (nil means unrestricted, matching scriptling-cli/server's default).
func NewHandlerConfig ¶ added in v0.16.1
func NewHandlerConfig(libDirs []string, opts ...HandlerOption) HandlerConfig
NewHandlerConfig builds a HandlerConfig from the given lib dirs plus any number of options. It is the recommended entry point for hosts constructing tool/resource/prompt handlers.
type HandlerOption ¶ added in v0.16.1
type HandlerOption func(*HandlerConfig)
HandlerOption configures a HandlerConfig.
func WithAllowedPaths ¶ added in v0.16.1
func WithAllowedPaths(paths []string) HandlerOption
WithAllowedPaths returns an option that constrains os/pathlib/glob/fs/grep/sed to the given paths. nil means unrestricted, an empty slice denies all.
func WithDisabledLibs ¶ added in v0.16.1
func WithDisabledLibs(names []string) HandlerOption
WithDisabledLibs returns an option that disables the named built-in libraries.
func WithLogger ¶ added in v0.16.1
func WithLogger(l logger.Logger) HandlerOption
WithLogger returns an option that supplies the logger used by the logging library inside the script interpreter.
func WithPackLoader ¶ added in v0.16.1
func WithPackLoader(pl *pack.Loader) HandlerOption
WithPackLoader returns an option that chains a pack loader behind the filesystem library loader of every handler's interpreter.
func WithPlugins ¶ added in v0.16.1
func WithPlugins(pm *scriptlingplugin.Manager) HandlerOption
WithPlugins returns an option that attaches a plugin manager to every handler built from the resulting HandlerConfig.
func WithSecrets ¶ added in v0.16.1
func WithSecrets(r *secretprovider.Registry) HandlerOption
WithSecrets returns an option that supplies the secret registry exposed to scripts via the secret library.
func WithSetupHook ¶ added in v0.16.1
func WithSetupHook(fn func(*scriptling.Scriptling)) HandlerOption
WithSetupHook returns an option that registers a callback invoked after the standard library set is registered on each fresh interpreter. Hosts use this to expose their own libraries to served scripts.
type PromptArgument ¶ added in v0.16.0
PromptArgument describes one argument a dynamic prompt accepts.