js

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for JS execution
	DefaultTimeout = 15 * time.Second
	// MaxScriptSize is the maximum script size in bytes
	MaxScriptSize = 100 * 1024 // 100KB
	// MaxLogEntries is the maximum number of log entries allowed
	MaxLogEntries = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Timeout      time.Duration
	AllowedTools map[string][]string // map[serverID][]toolNames, nil = allow all
}

Config holds runtime configuration

type ErrorType

type ErrorType string

ErrorType represents the type of runtime error

const (
	ErrorTypeTimeout    ErrorType = "timeout"
	ErrorTypeSyntax     ErrorType = "syntax_error"
	ErrorTypeRuntime    ErrorType = "runtime_error"
	ErrorTypeValidation ErrorType = "validation_error"
	ErrorTypeAsync      ErrorType = "async_not_allowed"
)

type LogEntry

type LogEntry struct {
	Level   string         `json:"level"`
	Message string         `json:"message"`
	Fields  map[string]any `json:"fields,omitempty"`
}

LogEntry represents a log entry from mcp.log()

type ManagerCaller

type ManagerCaller struct {
	// contains filtered or unexported fields
}

ManagerCaller adapts a SessionGetter (like client.Manager) to the ToolCaller interface

func NewManagerCaller

func NewManagerCaller(getter SessionGetter) *ManagerCaller

NewManagerCaller creates a new ManagerCaller from a SessionGetter

func (*ManagerCaller) CallTool

func (m *ManagerCaller) CallTool(ctx context.Context, serverID, toolName string, params map[string]any) (*mcp.CallToolResult, error)

CallTool implements ToolCaller for ManagerCaller

func (*ManagerCaller) ListTools added in v0.1.1

func (m *ManagerCaller) ListTools(ctx context.Context) ([]*mcp.Tool, error)

ListTools implements ToolCaller for ManagerCaller

type Runtime

type Runtime struct {
	// contains filtered or unexported fields
}

Runtime represents a JavaScript runtime for executing tool scripts

func NewRuntime

func NewRuntime(logger *slog.Logger, caller ToolCaller, cfg *Config) *Runtime

NewRuntime creates a new JavaScript runtime

func (*Runtime) Execute

func (r *Runtime) Execute(ctx context.Context, script string) (any, []LogEntry, error)

Execute executes a JavaScript script with sync-only enforcement

type RuntimeError

type RuntimeError struct {
	Type    ErrorType `json:"type"`
	Message string    `json:"message"`
}

RuntimeError represents a structured runtime error

func (*RuntimeError) Error

func (e *RuntimeError) Error() string

Error implements the error interface

type SessionGetter

type SessionGetter interface {
	GetClient(serverID string) (*mcp.ClientSession, error)
	GetAllTools() map[string]*mcp.Tool
}

SessionGetter abstracts getting a client session by server ID (implemented by client.Manager)

type ToolCaller

type ToolCaller interface {
	// CallTool calls a tool with the given serverID, toolName, and parameters
	// For single-server clients, serverID can be ignored or used as a default
	CallTool(ctx context.Context, serverID, toolName string, params map[string]any) (*mcp.CallToolResult, error)
	// ListTools returns all available tools (used for name resolution)
	ListTools(ctx context.Context) ([]*mcp.Tool, error)
}

ToolCaller abstracts tool calling for different client types

Jump to

Keyboard shortcuts

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