Skip to content

Conversation

@msanatan
Copy link
Contributor

@msanatan msanatan commented Nov 28, 2025

Introduce McpDistributionSettings ScriptableObject to configure different defaults for Asset Store and git distributions without code forking. Add skipSetupWindowWhenRemoteDefault flag to bypass setup wizard when shipping with hosted MCP URL. Replace hardcoded localhost:8080 defaults with configurable defaultHttpBaseUrl from distribution settings in HttpEndpointUtility and WebSocketTransportClient.

Summary by CodeRabbit

  • New Features

    • Configurable distribution settings to support different build environments with runtime fallback when no asset is present
    • Option to automatically skip the setup window when a remote default configuration is detected
  • Chores

    • Replaced hardcoded default URLs with dynamic configuration values used across editor flows

✏️ Tip: You can customize this high-level summary in your review settings.

Introduce McpDistributionSettings ScriptableObject to configure different defaults for Asset Store and git distributions without code forking. Add skipSetupWindowWhenRemoteDefault flag to bypass setup wizard when shipping with hosted MCP URL. Replace hardcoded localhost:8080 defaults with configurable defaultHttpBaseUrl from distribution settings in HttpEndpointUtility and WebSocketTransportClient.
@msanatan msanatan self-assigned this Nov 28, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 28, 2025

Walkthrough

Adds a ScriptableObject-based distribution configuration (default HTTP base URL and skip-setup flag), replaces hardcoded defaults with values from that configuration, and conditions the setup window to skip when a remote default is active and not overridden by the user.

Changes

Cohort / File(s) Summary
Config Infrastructure
MCPForUnity/Editor/Config.meta, MCPForUnity/Editor/Config/McpDistributionSettings.cs, MCPForUnity/Editor/Config/McpDistributionSettings.cs.meta
Introduces McpDistributionSettings ScriptableObject (fields: defaultHttpBaseUrl, skipSetupWindowWhenRemoteDefault) and internal McpDistribution lazy-loading helper; adds Unity meta files for the new config.
HTTP and Transport Client Integration
MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs, MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs
Replaces hardcoded default base URLs with McpDistribution.Settings.defaultHttpBaseUrl usage.
Setup Window Logic
MCPForUnity/Editor/Setup/SetupWindowService.cs
Adds a runtime check to skip showing the setup window when no user override exists and skipSetupWindowWhenRemoteDefault is enabled in distribution settings.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify lazy-loading and fallback behavior in McpDistribution.Settings (resource load vs runtime-created asset)
  • Confirm defaultHttpBaseUrl propagation and normalization across HttpEndpointUtility and WebSocketTransportClient
  • Validate detection of user override and skip logic in SetupWindowService.CheckSetupNeeded

Suggested reviewers

  • dsarno

Poem

🐰 I dug a little file today,

defaults no longer stuck in clay.
Lazy hops bring settings near,
setup sleeps when remote is clear,
a quiet burrow — code that’s gay. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the PR: introducing distribution settings to configure different defaults for Asset Store versus git distributions.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)

15-18: Consider edge cases in remote detection logic.

The IsRemoteDefault check only tests for "localhost" and "127.0.0.1". This may not catch other local addresses such as:

  • IPv6 localhost (::1)
  • All interfaces (0.0.0.0)
  • Local network addresses (e.g., 192.168.x.x, 10.x.x.x)

For the Asset Store vs git distribution use case, the current implementation is likely adequate. However, if broader local address detection becomes necessary, consider using System.Net.IPAddress.IsLoopback or checking private IP ranges.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd620e0 and 83dd9c0.

📒 Files selected for processing (6)
  • MCPForUnity/Editor/Config.meta (1 hunks)
  • MCPForUnity/Editor/Config/McpDistributionSettings.cs (1 hunks)
  • MCPForUnity/Editor/Config/McpDistributionSettings.cs.meta (1 hunks)
  • MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs (2 hunks)
  • MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs (2 hunks)
  • MCPForUnity/Editor/Setup/SetupWindowService.cs (2 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-10-13T13:27:23.040Z
Learnt from: msanatan
Repo: CoplayDev/unity-mcp PR: 316
File: TestProjects/UnityMCPTests/Assets/Tests/EditMode/Resources.meta:1-8
Timestamp: 2025-10-13T13:27:23.040Z
Learning: UnityMcpBridge is a legacy project kept for backwards compatibility; MCPForUnity is the only active Unity plugin project. GUID collisions between UnityMcpBridge and MCPForUnity are acceptable.

Applied to files:

  • MCPForUnity/Editor/Config/McpDistributionSettings.cs.meta
  • MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs
  • MCPForUnity/Editor/Setup/SetupWindowService.cs
  • MCPForUnity/Editor/Config/McpDistributionSettings.cs
  • MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs
  • MCPForUnity/Editor/Config.meta
📚 Learning: 2025-09-04T01:01:11.927Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 260
File: UnityMcpBridge/UnityMcpServer~/src/server_version.txt:1-1
Timestamp: 2025-09-04T01:01:11.927Z
Learning: The UnityMcpBridge project is not maintaining changelogs yet, so don't suggest adding changelog entries for version bumps.

Applied to files:

  • MCPForUnity/Editor/Config/McpDistributionSettings.cs.meta
  • MCPForUnity/Editor/Config.meta
📚 Learning: 2025-09-03T16:00:55.839Z
Learnt from: dsarno
Repo: CoplayDev/unity-mcp PR: 0
File: :0-0
Timestamp: 2025-09-03T16:00:55.839Z
Learning: ComponentResolver in UnityMcpBridge/Editor/Tools/ManageGameObject.cs is a nested static class within ManageGameObject, not a sibling type. The `using static MCPForUnity.Editor.Tools.ManageGameObject;` import is required to access ComponentResolver methods directly without the outer class qualifier.

Applied to files:

  • MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs
  • MCPForUnity/Editor/Setup/SetupWindowService.cs
  • MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs
📚 Learning: 2025-10-13T13:41:00.086Z
Learnt from: JohanHoltby
Repo: CoplayDev/unity-mcp PR: 309
File: MCPForUnity/Editor/Helpers/ServerInstaller.cs:478-508
Timestamp: 2025-10-13T13:41:00.086Z
Learning: In the MCPForUnityTools feature (MCPForUnity/Editor/Helpers/ServerInstaller.cs), the design intentionally forces users to have only one .py file per MCPForUnityTools folder to keep file tracking simple. Package-style tools (subdirectories with __init__.py) are not supported.

Applied to files:

  • MCPForUnity/Editor/Setup/SetupWindowService.cs
  • MCPForUnity/Editor/Config/McpDistributionSettings.cs
  • MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs
🧬 Code graph analysis (3)
MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs (1)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)
  • McpDistribution (21-47)
MCPForUnity/Editor/Setup/SetupWindowService.cs (3)
MCPForUnity/Editor/Constants/EditorPrefKeys.cs (1)
  • EditorPrefKeys (7-40)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)
  • McpDistribution (21-47)
MCPForUnity/Editor/Helpers/McpLog.cs (2)
  • McpLog (7-52)
  • Info (37-41)
MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs (1)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)
  • McpDistribution (21-47)
🔇 Additional comments (6)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)

26-46: LGTM: Lazy-loading pattern is appropriate for Unity editor context.

The lazy-loading implementation correctly checks the cache, attempts resource loading, and falls back to runtime defaults. While not thread-safe (no volatile or locking), this is acceptable since Unity's editor operates on a single thread.

MCPForUnity/Editor/Services/Transport/Transports/WebSocketTransportClient.cs (1)

9-9: LGTM: Clean integration with distribution settings.

The change correctly replaces the hardcoded default with the configurable value from McpDistribution.Settings.defaultHttpBaseUrl. The existing URL validation logic (lines 674-677) ensures invalid values are caught, making this integration safe.

Also applies to: 671-671

MCPForUnity/Editor/Config.meta (1)

1-8: Standard Unity folder metadata.

This is standard Unity-generated metadata for the new Config folder with no issues.

MCPForUnity/Editor/Helpers/HttpEndpointUtility.cs (1)

4-4: LGTM: Proper integration with distribution settings.

Converting DefaultBaseUrl from a constant to a property that reads from McpDistribution.Settings.defaultHttpBaseUrl enables runtime configuration while maintaining backward compatibility. The property is private, so this is an implementation detail with no API surface changes.

Also applies to: 16-16

MCPForUnity/Editor/Config/McpDistributionSettings.cs.meta (1)

1-11: Standard Unity script metadata.

This is standard Unity-generated metadata for the C# source file with no issues.

MCPForUnity/Editor/Setup/SetupWindowService.cs (1)

48-57: LGTM: Well-designed conditional setup skip logic.

The implementation correctly handles the Asset Store distribution scenario:

  1. EditorPrefs.HasKey properly detects user overrides (even if set to the same value)
  2. The three-condition check ensures the setup window is only skipped when:
    • User hasn't customized the URL
    • Distribution is configured to skip setup for remote defaults
    • The default URL is actually remote (not localhost)
  3. The log message clearly communicates the skip reason and provides guidance for manual setup access
  4. Using always: false appropriately respects debug logging preferences

This enables Asset Store distributions to ship with hosted MCP URLs while preserving user choice and git/dev workflow.

…ehensive IP range checks

Replace simple string-based localhost/127.0.0.1 checks with robust IsLocalAddress method that validates loopback addresses, private IPv4 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16), IPv6 link-local and loopback addresses, and .local hostnames using proper URI parsing and IPAddress validation.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (2)

49-59: Consider treating invalid/relative URLs as non‑remote to avoid skipping setup.

Right now, if Uri.TryCreate fails, IsLocalAddress returns false, which makes IsRemoteDefault true for any non‑empty but invalid URL. That means a broken default URL can be treated as a “remote default” and may skip the setup flow.

If you’d rather err on the side of showing setup when the URL is bad, invert that behavior:

-            if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
-            {
-                return false;
-            }
+            if (!Uri.TryCreate(url, UriKind.Absolute, out var uri))
+            {
+                // If it's not even a valid absolute URI, don't consider it a remote default.
+                // This keeps the setup window visible for obviously broken values.
+                return true;
+            }

Please double‑check this against how skipSetupWindowWhenRemoteDefault is consumed so the UX matches your intent.


27-47: Optionally log when falling back to runtime defaults.

When no McpDistributionSettings asset exists in Resources, you silently create a runtime default. That’s fine behavior, but a one‑time log can make misconfiguration easier to spot in editor logs.

-                // No asset present (git/dev installs) - fall back to baked-in defaults.
-                _cached = ScriptableObject.CreateInstance<McpDistributionSettings>();
-                _cached.name = "McpDistributionSettings (Runtime Defaults)";
+                // No asset present (git/dev installs) - fall back to baked-in defaults.
+                _cached = ScriptableObject.CreateInstance<McpDistributionSettings>();
+                _cached.name = "McpDistributionSettings (Runtime Defaults)";
+#if UNITY_EDITOR
+                Debug.LogWarning("McpDistributionSettings asset not found in a Resources folder; using runtime defaults.");
+#endif
                 return _cached;

This keeps the current behavior but makes configuration issues more discoverable in the Editor.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83dd9c0 and 4aa13d7.

📒 Files selected for processing (1)
  • MCPForUnity/Editor/Config/McpDistributionSettings.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
MCPForUnity/Editor/Config/McpDistributionSettings.cs (1)
MCPForUnity/Editor/Resources/Tests/GetTests.cs (1)
  • TryParse (79-104)

@msanatan msanatan merged commit c50e583 into CoplayDev:main Nov 28, 2025
@msanatan msanatan deleted the asset-store-defualts branch November 28, 2025 02:10
dsarno added a commit to dsarno/unity-mcp that referenced this pull request Dec 2, 2025
* 'main' of https://github.com/CoplayDev/unity-mcp:
  chore: bump version to 8.1.4
  Fix Claude Windows config and CLI status refresh (CoplayDev#412)
  chore: bump version to 8.1.3
  fix: restrict fastmcp version to avoid potential KeyError (CoplayDev#411)
  chore: bump version to 8.1.2
  Revert project script change
  chore: bump version to 8.1.1
  Fix CLI entry point path in pyproject.toml (CoplayDev#407)
  Fix manage prefabs (CoplayDev#405)
  Remove automatic version bumping from README files and switch to unversioned git URLs
  chore: bump version to 8.1.0
  Add distribution settings for Asset Store vs git defaults (CoplayDev#404)
  Add CodeBuddy CLI configurator (CoplayDev#403)
  Fix stdio reloads (CoplayDev#402)
  Simplify MCP client configs (CoplayDev#401)
  chore: bump version to 8.0.1
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