Documentation
¶
Index ¶
- Constants
- func DecodePromptResponse(response *mcplib.PromptResponse) object.Object
- func DecodeResourceResponse(response *mcplib.ResourceResponse) object.Object
- func DecodeToolContent(content mcp.ToolContent) object.Object
- func DecodeToolResponse(response *mcp.ToolResponse) object.Object
- func DictToMap(dict *object.Dict) map[string]interface{}
- func GetMCPClientClass() *object.Class
- func ParseToolSearchResults(response *mcplib.ToolResponse) (*object.List, error)
- func ParseToolSearchResultsFromText(text string) (*object.List, error)
- func Register(registrar interface{ ... }, cfg ...*netsecurity.Config)
- func RegisterConfigured(registrar interface{ ... }, policy *netsecurity.Config, allowProcesses bool)
- func RegisterToolHelpers(registrar interface{ ... })
- func RegisterToon(registrar interface{ ... })
- func RunToolScript(ctx context.Context, sl *scriptling.Scriptling, script string, ...) (response string, exitCode int, err error)
- func WrapClient(c *mcplib.Client) object.Object
- type ClientInstance
Constants ¶
const ( MCPLibraryName = "scriptling.mcp" MCPLibraryDesc = "MCP (Model Context Protocol) tool interaction library" )
const ( // MCPParamsVarName is the environment variable name for MCP tool parameters MCPParamsVarName = "__mcp_params" // MCPResponseVarName is the environment variable name for MCP tool response MCPResponseVarName = "__mcp_response" // MCPResponseStructuredVarName marks that __mcp_response's JSON (set by // tool.return_structured()) should also be surfaced as the tool result's // structuredContent field, not just its text content. MCPResponseStructuredVarName = "__mcp_response_structured" )
const ( ToonLibraryName = "scriptling.toon" ToonLibraryDesc = "TOON (Token-Oriented Object Notation) encoding/decoding library" )
Variables ¶
This section is empty.
Functions ¶
func DecodePromptResponse ¶ added in v0.16.0
func DecodePromptResponse(response *mcplib.PromptResponse) object.Object
DecodePromptResponse converts an MCP PromptResponse to a scriptling Object.
func DecodeResourceResponse ¶ added in v0.16.0
func DecodeResourceResponse(response *mcplib.ResourceResponse) object.Object
DecodeResourceResponse converts an MCP ResourceResponse to a scriptling Object. A single content block returns that block's dict; multiple return a list.
func DecodeToolContent ¶
func DecodeToolContent(content mcp.ToolContent) object.Object
DecodeToolContent converts a single ToolContent block to a scriptling Object.
func DecodeToolResponse ¶
func DecodeToolResponse(response *mcp.ToolResponse) object.Object
DecodeToolResponse converts an MCP ToolResponse to a scriptling Object. Handles: - Single text content: returns parsed JSON or string - Multiple content blocks: returns list of decoded blocks - Structured content: returns decoded object
func DictToMap ¶
DictToMap converts a scriptling Dict to a Go map[string]interface{}. This is a convenience wrapper around conversion.ToGo for the common case of converting Dict arguments for tool calls.
func GetMCPClientClass ¶
GetMCPClientClass returns the MCP Client class (thread-safe singleton)
func ParseToolSearchResults ¶
func ParseToolSearchResults(response *mcplib.ToolResponse) (*object.List, error)
ParseToolSearchResults extracts tool list from tool_search response. Returns a scriptling List containing tool dicts with name, description, inputSchema. The tool_search response is expected to be a ToolResponse with JSON text content containing an array of tool definitions.
func ParseToolSearchResultsFromText ¶
ParseToolSearchResultsFromText parses tool search results from a JSON string. This is a convenience function when you already have the JSON text extracted.
func Register ¶
func Register(registrar interface{ RegisterLibrary(*object.Library) }, cfg ...*netsecurity.Config)
Register registers the mcp library with the given registrar. cfg is an optional outbound network policy: when provided (non-nil), every HTTP-transport client created via mcp.Client() is restricted to it (an invalid policy fails closed rather than falling back to unrestricted access). Stdio clients launch a local subprocess and are unaffected — the policy only governs network access. Omitting cfg preserves the previous, unrestricted behaviour. Register allows stdio servers; hosts that disable subprocesses use RegisterConfigured to refuse them.
First call with no cfg builds and caches the unrestricted library; subsequent calls just register it. A call with cfg always builds a fresh, guard-bound library.
func RegisterConfigured ¶ added in v0.33.0
func RegisterConfigured(registrar interface{ RegisterLibrary(*object.Library) }, policy *netsecurity.Config, allowProcesses bool)
RegisterConfigured is Register with control over stdio servers. A stdio server is a subprocess the script names and starts, so it is only allowed where the host allows subprocesses: with allowProcesses false, mcp.Client() refuses any target that is not an http(s) URL. Hosts that disable the subprocess library pass false so mcp.Client() cannot be used to run programs instead. policy is the optional outbound network policy for HTTP clients, as for Register.
func RegisterToolHelpers ¶
RegisterToolHelpers registers the scriptling.mcp.tool sub-library This is optional and separate from the main MCP library registration
func RegisterToon ¶
Register registers the toon library with the given registrar First call builds the library, subsequent calls just register it
func RunToolScript ¶
func RunToolScript(ctx context.Context, sl *scriptling.Scriptling, script string, params interface{}) (response string, exitCode int, err error)
RunToolScript is a Go helper that sets up MCP parameters, runs a script, and retrieves the response. It enables output capture automatically so print() output is available as a fallback response when no explicit return_* call is made. params may be map[string]interface{} or map[string]object.Object.
Types ¶
type ClientInstance ¶
type ClientInstance struct {
// contains filtered or unexported fields
}
ClientInstance wraps an MCP client for use in scriptling
func (*ClientInstance) GetClient ¶
func (c *ClientInstance) GetClient() *mcplib.Client
GetClient returns the underlying MCP client