-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(transport): add a headless boot path for the HTTP plugin hub #1372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lgarczyn
wants to merge
2
commits into
CoplayDev:beta
Choose a base branch
from
lgarczyn:feat/http-ci-boot
base: beta
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System; | ||
| using MCPForUnity.Editor.Constants; | ||
| using MCPForUnity.Editor.Helpers; | ||
| using MCPForUnity.Editor.Services; | ||
| using MCPForUnity.Editor.Services.Transport; | ||
| using UnityEditor; | ||
|
|
||
| namespace MCPForUnity.Editor | ||
| { | ||
| // HTTP is a plugin-hub pull model: the bridge waits at ws://127.0.0.1:<port>/hub/plugin | ||
| // and the editor must dial in. StartStdioForCi forces stdio and only listens, so an | ||
| // editor booted that way never registers and every call returns no_unity_session. | ||
| // | ||
| // The port comes from UNITY_MCP_HTTP_PORT rather than a pref because sibling checkouts | ||
| // of one project share an EditorPrefs file, so a persisted HttpUrl is clobbered by | ||
| // whichever editor wrote last. | ||
| public static class McpHttpCiBoot | ||
| { | ||
| private const string PortEnv = "UNITY_MCP_HTTP_PORT"; | ||
|
|
||
| // Re-asserted on every domain load so a reload cannot resume a sibling's port | ||
| [InitializeOnLoadMethod] | ||
| private static void ReassertEndpointFromEnv() | ||
| { | ||
| ApplyEndpointFromEnv(); | ||
| } | ||
|
|
||
| public static void StartHttpForCi() | ||
| { | ||
| if (!ApplyEndpointFromEnv()) | ||
| { | ||
| McpLog.Error($"[MCPForUnity] StartHttpForCi: {PortEnv} not set or invalid; cannot start HTTP transport"); | ||
| return; | ||
| } | ||
|
|
||
| // Defer the connect so MCPServiceLocator and friends are initialized. | ||
| EditorApplication.delayCall += () => | ||
| { | ||
| _ = MCPServiceLocator.TransportManager.StartAsync(TransportMode.Http); | ||
| }; | ||
| } | ||
|
|
||
| private static bool ApplyEndpointFromEnv() | ||
| { | ||
| string portStr = Environment.GetEnvironmentVariable(PortEnv); | ||
| if (string.IsNullOrWhiteSpace(portStr) || !int.TryParse(portStr, out int port) || port <= 0) | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| { | ||
| return false; | ||
| } | ||
|
|
||
| EditorPrefs.SetBool(EditorPrefKeys.UseHttpTransport, true); | ||
| EditorPrefs.SetString(EditorPrefKeys.HttpTransportScope, "local"); | ||
| EditorPrefs.SetString(EditorPrefKeys.HttpBaseUrl, $"http://127.0.0.1:{port}"); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| return true; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.