-
Notifications
You must be signed in to change notification settings - Fork 546
Fix/port discovery missing imports #398
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
Changes from 23 commits
8ae595d
83b16ea
67be840
f7ce27d
83b9e47
9dff8f1
00fad91
74d35d3
1bb280e
e6cc955
532b30d
5939d23
9549dd4
6ed7a35
aeceec3
2d7844c
d7cbbfb
e613607
d463aa5
b264bed
2850af8
293bd1f
7bfad3b
42b8eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,30 @@ namespace MCPForUnity.Editor.Services | |
| /// </summary> | ||
| public class ServerManagementService : IServerManagementService | ||
| { | ||
| /// <summary> | ||
| /// Convert a uvx path to a uv path by replacing "uvx" with "uv" while preserving the extension | ||
| /// </summary> | ||
| private string ConvertUvxToUv(string uvxPath) | ||
| { | ||
| if (string.IsNullOrEmpty(uvxPath)) | ||
| return uvxPath; | ||
|
|
||
| // Handle case-insensitive replacement of "uvx" with "uv" | ||
| // This works for paths like: | ||
| // - /usr/bin/uvx -> /usr/bin/uv | ||
| // - C:\path\to\uvx.exe -> C:\path\to\uv.exe | ||
| // - uvx -> uv | ||
|
|
||
| int lastIndex = uvxPath.LastIndexOf("uvx", StringComparison.OrdinalIgnoreCase); | ||
| if (lastIndex >= 0) | ||
| { | ||
| return uvxPath.Substring(0, lastIndex) + "uv" + uvxPath.Substring(lastIndex + 3); | ||
| } | ||
|
|
||
| // Fallback: if "uvx" not found, try removing last character (original behavior) | ||
| return uvxPath.Length > 0 ? uvxPath.Remove(uvxPath.Length - 1, 1) : uvxPath; | ||
| } | ||
|
Comment on lines
+17
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Questionable fallback behavior could produce invalid paths. The fallback on line 38 removes the last character when "uvx" is not found in the path. This is problematic:
Consider handling this case more defensively: Apply this diff to improve the fallback behavior: - // Fallback: if "uvx" not found, try removing last character (original behavior)
- return uvxPath.Length > 0 ? uvxPath.Remove(uvxPath.Length - 1, 1) : uvxPath;
+ // Fallback: if "uvx" not found, assume the path is already pointing to "uv"
+ McpLog.Warn($"ConvertUvxToUv: 'uvx' not found in path '{uvxPath}', assuming it already points to 'uv' or is a custom override.");
+ return uvxPath;Alternatively, if the original behavior was intentional for specific edge cases, document why with a comment explaining the use case.
🤖 Prompt for AI Agents |
||
|
|
||
| /// <summary> | ||
| /// Clear the local uvx cache for the MCP server package | ||
| /// </summary> | ||
|
|
@@ -23,7 +47,7 @@ public bool ClearUvxCache() | |
| try | ||
| { | ||
| string uvxPath = MCPServiceLocator.Paths.GetUvxPath(); | ||
| string uvCommand = uvxPath.Remove(uvxPath.Length - 1, 1); | ||
| string uvCommand = ConvertUvxToUv(uvxPath); | ||
|
|
||
| // Get the package name | ||
| string packageName = "mcp-for-unity"; | ||
|
|
@@ -65,7 +89,7 @@ private bool ExecuteUvCommand(string uvCommand, string args, out string stdout, | |
| stderr = null; | ||
|
|
||
| string uvxPath = MCPServiceLocator.Paths.GetUvxPath(); | ||
| string uvPath = uvxPath.Remove(uvxPath.Length - 1, 1); | ||
| string uvPath = ConvertUvxToUv(uvxPath); | ||
|
|
||
| if (!string.Equals(uvCommand, uvPath, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical:
cmd /cargument handling will fail with spaces in paths.The current implementation adds
uvxPathas a separate argument after/c, butcmd /cexpects the entire command line as a single string following the/cflag. This will fail on Windows whenuvxPathcontains spaces (e.g.,"C:\Program Files\uvx\uvx.exe"), which is very common.When the MCP client executes this, cmd will interpret only the first part before the space as the command, causing execution to fail.
Apply this diff to properly construct the command line for Windows:
🤖 Prompt for AI Agents