scriptmcp

package
v0.40.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package scriptmcp provides an in-process MCP server exposing a sandboxed JavaScript execution tool for deterministic data transformation/formatting. It follows the same pattern as internal/webmcp and internal/configmcp: no subprocess is spawned; the server runs in-process via mcp.NewInMemoryTransports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSemaphore

func NewSemaphore(n int) chan struct{}

NewSemaphore returns a concurrency semaphore bounding simultaneous VM executions to n. A non-positive n returns nil, meaning unbounded. Construct one per process and share it across every agent's Deps so the cap is global.

Types

type Deps

type Deps struct {
	// Enabled gates tool registration. When false, no tool is registered.
	Enabled bool
	// Timeout is the wall-clock limit for a single snippet. Default applied by caller.
	Timeout time.Duration
	// MaxOutputChars caps the returned result length.
	MaxOutputChars int
	// MaxInputBytes caps the accepted input payload size.
	MaxInputBytes int
	// Sem bounds simultaneous VM executions. It is shared across all per-agent
	// Script servers so the cap is process-global, protecting the shared goja
	// heap. A nil semaphore means unbounded concurrency. Use NewSemaphore.
	Sem chan struct{}
	// AgentSem additionally bounds simultaneous VM executions for this one agent,
	// so a single agent can't monopolize the global pool. Not shared between
	// agents. A nil semaphore means no per-agent limit. Use NewSemaphore.
	AgentSem chan struct{}
	// PermissionTier returns the current effective tier for the agent.
	PermissionTier func() string

	Logger *slog.Logger
}

Deps holds the runtime dependencies injected into the Script MCP server.

type Server

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

Server is the in-process Script MCP server for a single agent.

func New

func New(deps Deps) *Server

New constructs and wires the Script MCP server. The run_javascript tool is registered immediately (when enabled); the server does not begin serving until Connect is called.

func (*Server) Connect

func (s *Server) Connect(ctx context.Context) (*mcp.ClientSession, error)

Connect starts the in-process server goroutine and returns a *mcp.ClientSession ready to be passed to tool.Manager.RegisterSession.

Jump to

Keyboard shortcuts

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