Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ namespace MCPForUnity.Editor.Clients.Configurators
{
public class ClaudeDesktopConfigurator : JsonFileMcpConfigurator
{
public const string ClientName = "Claude Desktop";

public ClaudeDesktopConfigurator() : base(new McpClient
{
name = "Claude Desktop",
name = ClientName,
windowsConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Claude", "claude_desktop_config.json"),
macConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Library", "Application Support", "Claude", "claude_desktop_config.json"),
linuxConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".config", "Claude", "claude_desktop_config.json"),
SupportsHttpTransport = false
SupportsHttpTransport = false,
StripEnvWhenNotRequired = true
})
{ }

Expand Down
64 changes: 55 additions & 9 deletions MCPForUnity/Editor/Helpers/ConfigJsonBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MCPForUnity.Editor.Constants;
using MCPForUnity.Editor.Clients.Configurators;
using MCPForUnity.Editor.Helpers;
using MCPForUnity.Editor.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEditor;
using UnityEngine;

namespace MCPForUnity.Editor.Helpers
{
Expand Down Expand Up @@ -77,19 +81,22 @@ private static void PopulateUnityNode(JObject unity, string uvPath, McpClient cl
// Stdio mode: Use uvx command
var (uvxPath, fromUrl, packageName) = AssetPathUtility.GetUvxCommandParts();

unity["command"] = uvxPath;
var toolArgs = BuildUvxArgs(fromUrl, packageName);

var args = new List<string> { packageName };
if (!string.IsNullOrEmpty(fromUrl))
if (ShouldUseWindowsCmdShim(client))
{
args.Insert(0, fromUrl);
args.Insert(0, "--from");
}
unity["command"] = ResolveCmdPath();

args.Add("--transport");
args.Add("stdio");
var cmdArgs = new List<string> { "/c", uvxPath };
cmdArgs.AddRange(toolArgs);

unity["args"] = JArray.FromObject(args.ToArray());
unity["args"] = JArray.FromObject(cmdArgs.ToArray());
}
else
{
unity["command"] = uvxPath;
unity["args"] = JArray.FromObject(toolArgs.ToArray());
}

// Remove url/serverUrl if they exist from previous config
if (unity["url"] != null) unity.Remove("url");
Expand Down Expand Up @@ -145,5 +152,44 @@ private static JObject EnsureObject(JObject parent, string name)
parent[name] = created;
return created;
}

private static IList<string> BuildUvxArgs(string fromUrl, string packageName)
{
var args = new List<string> { packageName };

if (!string.IsNullOrEmpty(fromUrl))
{
args.Insert(0, fromUrl);
args.Insert(0, "--from");
}

args.Add("--transport");
args.Add("stdio");

return args;
}

private static bool ShouldUseWindowsCmdShim(McpClient client)
{
if (client == null)
{
return false;
}

return Application.platform == RuntimePlatform.WindowsEditor &&
string.Equals(client.name, ClaudeDesktopConfigurator.ClientName, StringComparison.OrdinalIgnoreCase);
}

private static string ResolveCmdPath()
{
var comSpec = Environment.GetEnvironmentVariable("ComSpec");
if (!string.IsNullOrEmpty(comSpec) && File.Exists(comSpec))
{
return comSpec;
}

string system32Cmd = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe");
return File.Exists(system32Cmd) ? system32Cmd : "cmd.exe";
}
}
}
82 changes: 82 additions & 0 deletions MCPForUnity/Editor/Services/PathResolverService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -34,6 +35,12 @@ public string GetUvxPath()
McpLog.Debug("No uvx path override found, falling back to default command");
}

string discovered = ResolveUvxFromSystem();
if (!string.IsNullOrEmpty(discovered))
{
return discovered;
}

return "uvx";
}

Expand Down Expand Up @@ -123,6 +130,81 @@ public bool IsClaudeCliDetected()
return !string.IsNullOrEmpty(GetClaudeCliPath());
}

private static string ResolveUvxFromSystem()
{
try
{
foreach (string candidate in EnumerateUvxCandidates())
{
if (!string.IsNullOrEmpty(candidate) && File.Exists(candidate))
{
return candidate;
}
}
}
catch
{
// fall back to bare command
}

return null;
}

private static IEnumerable<string> EnumerateUvxCandidates()
{
string exeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "uvx.exe" : "uvx";

string home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
if (!string.IsNullOrEmpty(home))
{
yield return Path.Combine(home, ".local", "bin", exeName);
yield return Path.Combine(home, ".cargo", "bin", exeName);
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
yield return "/opt/homebrew/bin/" + exeName;
yield return "/usr/local/bin/" + exeName;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
yield return "/usr/local/bin/" + exeName;
yield return "/usr/bin/" + exeName;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string programFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);

if (!string.IsNullOrEmpty(localAppData))
{
yield return Path.Combine(localAppData, "Programs", "uv", exeName);
}

if (!string.IsNullOrEmpty(programFiles))
{
yield return Path.Combine(programFiles, "uv", exeName);
}
}

string pathEnv = Environment.GetEnvironmentVariable("PATH");
if (!string.IsNullOrEmpty(pathEnv))
{
foreach (string rawDir in pathEnv.Split(Path.PathSeparator))
{
if (string.IsNullOrWhiteSpace(rawDir)) continue;
string dir = rawDir.Trim();
yield return Path.Combine(dir, exeName);

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
// Some PATH entries may already contain the file without extension
yield return Path.Combine(dir, "uvx");
}
}
}
}

public void SetUvxPathOverride(string path)
{
if (string.IsNullOrEmpty(path))
Expand Down
Loading