Help us shape the future of Go! Take the 2026 Go Developer Survey

mcp

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 17 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"
	// 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"
)
View Source
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

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, inputSchema. 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) }, 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.

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 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 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.

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