mcp

package
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MCPLibraryName = "scriptling.mcp"
	MCPLibraryDesc = "MCP (Model Context Protocol) tool interaction library"
)
View Source
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"
)
View Source
const (
	ToonLibraryName = "scriptling.toon"
	ToonLibraryDesc = "TOON (Token-Oriented Object Notation) encoding/decoding library"
)

Variables

This section is empty.

Functions

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

func DictToMap(dict *object.Dict) map[string]interface{}

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

func GetMCPClientClass() *object.Class

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, input_schema. The tool_search response is expected to be a ToolResponse with JSON text content containing an array of tool definitions.

func ParseToolSearchResultsFromText

func ParseToolSearchResultsFromText(text string) (*object.List, error)

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) })

Register registers the mcp library with the given registrar First call builds the library, subsequent calls just register it

func RegisterToolHelpers

func RegisterToolHelpers(registrar interface{ RegisterLibrary(*object.Library) })

RegisterToolHelpers registers the scriptling.mcp.tool sub-library This is optional and separate from the main MCP library registration

func RegisterToon

func RegisterToon(registrar interface{ RegisterLibrary(*object.Library) })

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 map[string]interface{}) (response string, exitCode int, err error)

RunToolScript is a Go helper that sets up MCP parameters, runs a script, and retrieves the response This simplifies calling MCP tool scripts from Go code

func WrapClient

func WrapClient(c *mcplib.Client) object.Object

WrapClient wraps an MCP client as a scriptling Object that can be passed into a script via SetObjectVar. This allows multiple clients to be used simultaneously.

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

Jump to

Keyboard shortcuts

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