Skip to content

fix(rql): a nullable tool parameter without a default is not required; screenshot-isolated's target is non-nullable - #1214

Merged
IvanMurzak merged 3 commits into
mainfrom
fix/unity-nullable-params
Nov 28, 2026
Merged

IvanMurzak merged 3 commits into
mainfrom
fix/unity-nullable-params

Conversation

@IvanMurzak

Copy link
Copy Markdown
Owner

Summary

Owner rule: a tool parameter declared nullable (NRT T? or Nullable<T>) without a default is not required. A non-nullable parameter without a default is required. A default or [Optional] makes a parameter not required. Nullability never adds "null" to a schema type: GitHub Copilot and Gemini turn type arrays into ""/0/false/[]. This mirrors IvanMurzak/Godot-MCP#549.

  • RqlToolBinding.Build used to compute required as !HasDefaultValue && !IsOptional && Nullable.GetUnderlyingType(type) == null. That ignored NRT ? on reference types, so a string? or GameObjectRef? without a default was required in the Rql layer but optional in ReflectorNet's Json layer. It now uses com.IvanMurzak.ReflectorNet.Utils.MethodUtils.IsParameterNullable(p) (ReflectorNet 5.6.1, through a using-alias), the check ReflectorNet's JsonSchema also uses. An omitted or JSON-null nullable argument still reaches the method as null: McpPlugin binds an omitted key through ReflectorNet's MethodWrapper (default, else null), and TryConvert maps JSON null to null.
  • The schema type is unchanged; nullability only removes the parameter from required.

Signature audit (every [AiTool] method in the package and extensions/)

extensions/ defines no [AiTool] methods (they are RQL modules). The 29 tool methods in com.ivanmurzak.unity.mcp were audited by script and checked again by a reviewer.

Changed signature

  • screenshot-isolated (Editor/Scripts/API/Tool/Screenshot.Isolated.cs): GameObjectRef? gameObjectRef → GameObjectRef gameObjectRef. It had no default, and the body returned "[Error] gameObjectRef is required.". It is now required in both layers. In Rql it was already required, because the old rule ignored NRT. In Json, ReflectorNet treated it as optional. The null guard stays, since an explicit JSON null can still arrive.

Remaining nullable parameters without a default: none. Every other T? tool parameter has a default, so it was already optional and stays so. Examples: screenshot-camera's GameObjectRef? cameraRef = null (falls back to Camera.main), and screenshot-isolated's bool? includeChildren = true and other options.

Tests (EditMode, RqlToolBindingTests)

New test tool Optionals(string name, string? note, GameObjectRef? gameObjectRef, int? count, int times = 1):

  • OnlyNonNullableParametersWithoutDefaultsAreRequired (Rql and Json): required == ["name"]. NRT reference without a default, Nullable<int> without a default and a defaulted parameter are not required; a non-nullable parameter without a default is required. The schema contains no "null".
  • NullableParametersKeepTheirPlainRqlType: in RQL, note/gameObjectRef are string and count is integer.
  • OmittedOrNullNullableArgumentsReachTheMethodAsNull: omitted, explicit-null and given values (including unity.find("Alpha")).
  • ScreenshotIsolatedRequiresItsTarget (Rql and Json): required == ["gameObjectRef"].
  • ScreenshotIsolatedTests / ScreenshotNoGraphicsTests: an explicit null! where they pass null on purpose.

Local verification in real Unity 2022.3.62f3, EditMode, filter RqlToolBindingTests|ScreenshotIsolatedTests|ScreenshotNoGraphicsTests|RunToolRqlResultTests|ScreenshotImageResultTests|CSharpExecResultTests|ScreenshotCameraTests|ChainRecordTests:

  • -toolDataLayer Rql: 68 passed, 0 failed, 12 skipped. The skipped tests need a graphics device under -nographics.
  • -toolDataLayer Json: 67 passed, 0 failed, 12 skipped (same reason).

Chain fixtures: not re-recorded, because they did not change. The fixtures are recorded in the Rql layer, where screenshot-isolated already required gameObjectRef. A fresh in-process recording (-CHAIN_RECORD_OUT, battery.json) was run through chain_fixture.py canonicalize, and diff against tests/chain-fixtures/2022.3.62f3/tools.jsonl reports no differences (exit 0).

Quality stages

  • simplify: added a shared Required test helper, split the RQL-only type checks out of the per-layer test, and corrected the wording of the required-rule comment. Skipped: a shared IsParameterRequired in ReflectorNet, which would be a cross-repo change needing a ReflectorNet release. The Rql layer also counts [Optional], which ReflectorNet's schema does not; no current tool uses [Optional] without a default.
  • code review (report-only high fan-out): found no binding bugs. Fixed: a <none> test placeholder, so a null-to-"null" text bug would show; null! in ScreenshotNoGraphicsTests (CS8625); type checks moved into an RQL-only test, because Json uses ReflectorNet's schema shape.

🤖 Generated with Claude Code

IvanMurzak and others added 3 commits November 28, 2026 01:59
…; screenshot-isolated's target is non-nullable

RqlToolBinding computed required as !HasDefaultValue && !IsOptional && not Nullable<T>,
so an NRT-annotated reference parameter (string?, GameObjectRef?) without a default
was required in the Rql layer but optional in ReflectorNet's Json layer. Use
ReflectorNet's MethodUtils.IsParameterNullable, the same rule as the Json layer
(mirrors Godot-MCP#549). Nullability never adds "null" to a schema type.

screenshot-isolated declared GameObjectRef? gameObjectRef without a default but
rejects null, so it is now GameObjectRef: required in both layers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…layer test, accurate required-rule comment

Skipped: one shared IsParameterRequired in ReflectorNet (cross-repo, needs a ReflectorNet release);
moving ScreenshotIsolatedRequiresItsTarget to ScreenshotIsolatedTests (would duplicate the binding
save/restore setup; this suite already checks screenshot-isolated's schema).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…torNet's schema shape), <none> placeholder so a null-to-"null" text bug shows, null! in ScreenshotNoGraphicsTests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IvanMurzak
IvanMurzak merged commit c17091c into main Nov 28, 2026
37 checks passed
@IvanMurzak
IvanMurzak deleted the fix/unity-nullable-params branch November 28, 2026 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant