Repository navigation
feat(mcp): add spawn, destroy and component edit tools (#464) - #708
Merged
Merged
Conversation
…dec edits PatchComponent built its starting value with a JSON round trip, which zeroed unexported fields and json:"-" fields and replaced every pointee with a copy. Patches now go through internal/jsonedit, which decodes onto a clone whose exported pointers, maps, slices and interfaces are freshly allocated and then takes only the fields the patch changed, so untouched runtime state and pointer identity survive and a failed decode never reaches the live value. DecodeComponent and PatchComponent also refuse a decoded value that cannot be encoded back, such as a NaN produced by a custom UnmarshalJSON, which would otherwise break every later EncodeComponent and Snapshot of the entity.
…hat ran - Typed component patches use internal/jsonedit, so unexported, json:"-" and pointer fields survive and a decode error or a rejecting editor leaves the live component untouched, including components with callback fields that cannot be marshalled. - game_entity_spawn rolls back when reading the new entity back fails; game_component_set reports a failed read-back in read_error instead of an error, since the write already stands. - game_entity_destroy reports the hierarchy's actual default policy (or "none" for a childless entity), "reparent" keeps children's world transforms, and children are checked before any of them moves. - RegisterScenePrefab requires exactly one top-level object, and RegisterComponentEditor only upgrades a RegisterComponent[T] registration of the same type. - Docs, the design note and hard-wrapped comments are updated to match.
houko
force-pushed
the
feat/mcp-spawn-edit-464
branch
from
November 24, 2026 19:13
14d1dd6 to
e8edb28
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements object spawning, entity destruction, and live component editing for
packages/game/mcp(parent: #460).packages/game/mcp/edit.go):game_prefabs_list: lists registered prefabs (custom,entity_prefab,scene) in deterministic sorted order.game_entity_spawn: spawns a registered prefab (or empty entity) with optionaloverrides,parentref,x/yTransform2Dconvenience position, and initialcomponentsmap; rolls back spawned entities atomically if parenting, component setup or the read-back fails.game_entity_destroy: destroys a live entity by stable generational ref (entity:<index>:<generation>) with optional hierarchypolicy(cascade,orphan,keep_world,reparent, the last keeping children's world transforms), reporting the policy that actually ran (the hierarchy's default when omitted,nonefor a childless entity), and rejecting stale/invalid refs cleanly.game_component_set: sets or patches a named component on a live entity acrossentities.RegisterCodeccodecs, built-intransform2d/object_ref(propagatingHierarchy2Ddirty flags), and bridge-registered editors (RegisterMutableComponent,RegisterComponentEditor). Refuses unknown fields, trailing data, non-finite floats (NaN/±Inf), invalid nulls, and read-only/derived components without partially mutating state. Patches keep untouched fields exactly as they were (unexported,json:"-"and pointer fields included). A failed read-back after a successful write is reported inread_error.game_component_remove: removes a named editable component from a live entity.Config.Prefabs,Bridge.RegisterPrefab,Bridge.RegisterEntityPrefab, andBridge.RegisterScenePrefab(exactly one top-level object per scene prefab).mcp.RegisterMutableComponent[T]andmcp.RegisterComponentEditor[T](which upgrades only aRegisterComponent[T]registration of the same type).packages/game/entities/snapshot.go):World.DecodeComponent,World.PatchComponent, andWorld.RemoveComponentwith strict JSON decoding, isolated patching throughinternal/jsoneditand refusal of values the codec cannot encode back (such asNaN).docs/en/mcp.md,docs/zh/mcp.md,packages/game/mcp/doc.go, andpackages/game/mcp/example_test.go.changelog.d/mcp-spawn-destroy-edit.mdand.agents/notes/implemented/feature/2026-11-24-mcp-spawn-destroy-edit.md.Verification
gofmtcleango tool nsgo testfor./internal/jsonedit,./entitiesand./mcp, andgo tool nsgo check -target linux,webfor eachgo tool nsgo test .inpackages/game(3419 passed)go run ./tools/changelog checkpassedCloses #464