Skip to content

fix: keep MCPForUnity.Runtime out of player builds - #1512

Open
sssooonnnggg wants to merge 1 commit into
CoplayDev:betafrom
sssooonnnggg:fix/runtime-asmdef-editor-only
Open

sssooonnnggg wants to merge 1 commit into
CoplayDev:betafrom
sssooonnnggg:fix/runtime-asmdef-editor-only

Conversation

@sssooonnnggg

@sssooonnnggg sssooonnnggg commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

MCPForUnity.Runtime currently has includePlatforms: [], so it is compiled into every player build of any project that installs the package. It only contains helpers for MCPForUnity.Editor (compat shims, screenshot helpers, Newtonsoft converters). Inside the package, only the Editor assembly and the EditMode tests reference it, and several of its files already wrap their UnityEditor calls in #if UNITY_EDITOR.

Shipping it in players has costs and no benefit:

  • It adds the assembly and its Newtonsoft.Json usage to IL2CPP builds. We noticed it in our release build when checking what went into the player.
  • Its public JsonConverters (Vector3Converter, UnityMathematicsConverter, ...) can be found at runtime by packages that scan loaded assemblies for converters and add them to JsonConvert.DefaultSettings. This is the same kind of problem as Public UnityEngine.Object JsonConverter can disrupt existing Newtonsoft.Json serialization #1138, which happened in the Editor.

This PR limits the assembly to the Editor platform. In the Editor nothing changes: MCPForUnity.Editor and the EditMode tests still reference it as before.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

  • MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef: includePlatforms set to ["Editor"].
  • New EditMode test PackageAssemblyPlatformTests: uses CompilationPipeline.GetAssemblies to check that MCPForUnity.Runtime and MCPForUnity.Editor are not in the player assembly set, and that MCPForUnity.Runtime is still compiled for the Editor.

Compatibility / Package Source

  • Unity version(s) tested: 2022.3.62f2 (batchmode, TestProjects/UnityMCPTests opened as-is)
  • Package source used: file: (TestProjects/UnityMCPTests, and an embedded copy in our own project)
  • Resolved commit hash: n/a (file: source)

Testing/Screenshots/Recordings

  • Python tests (cd Server && uv run pytest tests/ -v)
  • Unity EditMode tests
  • Unity PlayMode tests
  • Package import/compile check
  • Not applicable (explain why in Additional Notes)

Ran -runTests -testPlatform EditMode -testFilter MCPForUnityTests.Editor.PackageAssemblyPlatformTests:

  • With this change: 3/3 passed, and the test project compiles with no errors.
  • With the original asmdef (includePlatforms: []): PackageAssembly_IsNotCompiledIntoPlayer("MCPForUnity.Runtime") fails. This confirms the test catches the regression.

I did not run the full Unity 2021.3 / Unity 6 matrix locally.

Documentation Updates

  • I have added/removed/modified tools or resources
  • If yes, I have updated all documentation files using:
    • The LLM prompt at tools/UPDATE_DOCS_PROMPT.md (recommended)
    • Manual review of the generated changes

Related Issues

Relates to #1138

Additional Notes

This only breaks a project if its own player code references MCPForUnity.Runtime (the assembly is autoReferenced). That code would now compile in the Editor but fail in player builds. Since the package is Editor tooling, I don't expect anyone to rely on that, but it's worth mentioning in the release notes.

Summary by CodeRabbit

  • Bug Fixes

    • The runtime package is now limited to the Unity Editor and is no longer included in player builds. Editor functionality remains available.
  • Tests

    • Added checks to verify that package assemblies are excluded from player builds and the runtime assembly remains available in the Editor.

MCPForUnity.Runtime only holds helpers for MCPForUnity.Editor, but with
includePlatforms empty it was compiled into every player build, bringing
its Newtonsoft converters along. Limit it to the Editor platform.

Add an EditMode test that checks neither package assembly is in the
player assembly set and that the Runtime assembly is still compiled for
the Editor.
@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Runtime assembly now targets only the Editor platform. New edit-mode tests check that Runtime and Editor assemblies are absent from player assemblies and that Runtime is present in editor assemblies.

Changes: Assembly Platform Scope

Layer / File(s) Summary
Editor-only assembly scope
MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef, TestProjects/UnityMCPTests/Assets/Tests/EditMode/PackageAssemblyPlatformTests.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/PackageAssemblyPlatformTests.cs.meta
The Runtime assembly definition includes only the Editor platform. New edit-mode tests check assembly presence in editor and player assemblies. Unity metadata was added for the test file.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • CoplayDev/unity-mcp#1505: Adds an interface to the Runtime assembly and a sample component that implements it. This PR changes which platform compiles that assembly.

Suggested reviewers: msanatan

Merge Risk: Minimal · up to 718ef

The assembly is restricted to the Editor. No supported player functionality was found to depend on it, so the change is ready to merge after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title "fix: keep MCPForUnity.Runtime out of player builds" matches the main change. The PR sets the MCPForUnity.Runtime asmdef includePlatforms to ["Editor"], so the assembly no longer compiles in…
Description check Passed The description follows the repository template and covers the main sections. It explains the problem (MCPForUnity.Runtime compiled into every player build) and the fix (includePlatforms set to ["Edit…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: keep MCPForUnity.Runtime out of player builds" matches the main change. The PR sets the MCPForUnity.Runtime asmdef includePlatforms to ["Editor"], so the assembly no longer compiles into player builds. The title uses a conventional-commit prefix and names the assembly, and it stays short and specific. It does not mention the new EditMode test, but the test is secondary to the fix.

Full details: Description check

Explanation

The description follows the repository template and covers the main sections. It explains the problem (MCPForUnity.Runtime compiled into every player build) and the fix (includePlatforms set to ["Editor"]). It marks the Bug fix and Test update types, lists the changes, and gives Unity version, package source, and test results. It also describes the impact on player code that references the assembly. Gaps: the 'Resolved commit hash' field is marked n/a, which is acceptable for a file: source. The Python tests and PlayMode tests are unchecked with no explanation. The Documentation Updates section is unchecked, and the Related Issues section links #1138 only as 'Relates to', which is appropriate. The description is mostly complete.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files. (2 skipped: 2 unsupported.)

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d570c3a-bcfc-461f-b4e2-46400f4e65b9
Commits

Reviewing files that changed from the base of the PR and between e2fd09c and 718efc7.

Files selected for processing: 3

  • MCPForUnity/Runtime/MCPForUnity.Runtime.asmdef
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/PackageAssemblyPlatformTests.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/PackageAssemblyPlatformTests.cs.meta

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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