webmcpbridge

package
v0.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// PriorityLoop is the fallback registration priority used by game.Loop.Run
	// when a game does not attach a full pkg/mcp.Bridge.
	PriorityLoop = 1
	// PriorityBridge is the full pkg/mcp.Bridge registration priority,
	// superseding any game.Loop fallback while attached.
	PriorityBridge = 2
)

Variables

This section is empty.

Functions

func IsSameOriginPath

func IsSameOriginPath(raw string) bool

IsSameOriginPath reports whether raw is a safe same-origin absolute URL path (starts with "/" and not "//", contains no backslashes, whitespace, or control characters).

func Register

func Register(Config) (unregister func())

Register is a no-op outside js/wasm web builds.

func RegisterLoop

func RegisterLoop(post func(func()), c LoopControl) (unregister func())

RegisterLoop registers the fallback loop tools at PriorityLoop, running each call through post on the loop's goroutine. It returns the unregister function, a no-op outside js/wasm.

Types

type Config

type Config struct {
	// Source identifies who registered the runtime (for example "mcp.Bridge" or "game.Loop").
	Source string
	// Priority selects which active registration wins when more than one is attached.
	Priority int
	// Post schedules fn to run on the engine/graph goroutine (typically core.Scope.Post).
	// When nil, CallTool runs directly.
	Post func(fn func())
	// ListTools returns the tools currently exposed by this registration.
	ListTools func() []ToolInfo
	// CallTool invokes a named tool with JSON object arguments on the engine goroutine
	// and returns its JSON-encoded result.
	CallTool func(ctx context.Context, name string, args json.RawMessage) (json.RawMessage, error)
}

Config registers a runtime's MCP tool dispatcher on window.__nsgoMCP in js/wasm web builds.

type LoopControl

type LoopControl struct {
	Paused         func() bool
	SetPaused      func(bool)
	TimeScale      func() float64
	SetTimeScale   func(float64)
	StepSeconds    func() float64
	StepRate       func() int
	Steps          func() uint64
	ElapsedSeconds func() float64
	StepNow        func(int) int
}

LoopControl is the part of game.Loop the fallback Play-mode tools read and drive. game.Loop fills it with its own methods; it lives here so the tools build and test on every target, while Register stays a no-op outside js/wasm.

func (LoopControl) Call

func (c LoopControl) Call(name string, raw json.RawMessage) (json.RawMessage, error)

Call runs the fallback loop tool name with its JSON arguments and returns its JSON result.

type ToolInfo

type ToolInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

ToolInfo describes one game MCP tool exposed through window.__nsgoMCP.listTools().

func LoopTools

func LoopTools() []ToolInfo

LoopTools lists the fallback tools RegisterLoop serves.

Jump to

Keyboard shortcuts

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